Components64 / 118
Avatar Dock
A round plus that springs open into a column of people. Press it and the plus turns into a minus while a pill springs up out of it and avatars pop in one after another, bottom to top. Glide over them and they swell like a dock, with each person's name sliding out beside them; press again and they leave top first as the pill sinks back into the button.
Expanding buttonExpanding buttonAvatarsAvatarsDock magnifyDock magnifyElasticElasticKeyboardKeyboardGSAPGSAP
Press the plusGlide over the people
Tweak
LIVELIVEShape
46px
Names slide out
Colours
#dcdcdc
#8e8e8e
#1a1a1a
Usage
Follows your tweaks.
usage.tsx
import { AvatarDock } from "@/components/inreact/avatar-dock";
const team = [
{ name: "Maya Chen", role: "Design", src: "/team/maya.jpg" },
{ name: "Leo Hart", role: "Engineering", src: "/team/leo.jpg" },
// ...
];
export function Collaborators() {
return <AvatarDock people={team} onSelect={(person) => console.log(person.name)} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/avatar-dock.jsonOr copy the source
Install the dependencies, then save this as components/inreact/avatar-dock.tsx.
terminal
npm install gsapcomponents/inreact/avatar-dock.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useEffect, useRef, useState, type KeyboardEvent } from "react";
/**
* Avatar Dock: a "+" that pours open into a liquid column of people.
*
* The button, the pill and a bubble behind every person are one body of
* liquid (a metaball field drawn with Three.js, softly lit, no outlines).
* Press the plus: it turns into a minus and the people rise out of the button
* as drops, flowing up through the column on springs and settling with a
* little bounce. Glide over them and the one under the cursor swells, the
* liquid bulging with it, while their name slides out beside them. Pull a
* person out and a liquid neck stretches after them until it snaps; let go and
* they spring back and merge. Closed, the button leans toward the cursor.
*
* <AvatarDock people={[{ name: "Maya", role: "Design", src: "/maya.jpg" }, ...]} onSelect={(p) => ...} />
*/
export interface DockPerson {
name: string;
role?: string;
src: string;
/** CSS object-position for the photo (default: faces sit high). */
focus?: string;
}
export interface AvatarDockProps {
people: DockPerson[];
/** Button diameter, px. */
size?: number;
/** The liquid. */
surface?: string;
/** The round button. */
button?: string;
/** The plus / minus. */
ink?: string;
/** Which side the name slides out on. */
labelSide?: "left" | "right";
defaultOpen?: boolean;
onOpenChange?: (open: boolean) => void;
onSelect?: (person: DockPerson, index: number) => void;
className?: string;
"aria-label"?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const MAX = 8;
const VERT = /* glsl */ `
varying vec2 vUv;
void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }
`;
// one body of liquid: a capsule (the column), the button disc and a bubble per person,
// melted together with a smooth minimum, lit as a soft dome with a soft shadow beneath
const FRAG = /* glsl */ `
precision highp float;
uniform vec2 uRes;
uniform vec3 uBtn; // x, y, r
uniform vec4 uCol; // x, y0, y1, r (capsule)
uniform vec3 uB[${MAX}]; // bubbles: x, y, r
uniform float uK[${MAX}]; // how much each bubble melts into the rest
uniform int uN;
uniform float uKBase;
uniform vec3 uSurface;
uniform vec3 uButton;
varying vec2 vUv;
float smin(float a, float b, float k) {
if (k <= 0.0) return min(a, b);
float h = max(k - abs(a - b), 0.0) / k;
return min(a, b) - h * h * k * 0.25;
}
float capsule(vec2 p, vec2 a, vec2 b, float r) {
vec2 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-4), 0.0, 1.0);
return length(pa - ba * h) - r;
}
float field(vec2 p, out float dBtn) {
dBtn = length(p - uBtn.xy) - uBtn.z;
float d = dBtn;
if (uCol.w > 0.5) d = smin(d, capsule(p, vec2(uCol.x, uCol.y), vec2(uCol.x, uCol.z), uCol.w), uKBase);
for (int i = 0; i < ${MAX}; i++) {
if (i >= uN) break;
if (uB[i].z > 0.1) d = smin(d, length(p - uB[i].xy) - uB[i].z, uK[i]);
}
return d;
}
void main() {
vec2 p = vUv * uRes;
float dBtn;
float d = field(p, dBtn);
// soft shadow: the same shape, lower down, blurred by distance
float dS;
float ds = field(p + vec2(0.0, 7.0), dS);
float shadow = (1.0 - smoothstep(-10.0, 18.0, ds)) * 0.28;
float a = 1.0 - smoothstep(-0.8, 0.8, d);
// a dome: thicker toward the middle of the body, lit from the upper left
float r = max(uCol.w, uBtn.z);
float h = sqrt(clamp(-d / (r * 0.9), 0.0, 1.0));
vec3 n = normalize(vec3(-dFdx(h) * 2.2, -dFdy(h) * 2.2, 1.0));
vec3 L = normalize(vec3(-0.45, 0.65, 0.62));
float diff = dot(n, L);
float spec = pow(max(dot(reflect(-L, n), vec3(0.0, 0.0, 1.0)), 0.0), 26.0);
float onBtn = 1.0 - smoothstep(-0.8, 0.8, dBtn);
vec3 base = mix(uSurface, uButton, onBtn);
vec3 col = base * (0.9 + 0.14 * diff) + vec3(spec * 0.22);
// a whisper of depth right at the rim, so the edge reads without a line
col *= 1.0 - 0.06 * (1.0 - smoothstep(0.0, 3.0, -d));
float outA = max(a, shadow * (1.0 - a));
gl_FragColor = vec4(col * a, outA); // the shadow is black: alpha only
}
`;
function vec3Of(c: string) {
const col = new THREE.Color(c);
return new THREE.Vector3(col.r, col.g, col.b);
}
export function AvatarDock({
people,
size = 46,
surface = "#dcdcdc",
button = "#8e8e8e",
ink = "#1a1a1a",
labelSide = "right",
defaultOpen = false,
onOpenChange,
onSelect,
className,
"aria-label": ariaLabel = "People",
}: AvatarDockProps) {
const [open, setOpen] = useState(defaultOpen);
const openRef = useRef(open);
openRef.current = open;
const rootRef = useRef<HTMLDivElement>(null);
const hostRef = useRef<HTMLDivElement>(null);
const btnRef = useRef<HTMLButtonElement>(null);
const barRef = useRef<SVGLineElement>(null);
const tagRef = useRef<HTMLDivElement>(null);
const items = useRef<(HTMLButtonElement | null)[]>([]);
const [hot, setHot] = useState<number | null>(null);
const hotRef = useRef<number | null>(null);
hotRef.current = hot;
const lastHot = useRef(0);
if (hot !== null) lastHot.current = hot;
const cb = useRef({ onSelect, people });
cb.current = { onSelect, people };
const n = Math.min(people.length, MAX);
const pad = Math.round(size * 0.11);
const av = Math.round(size * 0.94);
const gap = Math.round(size * 0.1);
const W = size + pad * 2;
const closedH = W;
const openH = pad * 2 + size + n * (av + gap);
const M = Math.round(size * 2.6); // room around the dock for bulges, pulls and the shadow
// the physics lives in the effect; React only renders the DOM once
const sim = useRef<{ setOpen: (o: boolean) => void } | null>(null);
useEffect(() => {
const root = rootRef.current, host = hostRef.current, btn = btnRef.current;
if (!root || !host || !btn) return;
const still = reduced();
const CW = W + M * 2, CH = openH + M * 2;
const bx = M + W / 2, by = M + closedH / 2; // the button centre, canvas px, y up
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;pointer-events:none;";
host.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, alpha: true, premultipliedAlpha: true, antialias: false });
} catch {
canvas.remove();
return;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(CW, CH, false);
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
const cam = new THREE.Camera();
const mat = new THREE.ShaderMaterial({
vertexShader: VERT,
fragmentShader: FRAG,
transparent: true,
depthTest: false,
blending: THREE.CustomBlending,
blendSrc: THREE.OneFactor,
blendDst: THREE.OneMinusSrcAlphaFactor,
uniforms: {
uRes: { value: new THREE.Vector2(CW, CH) },
uBtn: { value: new THREE.Vector3(bx, by, size / 2) },
uCol: { value: new THREE.Vector4(bx, by, by, 0) },
uB: { value: Array.from({ length: MAX }, () => new THREE.Vector3()) },
uK: { value: new Array(MAX).fill(0) },
uN: { value: n },
uKBase: { value: size * 0.5 },
uSurface: { value: vec3Of(surface) },
uButton: { value: vec3Of(button) },
},
});
const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), mat);
quad.frustumCulled = false;
scene.add(quad);
const u = mat.uniforms;
// springs: value, velocity, target, stiffness, damping
type Spring = { v: number; vel: number; t: number; k: number; c: number };
const sp = (v: number, k: number, c: number): Spring => ({ v, vel: 0, t: v, k, c });
const advance = (s: Spring, dt: number) => {
const a = s.k * (s.t - s.v) - s.c * s.vel;
s.vel += a * dt;
s.v += s.vel * dt;
};
const settled = (s: Spring) => Math.abs(s.t - s.v) < 0.005 && Math.abs(s.vel) < 0.005;
const openS = sp(openRef.current ? 1 : 0, 150, 15); // the column: a little liquid wobble
const press = sp(1, 420, 22);
const leanX = sp(0, 160, 18), leanY = sp(0, 160, 18);
const slot = (i: number) => size / 2 + gap + av / 2 + (n - 1 - i) * (av + gap);
const P = Array.from({ length: n }, (_, i) => ({
x: sp(0, 230, 21),
y: sp(openRef.current ? slot(i) : 0, 170, 16),
mag: sp(1, 260, 21),
vis: sp(openRef.current ? 1 : 0, 200, 22),
}));
let dragging = -1;
let dragPos = { x: 0, y: 0 };
let downAt = { x: 0, y: 0 };
let moved = false;
let ptr = { x: 1e4, y: 1e4, in: false };
const timers: gsap.core.Tween[] = [];
const clearTimers = () => timers.splice(0).forEach((t) => t.kill());
const setOpenSim = (o: boolean) => {
clearTimers();
openS.t = o ? 1 : 0;
if (still) openS.v = openS.t;
P.forEach((p, i) => {
// open: the bottom one first; close: the top one first
const order = o ? n - 1 - i : i;
const go = () => {
p.y.t = o ? slot(i) : 0;
p.x.t = 0;
p.vis.t = o ? 1 : 0;
if (still) {
p.y.v = p.y.t;
p.vis.v = p.vis.t;
}
};
if (still) go();
else timers.push(gsap.delayedCall(order * (o ? 0.06 : 0.035) + (o ? 0.04 : 0), go));
});
gsap.to(barRef.current, { rotation: o ? 90 : 0, svgOrigin: "12 12", duration: still ? 0 : 0.5, ease: "back.out(2.2)" });
wake();
};
// pointer: hover magnification, pulls, magnetic lean
const local = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
return { x: e.clientX - (r.left + W / 2), y: r.top + closedH / 2 - e.clientY }; // from the button centre, y up
};
const onMove = (e: PointerEvent) => {
ptr = { ...local(e), in: true };
if (dragging >= 0) {
dragPos = { x: ptr.x, y: ptr.y };
if (Math.hypot(ptr.x - downAt.x, ptr.y - downAt.y) > 5) moved = true;
}
wake();
};
const onUp = () => {
if (dragging < 0) return;
const i = dragging;
dragging = -1;
root.style.cursor = "";
// a tap picks; a pull springs back into the liquid
if (!moved) cb.current.onSelect?.(cb.current.people[i], i);
P[i].x.t = 0;
P[i].y.t = openRef.current ? slot(i) : 0;
wake();
};
const onDown = (e: PointerEvent) => {
const el = (e.target as HTMLElement).closest("[data-person]") as HTMLElement | null;
if (!el || !openRef.current) return;
dragging = Number(el.dataset.person);
downAt = local(e);
dragPos = downAt;
moved = false;
root.style.cursor = "grabbing";
e.preventDefault();
};
window.addEventListener("pointermove", onMove, { passive: true });
window.addEventListener("pointerup", onUp);
root.addEventListener("pointerdown", onDown);
const onBtnDown = () => {
press.t = 0.88;
wake();
};
const onBtnUp = () => {
press.t = 1;
wake();
};
btn.addEventListener("pointerdown", onBtnDown);
btn.addEventListener("pointerup", onBtnUp);
btn.addEventListener("pointerleave", onBtnUp);
let visible = true;
const io = new IntersectionObserver(([e]) => (visible = e.isIntersecting));
io.observe(root);
let awake = true;
function wake() {
awake = true;
}
const tick = (_t: number, dms: number) => {
if (!awake || !visible) return;
const dt = Math.min(0.033, dms / 1000);
const o = openRef.current;
// magnetic lean while closed
const near = Math.hypot(ptr.x, ptr.y);
const pull = !o && ptr.in && near < size * 2.2 ? 1 - near / (size * 2.2) : 0;
leanX.t = still ? 0 : ptr.x * 0.12 * pull;
leanY.t = still ? 0 : ptr.y * 0.12 * pull;
// dock magnification from the cursor's height along the column
P.forEach((p, i) => {
const d = Math.abs(ptr.y - p.y.v) / (av * 1.5);
const inX = Math.abs(ptr.x) < W * 1.6;
p.mag.t = o && inX && !still && dragging < 0 ? 1 + 0.24 * Math.max(0, 1 - d) : 1;
if (i === dragging) {
p.x.t = dragPos.x;
p.y.t = dragPos.y;
}
});
let moving = dragging >= 0;
for (const s of [openS, press, leanX, leanY]) if (!settled(s)) (advance(s, dt), (moving = true));
for (const p of P) for (const s of [p.x, p.y, p.mag, p.vis]) if (!settled(s)) (advance(s, dt), (moving = true));
const lx = leanX.v, ly = leanY.v;
u.uBtn.value.set(bx + lx, by + ly, (size / 2) * press.v);
btn.style.transform = `translate(${lx}px, ${-ly}px) scale(${press.v})`;
// the column grows to hold everyone, its width easing out from the button's
const ov = Math.max(0, openS.v);
u.uCol.value.set(bx, by, by + ov * (openH - closedH), ov > 0.01 ? THREE.MathUtils.lerp(size / 2, W / 2, Math.min(1, ov)) : 0);
// people: DOM photos ride on the liquid bubbles
P.forEach((p, i) => {
const vis = Math.min(1, Math.max(0, p.vis.v));
const s = vis * p.mag.v;
u.uB.value[i].set(bx + p.x.v, by + p.y.v, Math.max(0, (av / 2) * s + pad * 0.7 * vis));
// a pulled bubble melts less and less, until its liquid neck snaps
const away = Math.hypot(p.x.v, p.y.v - slot(i));
// at rest the column is a clean pill; bubbles melt strongly only while they move or are pulled
const speed = Math.min(1, Math.hypot(p.x.vel, p.y.vel) / (av * 6));
const melt = (0.16 + 0.42 * Math.max(speed, Math.min(1, away / av))) * size;
u.uK.value[i] = melt * (1 - THREE.MathUtils.smoothstep(away, av * 0.9, av * 2.4));
const el = items.current[i];
if (el) {
el.style.transform = `translate(${p.x.v}px, ${-p.y.v}px) scale(${Math.max(0.001, s)})`;
el.style.opacity = String(Math.min(1, Math.max(0, vis * 1.4 - 0.15)));
el.style.zIndex = i === dragging ? "5" : "2";
}
});
// the name tag rides with the hovered person
const tag = tagRef.current, h = hotRef.current;
if (tag && h !== null && P[h]) tag.style.transform = `translate(0, ${-P[h].y.v}px)`;
renderer.render(scene, cam);
// sleep when everything has settled and nothing is held
if (!moving) awake = false;
};
gsap.ticker.add(tick);
sim.current = { setOpen: setOpenSim };
setOpenSim(openRef.current);
return () => {
gsap.ticker.remove(tick);
clearTimers();
window.removeEventListener("pointermove", onMove);
window.removeEventListener("pointerup", onUp);
root.removeEventListener("pointerdown", onDown);
btn.removeEventListener("pointerdown", onBtnDown);
btn.removeEventListener("pointerup", onBtnUp);
btn.removeEventListener("pointerleave", onBtnUp);
io.disconnect();
mat.dispose();
quad.geometry.dispose();
renderer.dispose();
canvas.remove();
sim.current = null;
};
// rebuilt when the shape or colours change; people are read live
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [size, n, surface, button]);
// React state -> physics
useEffect(() => {
sim.current?.setOpen(open);
if (!open) setHot(null);
}, [open]);
// the tag fades in and out
useEffect(() => {
const tag = tagRef.current;
if (!tag) return;
gsap.to(tag, { autoAlpha: hot === null ? 0 : 1, duration: hot === null ? 0.16 : 0.3, ease: "power2.out", overwrite: true });
}, [hot]);
// click away / Escape closes
useEffect(() => {
if (!open) return;
const away = (e: PointerEvent) => !rootRef.current?.contains(e.target as Node) && toggle(false);
document.addEventListener("pointerdown", away);
return () => document.removeEventListener("pointerdown", away);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
const toggle = (next = !open) => {
setOpen(next);
onOpenChange?.(next);
};
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape" && open) {
toggle(false);
btnRef.current?.focus();
}
if (!open || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
e.preventDefault();
const list = items.current.filter(Boolean) as HTMLButtonElement[];
const i = list.indexOf(document.activeElement as HTMLButtonElement);
const next = e.key === "ArrowUp" ? (i < 0 ? list.length - 1 : Math.max(0, i - 1)) : i < 0 ? 0 : Math.min(list.length - 1, i + 1);
list[next]?.focus();
};
const person = people[lastHot.current] ?? null;
const fs = Math.max(11, Math.round(size * 0.27));
return (
<div ref={rootRef} className={["relative inline-block touch-none select-none", className].filter(Boolean).join(" ")} style={{ width: W, height: closedH }} onKeyDown={onKey}>
{/* the liquid (Three.js), with room around it for bulges, pulls and the shadow */}
<div ref={hostRef} aria-hidden="true" className="pointer-events-none absolute" style={{ left: -M, bottom: -M, width: W + M * 2, height: openH + M * 2 }} />
{/* people ride on the liquid bubbles */}
<div role="group" aria-label={ariaLabel} aria-hidden={!open}>
{people.slice(0, n).map((p, i) => (
<button
key={p.name + i}
ref={(el) => {
items.current[i] = el;
}}
data-person={i}
type="button"
tabIndex={open ? 0 : -1}
aria-label={p.role ? `${p.name}, ${p.role}` : p.name}
onPointerEnter={() => setHot(i)}
onPointerLeave={() => setHot((h) => (h === i ? null : h))}
onFocus={() => setHot(i)}
onBlur={() => setHot(null)}
onKeyDown={(e) => (e.key === "Enter" || e.key === " ") && onSelect?.(p, i)}
className="absolute block cursor-grab overflow-hidden rounded-full opacity-0 outline-none focus-visible:ring-2 focus-visible:ring-black/40"
style={{ width: av, height: av, left: W / 2 - av / 2, top: closedH / 2 - av / 2, willChange: "transform", boxShadow: "inset 0 0 0 1px rgba(0,0,0,.05)" }}
>
<img src={p.src} alt="" draggable={false} className="pointer-events-none h-full w-full object-cover" style={{ objectPosition: p.focus ?? "50% 22%" }} />
</button>
))}
</div>
{/* the name tag */}
<div
ref={tagRef}
aria-hidden="true"
className="pointer-events-none invisible absolute z-10 whitespace-nowrap rounded-full px-3 py-1.5 opacity-0"
style={{
[labelSide === "right" ? "left" : "right"]: W + 12,
top: closedH / 2 - fs * 0.95,
background: "rgba(18,18,20,.92)",
color: "#fff",
fontSize: fs,
boxShadow: "0 1px 2px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.16)",
}}
>
<span className="font-medium">{person?.name}</span>
{person?.role && <span className="ml-1.5 opacity-55">{person.role}</span>}
</div>
{/* the button: its disc is drawn by the liquid; this carries the icon and the events */}
<button
ref={btnRef}
type="button"
aria-expanded={open}
aria-label={open ? `Hide ${ariaLabel.toLowerCase()}` : `Show ${ariaLabel.toLowerCase()}`}
onClick={() => toggle()}
className="absolute z-[3] grid place-items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-black/40"
style={{ width: size, height: size, left: pad, top: pad, willChange: "transform" }}
>
<svg viewBox="0 0 24 24" width={size * 0.42} height={size * 0.42} fill="none" stroke={ink} strokeWidth={1.5} strokeLinecap="round" aria-hidden="true" style={{ overflow: "visible" }}>
<line x1="5" y1="12" x2="19" y2="12" />
<line ref={barRef} x1="12" y1="5" x2="12" y2="19" />
</svg>
</button>
</div>
);
}
export default AvatarDock;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
10 propspeople{ name; role?; src; focus? }[]The people: name, role, photo, and where their face sits (object-position).sizenumberButton diameter, px.default 46default 46surfacestringThe pill.default "#dcdcdc"default "#dcdcdc"buttonstringThe round button.default "#8e8e8e"default "#8e8e8e"inkstringThe plus / minus.default "#1a1a1a"default "#1a1a1a"labelSide"left" | "right"Which side the name slides out on.default "right"default "right"defaultOpenbooleanStart open.default falsedefault falseonOpenChange(open) => voidCalled when it opens or closes.onSelect(person, index) => voidCalled when a person is clicked.classNamestringExtra classes.