A images-badge component from Aceternity UI.
From Aceternity UI
1"use client";
2
3import React, { useState } from "react";
4import { motion } from "motion/react";
5import { cn } from "@/lib/utils";
6
7interface ImagesBadgeProps {
8 text: string;
9 images: string[];
10 className?: string;
11 /** Optional link URL */
12 href?: string;
13 /** Link target attribute (e.g., "_blank" for new tab) */
14 target?: string;
15 /** Folder dimensions { width, height } in pixels */
16 folderSize?: { width: number; height: number };
17 /** Image dimensions when teased (peeking) { width, height } in pixels */
18 teaserImageSize?: { width: number; height: number };
19 /** Image dimensions when hovered { width, height } in pixels */
20 hoverImageSize?: { width: number; height: number };
21 /** How far images translate up on hover in pixels */
22 hoverTranslateY?: number;
23 /** How far images spread horizontally on hover in pixels */
24 hoverSpread?: number;
25 /** Rotation angle for fanned images on hover in degrees */
26 hoverRotation?: number;
27}
28
29export function ImagesBadge({
30 text,
31 images,
32 className,
33 href,
34 target,
35 folderSize = { width: 32, height: 24 },
36 teaserImageSize = { width: 20, height: 14 },
37 hoverImageSize = { width: 48, height: 32 },
38 hoverTranslateY = -35,
39 hoverSpread = 20,
40 hoverRotation = 15,
41}: ImagesBadgeProps) {
42 const [isHovered, setIsHovered] = useState(false);
43
44 // Limit to max 3 images
45 const displayImages = images.slice(0, 3);
46
47 // Calculate folder tab dimensions proportionally
48 const tabWidth = folderSize.width * 0.375;
49 const tabHeight = folderSize.height * 0.25;
50
51 const Component = href ? "a" : "div";
52
53 return (
54 <Component
55 href={href}
56 target={target}
57 rel={target === "_blank" ? "noopener noreferrer" : undefined}
58 className={cn(
59 "inline-flex cursor-pointer items-center gap-2 perspective-[1000px] transform-3d",
60 className,
61 )}
62 onMouseEnter={() => setIsHovered(true)}
63 onMouseLeave={() => setIsHovered(false)}
64 >
65 {/* Folder Container */}
66 <motion.div
67 className="relative"
68 style={{
69 width: folderSize.width,
70 height: folderSize.height,
71 transformStyle: "preserve-3d",
72 }}
73 >
74 {/* Folder Back */}
75 <div className="absolute inset-0 rounded-[4px] bg-gradient-to-b from-amber-400 to-amber-500 shadow-sm dark:from-amber-500 dark:to-amber-600">
76 {/* Folder Tab */}
77 <div
78 className="absolute left-0.5 rounded-t-[2px] bg-gradient-to-b from-amber-300 to-amber-400 dark:from-amber-400 dark:to-amber-500"
79 style={{
80 top: -tabHeight * 0.65,
81 width: tabWidth,
82 height: tabHeight,
83 }}
84 />
85 </div>
86
87 {/* Images that pop out */}
88 {displayImages.map((image, index) => {
89 const totalImages = displayImages.length;
90
91 // Calculate rotation based on index
92 const baseRotation =
93 totalImages === 1
94 ? 0
95 : totalImages === 2
96 ? (index - 0.5) * hoverRotation
97 : (index - 1) * hoverRotation;
98
99 // Hover positions - fan out
100 const hoverY = hoverTranslateY - (totalImages - 1 - index) * 3;
101 const hoverX =
102 totalImages === 1
103 ? 0
104 : totalImages === 2
105 ? (index - 0.5) * hoverSpread
106 : (index - 1) * hoverSpread;
107
108 // Teaser positions - slight peek from folder
109 const teaseY = -4 - (totalImages - 1 - index) * 1;
110 const teaseRotation =
111 totalImages === 1
112 ? 0
113 : totalImages === 2
114 ? (index - 0.5) * 3
115 : (index - 1) * 3;
116
117 return (
118 <motion.div
119 key={index}
120 className="absolute top-0.5 left-1/2 origin-bottom overflow-hidden rounded-[3px] bg-white shadow-sm ring-1 shadow-black/10 ring-black/10 dark:bg-neutral-800 dark:shadow-white/10 dark:ring-white/10"
121 animate={{
122 x: `calc(-50% + ${isHovered ? hoverX : 0}px)`,
123 y: isHovered ? hoverY : teaseY,
124 rotate: isHovered ? baseRotation : teaseRotation,
125 width: isHovered ? hoverImageSize.width : teaserImageSize.width,
126 height: isHovered
127 ? hoverImageSize.height
128 : teaserImageSize.height,
129 }}
130 transition={{
131 type: "spring",
132 stiffness: 400,
133 damping: 25,
134 delay: index * 0.03,
135 }}
136 style={{
137 zIndex: 10 + index,
138 }}
139 >
140 <img
141 src={image}
142 alt={`Preview ${index + 1}`}
143 className="h-full w-full object-cover"
144 />
145 </motion.div>
146 );
147 })}
148
149 {/* Folder Front (flattens on hover) */}
150 <motion.div
151 className="absolute inset-x-0 bottom-0 h-[85%] origin-bottom rounded-[4px] bg-gradient-to-b from-amber-300 to-amber-400 shadow-sm dark:from-amber-400 dark:to-amber-500"
152 animate={{
153 rotateX: isHovered ? -45 : -25,
154 scaleY: isHovered ? 0.8 : 1,
155 }}
156 transition={{
157 type: "spring",
158 stiffness: 400,
159 damping: 25,
160 }}
161 style={{
162 transformStyle: "preserve-3d",
163 zIndex: 20,
164 }}
165 >
166 {/* Folder line detail */}
167 <div className="absolute top-1 right-1 left-1 h-px bg-amber-200/50 dark:bg-amber-300/50" />
168 </motion.div>
169 </motion.div>
170
171 {/* Text */}
172 <span className="text-sm font-medium text-neutral-700 dark:text-neutral-200">
173 {text}
174 </span>
175 </Component>
176 );
177}
178