Holo Card
An interactive 3D holographic profile card with tilt effects, sparkle animations, and flip functionality.
Category
CardReact
CSS
Custom CSS
Manual
Create a file and paste the following code into it.
holo-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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
"use client";
import Image from "next/image";
import type React from "react";
import { useRef, useState, useCallback } from "react";
import Tilt from "react-parallax-tilt";
import { cn } from "@/lib/cn";
import "./holo-card.css";
// ============================================================================
// Types
// ============================================================================
export interface HoloCardDisplayData {
/** Primary name displayed on the card */
name: string;
/** Secondary text (e.g., personality phrase, tagline) */
subtitle?: string;
/** Extended description shown on the back of the card */
description?: string;
/** Primary identifier (e.g., user number, ID) */
primaryId?: string | number;
/** Secondary info (e.g., member since date) */
secondaryInfo?: string;
/** Background image URL */
backgroundImage?: string;
/** Badge/tag text (e.g., house name, role) */
badge?: string;
/** Overlay color for the card */
overlayColor?: string;
/** Overlay opacity (0-100) */
overlayOpacity?: number;
}
export interface HoloCardBranding {
/** Primary logo image URL */
logo?: string;
/** Logo alt text */
logoAlt?: string;
/** Icon shown in various places */
icon?: string;
/** Icon alt text */
iconAlt?: string;
}
export interface HoloCardProps {
/** Card display data */
data: HoloCardDisplayData;
/** Card dimensions */
height?: number;
width?: number;
/** Show sparkle animation effect */
showSparkles?: boolean;
/** Force card to show front or back (disables flip) */
forceSide?: "front" | "back";
/** Custom branding (logos, icons) */
branding?: HoloCardBranding;
/** Additional CSS classes */
className?: string;
/** Children rendered inside the card */
children?: React.ReactNode;
/** Callback when card is flipped */
onFlip?: (isFlipped: boolean) => void;
}
// ============================================================================
// Default Values
// ============================================================================
const DEFAULT_BACKGROUND =
"https://i.pinimg.com/1200x/27/0a/74/270a74bdc412f9eeae4d2403ebc9bd63.jpg";
const DEFAULT_BRANDING: HoloCardBranding = {
logo: "/images/logos/text_w_logo_white.webp",
logoAlt: "Logo",
icon: "/images/logos/experience_logo.svg",
iconAlt: "Icon",
};
// ============================================================================
// Component
// ============================================================================
export const HoloCard = ({
data,
height = 446,
width = 320,
showSparkles = true,
forceSide,
branding = DEFAULT_BRANDING,
className,
children,
onFlip,
}: HoloCardProps) => {
const [hover, setHover] = useState(false);
const [animated, setAnimated] = useState(true);
const [isFlipped, setIsFlipped] = useState(false);
const [activeBackgroundPosition, setActiveBackgroundPosition] = useState({
tp: 0,
lp: 0,
});
const ref = useRef<HTMLDivElement>(null);
const {
name,
subtitle,
description,
primaryId,
secondaryInfo,
backgroundImage = DEFAULT_BACKGROUND,
badge,
overlayColor,
overlayOpacity = 40,
} = data;
const handleCardClick = useCallback(() => {
if (!forceSide) {
const newFlippedState = !isFlipped;
setIsFlipped(newFlippedState);
onFlip?.(newFlippedState);
}
}, [forceSide, isFlipped, onFlip]);
const handleOnMouseMove = useCallback(
(event: React.MouseEvent<HTMLDivElement>) => {
setAnimated(false);
setHover(true);
const card = ref.current;
const l = event.nativeEvent.offsetX;
const t = event.nativeEvent.offsetY;
const h = card ? card.clientHeight : 0;
const w = card ? card.clientWidth : 0;
const px = Math.abs(Math.floor((100 / w) * l) - 100);
const py = Math.abs(Math.floor((100 / h) * t) - 100);
const lp = 50 + (px - 50) / 1.5;
const tp = 50 + (py - 50) / 1.5;
setActiveBackgroundPosition({ lp, tp });
},
[],
);
const handleOnTouchMove = useCallback(
(event: React.TouchEvent<HTMLDivElement>) => {
setAnimated(false);
setHover(true);
const card = ref.current;
if (!card) return;
const touch = event.touches[0];
const rect = card.getBoundingClientRect();
const l = touch.clientX - rect.left;
const t = touch.clientY - rect.top;
const h = card.clientHeight;
const w = card.clientWidth;
const px = Math.abs(Math.floor((100 / w) * l) - 100);
const py = Math.abs(Math.floor((100 / h) * t) - 100);
const lp = 50 + (px - 50) / 1.5;
const tp = 50 + (py - 50) / 1.5;
setActiveBackgroundPosition({ lp, tp });
},
[],
);
const handleOnMouseOut = useCallback(() => {
setHover(false);
setAnimated(true);
}, []);
const effectiveFlipped = forceSide ? forceSide === "back" : isFlipped;
// Static mode styles for download/static rendering
const containerStyle = forceSide
? {
perspective: "none",
transform: "none",
}
: {
perspective: "1000px",
cursor: "pointer",
};
const innerStyle = forceSide
? {
transform: "none",
position: "relative" as const,
height: `${height}px`,
width: `${width}px`,
}
: {
transformStyle: "preserve-3d" as const,
transform: effectiveFlipped ? "rotateY(180deg)" : "rotateY(0deg)",
height: `${height}px`,
width: `${width}px`,
};
const frontStyle = forceSide
? {
display: forceSide === "front" ? "block" : "none",
position: "absolute" as const,
inset: 0,
}
: {
position: "absolute" as const,
inset: 0,
backfaceVisibility: "hidden" as const,
WebkitBackfaceVisibility: "hidden" as const,
};
const backStyle = forceSide
? {
display: forceSide === "back" ? "block" : "none",
position: "absolute" as const,
inset: 0,
transform: "none",
}
: {
position: "absolute" as const,
inset: 0,
backfaceVisibility: "hidden" as const,
WebkitBackfaceVisibility: "hidden" as const,
transform: "rotateY(180deg)",
};
const holoCardClasses = cn(
"holo-card",
hover && "holo-card--active",
animated && "holo-card--animated",
showSparkles && "holo-card--sparkles",
);
const holoCardStyle = {
"--holo-width": `${width}px`,
"--holo-height": `${height}px`,
backgroundImage: `url(${backgroundImage})`,
backgroundPosition: hover
? `${activeBackgroundPosition.lp}% ${activeBackgroundPosition.tp}%`
: "center",
} as React.CSSProperties;
// Overlay component
const OverlayLayer = overlayColor ? (
<div
className="pointer-events-none absolute inset-0 z-[3]"
style={{
background: overlayColor,
mixBlendMode: "overlay",
opacity: overlayOpacity / 100,
}}
/>
) : null;
// Front card content
const FrontContent = (
<div className="pointer-events-none absolute z-[2] flex h-full w-full flex-col items-start justify-end p-3 text-white transition">
{/* Top bar with logo and badge */}
<div className="absolute top-4 left-0 flex w-full justify-between px-3">
{branding.logo && (
<div className="rounded-full bg-white/30 p-1 px-2 font-serif text-xl font-light text-white/70 backdrop-blur-md">
<Image
src={branding.logo}
alt={branding.logoAlt || "Logo"}
width={100}
height={30}
className="object-contain"
/>
</div>
)}
{badge && (
<div className="rounded-full bg-white/20 p-1 px-4 font-serif text-xl font-light text-white/70 backdrop-blur-md">
{badge}
</div>
)}
</div>
{/* Background icon */}
{branding.icon && (
<Image
src={branding.icon}
alt={branding.iconAlt || "Icon"}
className="scale-125 opacity-10"
fill
/>
)}
{/* Bottom info card */}
<div className="relative flex w-full flex-col gap-1 overflow-hidden rounded-2xl bg-black/20 p-3 backdrop-blur-md">
<div className="font-serif text-4xl font-bold text-white">{name}</div>
{subtitle && (
<div className="mb-10 font-light text-white italic">{subtitle}</div>
)}
<div className="flex w-full items-center justify-between">
<div className="flex flex-col items-start gap-1">
{primaryId && (
<span className="text-sm text-white/80">User {primaryId}</span>
)}
{secondaryInfo && (
<span className="text-xs text-white/50">{secondaryInfo}</span>
)}
</div>
{branding.icon && (
<div className="flex gap-2">
<Image
src={branding.icon}
alt={branding.iconAlt || "Icon"}
width={30}
height={30}
/>
</div>
)}
</div>
</div>
</div>
);
// Back card content
const BackContent = (
<div className="pointer-events-none absolute z-[2] flex h-full w-full flex-col items-start justify-between p-3 text-white">
<div className="flex w-full flex-col gap-4">
{/* Top bar */}
<div className="flex items-center justify-between">
{branding.logo && (
<div className="rounded-full bg-white/30 p-1 px-2 backdrop-blur-md">
<Image
src={branding.logo}
alt={branding.logoAlt || "Logo"}
width={80}
height={24}
className="object-contain"
/>
</div>
)}
{badge && (
<div className="rounded-full bg-white/20 p-1 px-3 font-serif text-xl font-light text-white/70 backdrop-blur-md">
{badge}
</div>
)}
</div>
{/* Bio section */}
<div className="relative overflow-hidden rounded-2xl bg-black/20 p-4 backdrop-blur-md">
<div className="mb-2 font-serif text-2xl font-bold text-white">
{name}
</div>
{subtitle && (
<div className="mb-4 text-sm font-light text-white/80 italic">
{subtitle}
</div>
)}
{description && (
<p className="text-sm text-white/80">{description}</p>
)}
</div>
</div>
{/* Bottom info */}
<div className="flex w-full items-center justify-between rounded-xl bg-black/20 p-3 backdrop-blur-md">
<div className="flex flex-col gap-1">
<span className="text-xs text-white/50">Member Since</span>
<span className="text-sm font-medium text-white/80">
{secondaryInfo || "—"}
</span>
</div>
<div className="flex flex-col items-end gap-1">
<span className="text-xs text-white/50">User ID</span>
<span className="text-sm font-medium text-white/80">
{primaryId || "—"}
</span>
</div>
</div>
</div>
);
// Render card face (either static or with tilt)
const renderCardFace = (
content: React.ReactNode,
isStatic: boolean = false,
) => {
if (isStatic || forceSide) {
return (
<div className="relative h-full w-full overflow-hidden rounded-2xl shadow-xl">
{OverlayLayer}
{content}
<div ref={ref} className={holoCardClasses} style={holoCardStyle}>
{children}
</div>
</div>
);
}
return (
<Tilt className="relative h-full w-full overflow-hidden rounded-2xl p-0! shadow-xl">
{OverlayLayer}
{content}
<div
ref={ref}
className={holoCardClasses}
style={holoCardStyle}
onMouseMove={handleOnMouseMove}
onTouchMove={handleOnTouchMove}
onMouseOut={handleOnMouseOut}
onBlur={handleOnMouseOut}
>
{children}
</div>
</Tilt>
);
};
const handleKeyDown = useCallback(
(event: React.KeyboardEvent) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
handleCardClick();
}
},
[handleCardClick],
);
return (
<div
className={cn(forceSide ? "" : "perspective-1000", className)}
onClick={handleCardClick}
onKeyDown={!forceSide ? handleKeyDown : undefined}
role={!forceSide ? "button" : undefined}
tabIndex={!forceSide ? 0 : undefined}
title={
!forceSide ? `Profile card for ${name}. Click to flip.` : undefined
}
style={containerStyle}
>
<div
className={
forceSide ? "relative" : "relative transition-transform duration-700"
}
style={innerStyle}
>
{/* Front Side */}
<div style={frontStyle}>
{renderCardFace(FrontContent, !!forceSide)}
</div>
{/* Back Side */}
<div style={backStyle}>{renderCardFace(BackContent, !!forceSide)}</div>
</div>
</div>
);
};
export default HoloCard;
Update the import paths to match your project setup.