-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathDocumentFanStack.js
More file actions
163 lines (150 loc) · 4.51 KB
/
DocumentFanStack.js
File metadata and controls
163 lines (150 loc) · 4.51 KB
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
import { motion } from "framer-motion";
import { useState } from "react";
const MOCK_CONTENT = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
vehicula risus non lorem elementum, sed placerat orci suscipit.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia curae; Vivamus sit amet semper urna. Sed euismod,
ipsum at facilisis pulvinar, mauris urna hendrerit arcu, id
sollicitudin dolor lectus vitae ligula. Duis auctor nisi vel ex
tincidunt, vitae scelerisque erat tincidunt.`;
function DocumentCard({
content,
type = "Mock",
index,
totalCards,
hoveredIndex,
onHover,
onLeave,
}) {
const springConfig = { type: "spring", stiffness: 300, damping: 30 };
const baseOffset = index * 15;
const expandedOffset = index * 25;
const baseRotation = (index - (totalCards - 1) / 2) * 8;
const expandedRotation = (index - (totalCards - 1) / 2) * 15;
const translateX = hoveredIndex !== null ? expandedOffset : baseOffset;
const translateY = hoveredIndex === index && index > 0 ? -40 : 0;
const scale = hoveredIndex === index ? 1.05 : 1;
const zIndex = totalCards - index;
const rotate = hoveredIndex !== null ? expandedRotation : baseRotation;
// Separar título de las líneas de guiones
const isFileName = content && !content.includes("\n");
const title = isFileName ? content : content?.split("\n")[0] || "";
const dashLines = Array(12).fill("━━━━━━━━━━━━━━━━━━━━━━━━").join("\n");
return (
<motion.div
animate={{
x: translateX,
y: translateY,
scale: scale,
rotate: rotate,
zIndex: zIndex,
}}
transition={springConfig}
onHoverStart={() => onHover(index)}
onHoverEnd={onLeave}
style={{
width: "140px",
height: "190px",
background: "#ffffff",
borderRadius: 8,
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
padding: "16px",
paddingBottom: "8px",
overflow: "hidden",
cursor: "pointer",
position: "absolute",
left: 0,
top: 0,
}}
>
{/* Título con truncamiento de una línea */}
<div
style={{
margin: 0,
fontFamily: "Georgia, serif",
fontSize: "11px",
lineHeight: "1.3",
color: "#424242",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
marginBottom: "8px",
}}
>
{title}
</div>
{/* Líneas de guiones */}
<div
style={{
margin: 0,
fontFamily: "Georgia, serif",
fontSize: "11px",
lineHeight: "1.3",
color: "rgba(66, 66, 66, 0.4)",
overflow: "hidden",
display: "-webkit-box",
WebkitLineClamp: 10,
WebkitBoxOrient: "vertical",
}}
>
{dashLines}
</div>
</motion.div>
);
}
export default function DocumentPeekStack({ documents = [] }) {
const [hoveredIndex, setHoveredIndex] = useState(null);
const defaultDocuments = [
{ content: MOCK_CONTENT },
{ content: MOCK_CONTENT },
{ content: MOCK_CONTENT },
{ content: MOCK_CONTENT },
];
// Si documents es un array de strings (nombres de archivos), convertirlos a objetos
const processedDocuments = documents.map((doc) => {
if (typeof doc === "string") {
return {
content: doc,
type: "Document",
};
}
return doc;
});
const docsToRender =
processedDocuments.length > 0 ? processedDocuments : defaultDocuments;
// Calcular ancho necesario basado en número de documentos
const containerWidth = Math.max(200, docsToRender.length * 20 + 140);
return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "250px",
position: "relative",
width: "fit-content",
}}
>
<div
style={{
position: "relative",
width: `${containerWidth}px`,
height: "190px",
}}
>
{docsToRender.map((doc, index) => (
<DocumentCard
key={index}
content={doc.content}
type={doc.type}
index={index}
totalCards={docsToRender.length}
hoveredIndex={hoveredIndex}
onHover={setHoveredIndex}
onLeave={() => setHoveredIndex(null)}
/>
))}
</div>
</div>
);
}