Goo Profile Hovercard
An avatar that melts upward into a full profile card. Trigger and panel are drawn as one metaball body via an SVG goo filter, so a liquid neck stretches between them instead of a detached card fading in. Includes hover-intent delay, a shimmer skeleton on first fetch, staggered row reveal, and an optimistic Follow control.
CardReactMotionTailwind CSSSVG Filters
CSSshadcn
Manual
Create a file and paste the following code into it.
src/components/ui/goo-popover.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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
"use client";
import {
animate,
useMotionValue,
useMotionValueEvent,
useReducedMotion,
type MotionValue,
} from "motion/react";
import {
cloneElement,
createContext,
isValidElement,
useCallback,
useContext,
useEffect,
useId,
useLayoutEffect,
useMemo,
useRef,
useState,
type ReactElement,
type ReactNode,
type Ref,
} from "react";
import { cn } from "@/lib/cn";
type Side = "top" | "bottom";
type Align = "start" | "center" | "end";
type TriggerMode = "click" | "hover";
type PopupRole = "dialog" | "menu";
const GOO_SPRING = { type: "spring", visualDuration: 0.32, bounce: 0.28 } as const;
const HOVER_OPEN_DELAY = 90;
const HOVER_CLOSE_DELAY = 160;
const lerp = (a: number, b: number, t: number) => a + (b - a) * t;
interface Rect {
x: number;
y: number;
w: number;
h: number;
r: number;
}
interface Geo {
layerW: number;
layerH: number;
left: number;
top: number;
trigger: Rect;
panel: Rect;
}
/** Place the trigger rect and the panel rect inside one shared local box. */
function buildGeo(
tW: number,
tH: number,
cW: number,
cH: number,
side: Side,
align: Align,
gap: number,
panelRadius: number,
): Geo {
const py = side === "bottom" ? tH + gap : -(gap + cH);
const px = align === "start" ? 0 : align === "end" ? tW - cW : (tW - cW) / 2;
const left = Math.min(0, px);
const top = Math.min(0, py);
const layerW = Math.max(tW, px + cW) - left;
const layerH = Math.max(tH, py + cH) - top;
return {
layerW,
layerH,
left,
top,
trigger: { x: -left, y: -top, w: tW, h: tH, r: Math.min(tH / 2, panelRadius) },
panel: { x: px - left, y: py - top, w: cW, h: cH, r: panelRadius },
};
}
function insetFor(rect: Rect, layerW: number, layerH: number): string {
const right = layerW - (rect.x + rect.w);
const bottom = layerH - (rect.y + rect.h);
return `inset(${rect.y}px ${right}px ${bottom}px ${rect.x}px round ${rect.r}px)`;
}
/**
* The band of empty space the pointer must cross between trigger and panel.
* Nothing hoverable lives there, so without a bridge the pointer leaves the
* root mid-journey and a hover popover closes under the user's own cursor.
*/
function bridgeRect(geo: Geo, side: Side, gap: number) {
const t = geo.trigger;
const top = side === "bottom" ? t.y + t.h : geo.panel.y + geo.panel.h;
return { left: 0, top, width: geo.layerW, height: gap };
}
function insetForProgress(geo: Geo, p: number): string {
const t = geo.trigger;
const pn = geo.panel;
return insetFor(
{
x: lerp(t.x, pn.x, p),
y: lerp(t.y, pn.y, p),
w: lerp(t.w, pn.w, p),
h: lerp(t.h, pn.h, p),
r: lerp(t.r, pn.r, p),
},
geo.layerW,
geo.layerH,
);
}
interface GooPopoverContextValue {
open: boolean;
toggle: () => void;
triggerMode: TriggerMode;
side: Side;
align: Align;
gap: number;
panelRadius: number;
gooStrength: number;
popupRole: PopupRole;
gooId: string;
contentId: string;
progress: MotionValue<number>;
/** The measured trigger element — set by GooPopoverTrigger's callback ref. */
triggerEl: HTMLElement | null;
setTriggerEl: (node: HTMLElement | null) => void;
}
const GooPopoverContext = createContext<GooPopoverContextValue | null>(null);
function useGooPopoverContext(component: string) {
const ctx = useContext(GooPopoverContext);
if (!ctx) throw new Error(`${component} must be used within <GooPopover>`);
return ctx;
}
export interface GooPopoverProps {
children: ReactNode;
/** Controlled open state. */
open?: boolean;
/** Uncontrolled initial open state. */
defaultOpen?: boolean;
onOpenChange?: (open: boolean) => void;
/** How the popover is summoned. Default "click". */
trigger?: TriggerMode;
/** Which side of the trigger the panel oozes out of. Default "bottom". */
side?: Side;
/** Alignment along the trigger's edge. Default "center". */
align?: Align;
/** Gap between trigger and panel, in px — the length of the gooey neck. Default 14. */
sideOffset?: number;
/** Corner radius of the open panel, in px. Default 16. */
panelRadius?: number;
/** Blur radius feeding the goo filter — higher melts more. Default 8. */
gooStrength?: number;
/** ARIA role of the panel, mirrored onto the trigger. Default "dialog". */
popupRole?: PopupRole;
className?: string;
}
/**
* Liquid popover root. The trigger and the panel are drawn as one metaball
* body, so opening stretches a gooey neck between them instead of fading a
* detached card in.
*
* @param {ReactNode} children - Trigger and content. [Required]
* @param {boolean} open - Controlled open state. [Optional]
* @param {boolean} defaultOpen - Uncontrolled initial open state. [Optional, default: false]
* @param {function} onOpenChange - Fires whenever open state changes. [Optional]
* @param {"click" | "hover"} trigger - How the popover is summoned. [Optional, default: "click"]
* @param {"top" | "bottom"} side - Side the panel oozes toward. [Optional, default: "bottom"]
* @param {"start" | "center" | "end"} align - Alignment along the trigger edge. [Optional, default: "center"]
* @param {number} sideOffset - Neck length in px. [Optional, default: 14]
* @param {number} panelRadius - Open panel corner radius in px. [Optional, default: 16]
* @param {number} gooStrength - Blur feeding the goo filter. [Optional, default: 8]
* @param {"dialog" | "menu"} popupRole - ARIA role of the panel, mirrored onto the trigger's aria-haspopup. [Optional, default: "dialog"]
* @param {string} className - Extra classes on the root. [Optional]
*
* @example
* <GooPopover trigger="hover" side="top">
* <GooPopoverTrigger><button>@ava</button></GooPopoverTrigger>
* <GooPopoverContent>Profile</GooPopoverContent>
* </GooPopover>
*/
export function GooPopover({
children,
open: controlledOpen,
defaultOpen = false,
onOpenChange,
trigger = "click",
side = "bottom",
align = "center",
sideOffset = 14,
panelRadius = 16,
gooStrength = 8,
popupRole = "dialog",
className,
}: GooPopoverProps) {
const reduce = useReducedMotion() ?? false;
const gooId = useId().replace(/:/g, "");
const contentId = useId();
const rootRef = useRef<HTMLDivElement>(null);
const openTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
// Seed from whichever open source applies on first render, so a controlled
// popover mounted open renders open instead of playing the opening ooze.
const progress = useMotionValue((controlledOpen ?? defaultOpen) ? 1 : 0);
const [internalOpen, setInternalOpen] = useState(defaultOpen);
const [triggerEl, setTriggerEl] = useState<HTMLElement | null>(null);
const controlled = controlledOpen !== undefined;
const open = controlled ? controlledOpen : internalOpen;
const setOpen = useCallback(
(next: boolean) => {
if (!controlled) setInternalOpen(next);
onOpenChange?.(next);
},
[controlled, onOpenChange],
);
const clearTimers = useCallback(() => {
if (openTimer.current) clearTimeout(openTimer.current);
if (closeTimer.current) clearTimeout(closeTimer.current);
openTimer.current = null;
closeTimer.current = null;
}, []);
/** Pointer hover waits out a short intent delay; keyboard focus never does. */
const openHover = useCallback(() => {
clearTimers();
openTimer.current = setTimeout(() => setOpen(true), HOVER_OPEN_DELAY);
}, [clearTimers, setOpen]);
const openNow = useCallback(() => {
clearTimers();
setOpen(true);
}, [clearTimers, setOpen]);
const scheduleClose = useCallback(() => {
clearTimers();
closeTimer.current = setTimeout(() => setOpen(false), HOVER_CLOSE_DELAY);
}, [clearTimers, setOpen]);
const toggle = useCallback(() => setOpen(!open), [setOpen, open]);
useEffect(() => () => clearTimers(), [clearTimers]);
useEffect(() => {
const animation = animate(progress, open ? 1 : 0, reduce ? { duration: 0 } : GOO_SPRING);
return () => animation.stop();
}, [open, progress, reduce]);
useEffect(() => {
if (!open) return;
// Escape restores focus to the trigger when focus was inside the popover —
// closing marks the panel inert, which would otherwise drop focus to
// <body> and strand keyboard users.
const onKey = (e: KeyboardEvent) => {
if (e.key !== "Escape") return;
const focusWasInside = rootRef.current?.contains(document.activeElement) ?? false;
setOpen(false);
if (focusWasInside) triggerEl?.focus();
};
// Trigger and panel share rootRef, so moving between them isn't "outside".
// Registered for hover mode too: on touch devices a hover popover opens
// via synthesized mouseenter, and an outside tap is its only way out.
const onPointer = (e: PointerEvent) => {
if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);
};
window.addEventListener("keydown", onKey);
window.addEventListener("pointerdown", onPointer);
return () => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("pointerdown", onPointer);
};
}, [open, setOpen, triggerEl]);
const ctx = useMemo<GooPopoverContextValue>(
() => ({
open,
toggle,
triggerMode: trigger,
side,
align,
gap: sideOffset,
panelRadius,
gooStrength,
popupRole,
gooId,
contentId,
progress,
triggerEl,
setTriggerEl,
}),
[
open,
toggle,
trigger,
side,
align,
sideOffset,
panelRadius,
gooStrength,
popupRole,
gooId,
contentId,
progress,
triggerEl,
],
);
// All hover-mode interaction lives on the root. Pointer enter/leave use DOM
// containment, so the trigger, the gap bridge, and the panel all count as
// "inside" without per-part handlers (per-part handlers created leave/enter
// races on the way back to the trigger). Focus mirrors that via React's
// delegated focusin/focusout: keyboard travel INTO the panel must not close
// it — only focus leaving the whole root schedules a close.
const hoverHandlers =
trigger === "hover"
? {
onMouseEnter: openHover,
onMouseLeave: scheduleClose,
// Symmetric guards: open only when focus ENTERS from outside the
// root, close only when it EXITS to outside. Without the enter
// guard, Escape's focus-restore onto the trigger would count as an
// entry and reopen the popover it just closed.
onFocus: (event: React.FocusEvent) => {
if (!rootRef.current?.contains(event.relatedTarget as Node | null))
openNow();
},
onBlur: (event: React.FocusEvent) => {
if (!rootRef.current?.contains(event.relatedTarget as Node | null))
scheduleClose();
},
}
: {};
return (
<GooPopoverContext.Provider value={ctx}>
<div
ref={rootRef}
data-state={open ? "open" : "closed"}
className={cn("relative isolate inline-flex", className)}
{...hoverHandlers}
>
{children}
</div>
</GooPopoverContext.Provider>
);
}
/**
* Compose several refs into one cleanup-style callback ref. Object refs are
* nulled on detach; callback refs that return a cleanup (React 19) have that
* cleanup honored, and legacy callbacks are null-invoked — so every composed
* ref sees the contract it was written for.
*/
function mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {
return (node: T | null) => {
const cleanups: Array<() => void> = [];
for (const ref of refs) {
if (typeof ref === "function") {
const cleanup = ref(node);
cleanups.push(typeof cleanup === "function" ? cleanup : () => ref(null));
} else if (ref && typeof ref === "object") {
(ref as React.MutableRefObject<T | null>).current = node;
cleanups.push(() => {
(ref as React.MutableRefObject<T | null>).current = null;
});
}
}
return () => {
for (const cleanup of cleanups) cleanup();
};
};
}
export interface GooPopoverTriggerProps {
/** A single focusable element that opens the popover. [Required] */
children: ReactElement;
}
/**
* Clones its child into the popover trigger — wires handlers, ARIA, and the
* measurement ref without rendering an extra DOM node.
*
* @param {ReactElement} children - Single focusable element. [Required]
*/
export function GooPopoverTrigger({ children }: GooPopoverTriggerProps) {
const ctx = useGooPopoverContext("GooPopoverTrigger");
const child = isValidElement(children)
? (children as ReactElement<Record<string, unknown>>)
: null;
const childProps = child?.props;
const childRef = (childProps as { ref?: Ref<HTMLElement> } | undefined)?.ref;
// Memoized so consumer refs aren't detached/reattached on every re-render;
// setTriggerEl doubles as the measurement hook — attach, swap, and detach
// all flow through it, so geometry follows the live trigger element.
const mergedRef = useMemo(
() => mergeRefs<HTMLElement>(childRef, ctx.setTriggerEl),
[childRef, ctx.setTriggerEl],
);
if (!child || !childProps) return children;
const compose =
(name: string, handler: () => void) =>
(event: { defaultPrevented?: boolean }) => {
(childProps[name] as ((e: unknown) => void) | undefined)?.(event);
if (!event.defaultPrevented) handler();
};
// Hover mode is fully handled by the root's enter/leave/focus delegation;
// adding trigger-level focus handlers here would race the root's guard.
const handlers: Record<string, unknown> =
ctx.triggerMode === "hover" ? {} : { onClick: compose("onClick", ctx.toggle) };
return cloneElement(child, {
...handlers,
ref: mergedRef,
// Above the goo layer (z-[-1]) so the neck reads behind it.
className: cn("relative z-0", childProps.className as string | undefined),
"aria-haspopup": ctx.popupRole,
"aria-expanded": ctx.open,
"aria-controls": ctx.open ? ctx.contentId : undefined,
"data-state": ctx.open ? "open" : "closed",
});
}
const ALIGN_ORIGIN: Record<Align, string> = {
start: "left",
center: "center",
end: "right",
};
export interface GooPopoverContentProps {
children: ReactNode;
className?: string;
/** Accessible name for the dialog/menu panel. */
"aria-label"?: string;
/** Id of the element that names the panel. */
"aria-labelledby"?: string;
}
/**
* The panel. Renders the goo body behind the trigger and clips both the body
* and the content with the same morphing inset, so the surface and the text
* arrive together.
*
* @param {ReactNode} children - Panel content. [Required]
* @param {string} className - Extra classes on the panel. [Optional]
* @param {string} aria-label - Accessible name for the dialog/menu panel. [Optional]
* @param {string} aria-labelledby - Id of the element naming the panel. [Optional]
*/
export function GooPopoverContent({
children,
className,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledby,
}: GooPopoverContentProps) {
const {
side,
align,
gap,
panelRadius,
gooStrength,
popupRole,
gooId,
contentId,
progress,
triggerEl,
open,
triggerMode,
} = useGooPopoverContext("GooPopoverContent");
const measureRef = useRef<HTMLDivElement>(null);
const blobRef = useRef<HTMLDivElement>(null);
const clipRef = useRef<HTMLDivElement>(null);
const geoRef = useRef<Geo | null>(null);
const [sizes, setSizes] = useState({ tW: 0, tH: 0, cW: 0, cH: 0 });
// Keyed on triggerEl (state set by the trigger's callback ref), so a late
// attach, a Content-before-Trigger child order, or a swapped trigger element
// all re-run measurement against the live node.
useLayoutEffect(() => {
const contentNode = measureRef.current;
if (!contentNode) return;
const measure = () => {
const tW = triggerEl?.offsetWidth ?? 0;
const tH = triggerEl?.offsetHeight ?? 0;
const cW = contentNode.offsetWidth;
const cH = contentNode.offsetHeight;
setSizes((prev) =>
prev.tW === tW && prev.tH === tH && prev.cW === cW && prev.cH === cH
? prev
: { tW, tH, cW, cH },
);
};
measure();
const observer = new ResizeObserver(measure);
observer.observe(contentNode);
if (triggerEl) observer.observe(triggerEl);
return () => observer.disconnect();
}, [triggerEl]);
const geo = useMemo(
() => buildGeo(sizes.tW, sizes.tH, sizes.cW, sizes.cH, side, align, gap, panelRadius),
[sizes, side, align, gap, panelRadius],
);
const render = useCallback((g: Geo | null, p: number) => {
if (!g || g.layerW === 0) return;
const clip = insetForProgress(g, p);
if (blobRef.current) blobRef.current.style.clipPath = clip;
if (clipRef.current) {
clipRef.current.style.clipPath = clip;
// The panel takes pointer control only once it has essentially arrived.
// At small progress the clip region still overlaps the TRIGGER (the
// morph starts from its rect), so flipping hit-testing on at open would
// steal the pointer from the trigger mid-morph — the cursor flickers
// pointer→default→pointer and a second click lands on nothing.
clipRef.current.style.pointerEvents = p > 0.85 ? "auto" : "none";
}
}, []);
// The motion-value subscriber reads geo from a ref so it never re-subscribes.
useLayoutEffect(() => {
geoRef.current = geo;
render(geo, progress.get());
}, [geo, progress, render]);
useMotionValueEvent(progress, "change", (p) => render(geoRef.current, p));
return (
<>
{/* Goo filter: blur, sharpen the alpha back into solid shapes, then lay
the crisp original on top so blobs merge with liquid edges. */}
<svg aria-hidden width="0" height="0" className="pointer-events-none absolute">
<title>Goo popover filter</title>
<defs>
<filter id={gooId} x="-50%" y="-50%" width="200%" height="200%">
<feGaussianBlur in="SourceGraphic" stdDeviation={gooStrength} result="blur" />
<feColorMatrix
in="blur"
mode="matrix"
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -10"
result="goo"
/>
<feComposite in="SourceGraphic" in2="goo" operator="atop" />
</filter>
</defs>
</svg>
{/* Goo body: static trigger pill + morphing blob, behind the trigger.
The filter is dropped by CSS, not by the reduce flag — useReducedMotion()
reads false on the server and true on the client, so branching the
inline style here would desync hydration. */}
<div
aria-hidden
className="pointer-events-none absolute z-[-1] [filter:var(--goo-filter)] motion-reduce:[filter:none]"
style={{
left: geo.left,
top: geo.top,
width: geo.layerW,
height: geo.layerH,
"--goo-filter": `url(#${gooId})`,
} as React.CSSProperties}
>
<div
className="absolute bg-popover"
style={{
left: geo.trigger.x,
top: geo.trigger.y,
width: geo.trigger.w,
height: geo.trigger.h,
borderRadius: geo.trigger.r,
}}
/>
<div
ref={blobRef}
className="absolute inset-0 bg-popover"
style={{ clipPath: insetForProgress(geo, progress.get()) }}
/>
</div>
{/* Content, clipped by the same morph. */}
<div
className="pointer-events-none absolute z-10"
style={{ left: geo.left, top: geo.top, width: geo.layerW, height: geo.layerH }}
>
{/* Invisible hit area over the trigger→panel gap. Being a hit target
is its whole job: it keeps the pointer "inside" the root while
crossing, so the root's containment-scoped leave never fires. It
carries no handlers of its own — per-part enter/leave here raced
the root's on the way back to the trigger. */}
{open && triggerMode === "hover" && (
<div
aria-hidden
className="absolute"
style={{ ...bridgeRect(geo, side, gap), pointerEvents: "auto" }}
/>
)}
<div
ref={clipRef}
inert={!open}
className="absolute inset-0"
style={{
clipPath: insetForProgress(geo, progress.get()),
// Progress-driven (see render): hit-testing follows the morph,
// not the open flag, so the trigger keeps the pointer mid-morph.
pointerEvents: progress.get() > 0.85 ? "auto" : "none",
}}
>
<div
ref={measureRef}
id={contentId}
role={popupRole}
aria-label={ariaLabel}
aria-labelledby={ariaLabelledby}
style={{
position: "absolute",
left: geo.panel.x,
top: geo.panel.y,
transformOrigin: `${ALIGN_ORIGIN[align]} ${side === "bottom" ? "top" : "bottom"}`,
}}
className={cn(
"w-max max-w-[min(92vw,20rem)] p-4 text-popover-foreground outline-none",
className,
)}
>
{children}
</div>
</div>
</div>
</>
);
}
Update the import paths to match your project setup.
Similar components
Resource details
PublishedJuly 10, 2026
CategoryCard
ReactMotionTailwind CSSSVG Filters