opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Files
  4. Stacked Folder Card
Back to Files

Components / Files

Stacked Folder Card

Free Files React component — StackedFolderCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Three stacked folder cards with thick white borders and smooth hover rotation — back and middle peeks bring any card to the front.

Preview

Folder cover

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/files/stacked-folder-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { StackedFolderCard } from "@/components/files/stacked-folder-card";

    <StackedFolderCard imageSrc="/wallpaper-3.png" backImageSrc="/wallpaper-2.png" middleImageSrc="/wallpaper-11.png" />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/files/stacked-folder-card.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"use client";
 
import Image from "next/image";
import { forwardRef, useCallback, useState, type ComponentPropsWithoutRef } from "react";
 
import { cn } from "@/lib/cn";
 
type LayerIndex = 0 | 1 | 2;
type StackPosition = "front" | "middle" | "back";
 
const TRANSITION =
"transition-[top,left,width,height,transform,box-shadow] duration-400 ease-[cubic-bezier(0.22,1,0.36,1)]";
 
const POSITION_LAYOUT: Record<StackPosition, string> = {
front:
"top-0 left-9 z-30 h-[17rem] w-[15.75rem] rotate-0 shadow-[0_20px_44px_-14px_rgba(0,0,0,0.38)]",
middle:
"top-4 left-4 z-20 h-[16rem] w-[15rem] -rotate-[3.5deg] shadow-[0_12px_28px_-10px_rgba(0,0,0,0.3)]",
back:
"top-9 left-0.5 z-10 h-[15.5rem] w-[14.5rem] -rotate-[7deg] shadow-[0_10px_24px_-10px_rgba(0,0,0,0.28)]",
};
 
// [front, middle, back] — hovered card goes front, previous front goes back, other stays middle.
const STACK_ORDER: Record<LayerIndex, readonly [LayerIndex, LayerIndex, LayerIndex]> = {
0: [0, 1, 2],
1: [1, 0, 2],
2: [2, 1, 0],
};
 
function positionForLayer(layer: LayerIndex, active: LayerIndex): StackPosition {
const [front, middle] = STACK_ORDER[active];
if (layer === front) return "front";
if (layer === middle) return "middle";
return "back";
}
 
type LayerConfig = Readonly<{
index: LayerIndex;
src?: string;
alt: string;
surfaceClassName: string;
}>;
 
export type StackedFolderCardProps = Readonly<
{
imageSrc?: string;
imageAlt?: string;
backImageSrc?: string;
middleImageSrc?: string;
backClassName?: string;
middleClassName?: string;
} & ComponentPropsWithoutRef<"div">
>;
 
// Three-layer folder stack · fixed hit zones · hover rotates front → back.
export const StackedFolderCard = forwardRef<HTMLDivElement, StackedFolderCardProps>(
function StackedFolderCard(
{
className,
imageSrc = "/wallpaper-3.png",
imageAlt = "Folder cover",
backImageSrc,
middleImageSrc,
backClassName = "bg-[#e28a8a]",
middleClassName = "bg-[#5a675e]",
...props
},
ref,
) {
const [active, setActive] = useState<LayerIndex>(2);
 
const [frontLayer, middleLayer, backLayer] = STACK_ORDER[active];
 
const bringToFront = useCallback((layer: LayerIndex) => {
setActive((current) => (current === layer ? current : layer));
}, []);
 
const layers: LayerConfig[] = [
{
index: 0,
src: backImageSrc,
alt: "",
surfaceClassName: backClassName,
},
{
index: 1,
src: middleImageSrc,
alt: "",
surfaceClassName: middleClassName,
},
{
index: 2,
src: imageSrc,
alt: imageAlt,
surfaceClassName: "",
},
];
 
return (
<div
ref={ref}
data-slot="stacked-folder-card"
className={cn("relative h-[20rem] w-[19rem] font-sans", className)}
{...props}
>
{layers.map((layer) => {
const position = positionForLayer(layer.index, active);
 
return (
<div
key={layer.index}
aria-hidden
className={cn(
"pointer-events-none absolute overflow-hidden rounded-[2rem] border-[7px] border-white",
TRANSITION,
POSITION_LAYOUT[position],
layer.surfaceClassName,
)}
>
{layer.src ? (
<Image
src={layer.src}
alt={layer.alt}
fill
sizes="280px"
className="object-cover"
draggable={false}
/>
) : null}
</div>
);
})}
 
<button
type="button"
tabIndex={-1}
aria-label="Show back card"
onMouseEnter={() => bringToFront(backLayer)}
onFocus={() => bringToFront(backLayer)}
className="absolute top-0 bottom-0 left-0 z-40 w-4 cursor-default border-0 bg-transparent p-0"
/>
 
<button
type="button"
tabIndex={-1}
aria-label="Show middle card"
onMouseEnter={() => bringToFront(middleLayer)}
onFocus={() => bringToFront(middleLayer)}
className="absolute top-0 bottom-0 left-4 z-40 w-5 cursor-default border-0 bg-transparent p-0"
/>
 
<button
type="button"
tabIndex={-1}
aria-label="Show front card"
onMouseEnter={() => bringToFront(frontLayer)}
onFocus={() => bringToFront(frontLayer)}
className="absolute top-0 right-0 bottom-0 left-9 z-40 cursor-default border-0 bg-transparent p-0"
/>
</div>
);
},
);
 
StackedFolderCard.displayName = "StackedFolderCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/files/stacked-folder-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.