Components89 / 118
Closet Rack
A shop's clothes hanging side-on on a polished chrome rail, photographed at three angles. Run your cursor along it and the garment you point at winds back, then turns on its hanger to face you while its neighbours slide apart and sway. Click to take it off the rail into a close-up with an editorial title, and step through the collection.
ShopShopProductsProductsHoverHoverSpringsSpringsAnimation principlesAnimation principlesGSAPGSAP
Run along the railClick a garment to take it off
Tweak
LIVELIVELook
Ink
Usage
Follows your tweaks.
usage.tsx
import { ClosetRack } from "@/components/inreact/closet-rack";
const products = [
{ side: "/shop/tee-side.png", mid: "/shop/tee-mid.png", front: "/shop/tee-front.png", title: "Everyday Tee — Black", href: "/p/tee-black" },
{ side: "/shop/crew-side.png", front: "/shop/crew-front.png", title: "Forest Crewneck", href: "/p/crewneck" },
// ...
];
export function Shop() {
return <ClosetRack items={products} height={560} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/closet-rack.jsonOr copy the source
Install the dependencies, then save this as components/inreact/closet-rack.tsx.
terminal
npm install gsapcomponents/inreact/closet-rack.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useCallback, useEffect, useRef, useState } from "react";
/**
* Closet Rack: a shop's clothes hanging on a chrome rail, side-on, like a real closet.
*
* Each garment is photographed at three angles on its hanger (side, turning,
* front) and drawn on a small simulated piece of cloth pinned at the hanger,
* so the photo itself drapes and moves: it sways and lags behind its hanger,
* ripples when a neighbour slides past, flares a little as it turns, stirs
* when your cursor brushes through the rack and in an occasional breeze.
*
* Run your cursor along the rail and the one you point at winds back a touch,
* then turns on its hanger to face you: the three photos are warped to the
* same width at every moment and swapped with an organic dissolve (no
* see-through double image), with the side turning away falling into shade.
* Its neighbours slide apart and settle. Click to take it off the rail: it
* lifts, comes forward and grows while the rack fades back; arrows step
* through the collection. Escape or Close hangs it back. Every garment casts
* a soft shadow of its own silhouette onto the wall and onto the clothes
* behind it. One WebGL pass (three) + GSAP's ticker.
*
* <ClosetRack items={[{ side: "/shop/tee-side.png", mid: "/shop/tee-mid.png",
* front: "/shop/tee-front.png", title: "Everyday Tee, Black", href: "/p/tee" }, ...]} />
*
* Photos: transparent cut-outs of the garment on its hanger, all on the same
* canvas size, hanger hook at the top centre (every angle turns on the hook).
*/
export interface ClosetItem {
/** Side-on view (how it rests on the rail). */
side: string;
/** A partly turned view (optional, smooths the turn). */
mid?: string;
/** Facing you. */
front: string;
title: string;
href?: string;
/** Button label in the close-up. */
cta?: string;
}
export interface ClosetRackProps {
items: ClosetItem[];
height?: number;
background?: string;
/** Text colour. */
ink?: string;
/** Font for the close-up title (an editorial serif works best). */
titleFont?: string;
/** Photo canvas aspect (height / width). */
aspect?: number;
/** Occasional breeze along the rail. */
breeze?: boolean;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
type Spring = { x: number; v: number; t: number };
const step = (b: Spring, k: number, c: number, h: number) => {
for (let i = 0; i < 2; i++) (b.v += (k * (b.t - b.x) - c * b.v) * (h / 2)), (b.x += b.v * (h / 2));
};
const SIDE_SLOT = 0.21; // spacing along the rail, in canvas widths
const FRONT_SLOT = 0.84;
const HOOK_Y = 0.016; // hook top, fraction of canvas height
const HEM_Y = 0.9; // garments end about here
const GX = 13, GY = 17; // cloth grid per garment
const PIN_V = 0.19; // the hanger holds everything above this (hook, shoulders)
const VERT = /* glsl */ `
attribute float shade;
varying vec2 vUv;
varying float vShade;
void main() {
vUv = uv;
vShade = shade;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}`;
// the three photos warped to one width and swapped with an organic dissolve
const FRAG = /* glsl */ `
precision highp float;
uniform sampler2D tS, tM, tF;
uniform float uHasMid, uT, uFade, uSeed, uShadow;
uniform vec3 uW; // side, mid, front widths (fraction of canvas)
varying vec2 vUv;
varying float vShade;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7)) + uSeed) * 43758.5453); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);
}
vec4 view(sampler2D t, float wv, float w) {
float u = 0.5 + (vUv.x - 0.5) * (wv / w);
if (u < 0.0 || u > 1.0) return vec4(0.0);
// the shadow reads a very blurred copy (a far mip level): a soft cast shadow, not a ghost
vec4 c = uShadow > 0.5 ? texture2D(t, vec2(u, vUv.y), 4.5) : texture2D(t, vec2(u, vUv.y));
return vec4(c.rgb * c.a, c.a); // premultiplied
}
void main() {
float t = uT;
// the garment's current width as it turns: front -> partly turned -> side
float w;
if (uHasMid > 0.5) w = t < 0.4 ? mix(uW.z, uW.y, max(t, 0.0) / 0.4) : mix(uW.y, uW.x, clamp((t - 0.4) / 0.6, 0.0, 1.0));
else w = mix(uW.z, uW.x, clamp(t, 0.0, 1.0));
w *= 1.0 + 0.1 * max(-t, 0.0); // overshoot: it swings a little past facing you
float n = noise(vUv * vec2(3.0, 4.5)); // a soft, low-frequency handover (no blocks)
vec4 c;
if (uHasMid > 0.5) {
vec4 cs = view(tS, uW.x, w), cm = view(tM, uW.y, w), cf = view(tF, uW.z, w);
float a = smoothstep(n * 0.3 + 0.05, n * 0.3 + 0.65, (t - 0.4) / 0.6); // mid -> side
float b = smoothstep(n * 0.3 + 0.05, n * 0.3 + 0.65, t / 0.4); // front -> mid
c = t >= 0.4 ? mix(cm, cs, a) : mix(cf, cm, b);
} else {
vec4 cs = view(tS, uW.x, w), cf = view(tF, uW.z, w);
c = mix(cf, cs, smoothstep(n * 0.3 + 0.05, n * 0.3 + 0.65, t));
}
if (uShadow > 0.5) {
// fade out before the quad's edges so a soft shadow never ends in a hard line
float edge = smoothstep(0.0, 0.12, vUv.y) * smoothstep(0.0, 0.06, vUv.x) * smoothstep(1.0, 0.94, vUv.x);
gl_FragColor = vec4(0.0, 0.0, 0.0, c.a * 0.22 * uFade * edge);
return;
}
// the side turning away falls into shade; folds from the cloth darken / catch light
float tt = clamp(t, 0.0, 1.0);
float cyl = 1.0 - 0.2 * sin(tt * 3.14159) * smoothstep(0.35, 0.85, vUv.x);
c.rgb *= cyl * vShade;
gl_FragColor = c * uFade;
}`;
export function ClosetRack({
items,
height = 560,
background = "#ebeae5",
ink = "#36457a",
titleFont = "'Instrument Serif', 'Cormorant Garamond', Georgia, serif",
aspect = 880 / 720,
breeze = true,
className,
}: ClosetRackProps) {
const rootRef = useRef<HTMLDivElement>(null);
const hostRef = useRef<HTMLDivElement>(null);
const labelRef = useRef<HTMLDivElement>(null);
const [W, setW] = useState(0);
const [hover, setHover] = useState(-1);
const [open, setOpen] = useState(-1);
const api = useRef<{ close: () => void; go: (d: number) => void }>({ close: () => {}, go: () => {} });
const n = items.length;
const H = height;
useEffect(() => {
const el = rootRef.current;
if (!el) return;
const ro = new ResizeObserver(([e]) => setW(Math.round(e.contentRect.width)));
ro.observe(el);
return () => ro.disconnect();
}, []);
// layout (px)
const railY = Math.round(H * 0.17);
const span = SIDE_SLOT * (n - 1) + FRONT_SLOT;
const cw = Math.round(Math.max(60, Math.min((H * 0.66) / aspect, ((W || 900) * 0.86) / span)));
const ch = cw * aspect;
const top = railY - ch * HOOK_Y - 4;
const railW = Math.min((W || 900) * 0.94, cw * (span + 0.5));
const big = clamp(1, 1.42, (H * 0.68 - railY) / (ch * HEM_Y));
const fs = Math.round(clamp(10, 15, H * 0.025));
useEffect(() => {
const host = hostRef.current, root = rootRef.current, label = labelRef.current;
if (!host || !root || !label || !W || !n) return;
const still = reduced();
const cx = W / 2;
const hookX = cw / 2, hookY = ch * HOOK_Y; // in canvas px
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;";
host.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, premultipliedAlpha: true });
} catch {
canvas.remove();
return;
}
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));
renderer.setSize(W, H, false);
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(0, W, 0, H, -10, 10); // px, y down
const loader = new THREE.TextureLoader();
const disposables: { dispose: () => void }[] = [];
// measure a view's garment width (below the hook) once its photo is in
const widthOf = (img: HTMLImageElement) => {
const c = document.createElement("canvas");
c.width = 120;
c.height = Math.round(120 * aspect);
const x = c.getContext("2d", { willReadFrequently: true })!;
x.drawImage(img, 0, 0, c.width, c.height);
const d = x.getImageData(0, 0, c.width, c.height).data;
let lo = c.width, hi = 0;
for (let y = Math.round(c.height * 0.25); y < c.height; y++)
for (let xx = 0; xx < c.width; xx++)
if (d[(y * c.width + xx) * 4 + 3] > 128) (lo = Math.min(lo, xx)), (hi = Math.max(hi, xx));
return hi > lo ? (hi - lo + 1) / c.width : 0.5;
};
const tex = (src: string, onImg?: (img: HTMLImageElement) => void) => {
const t = loader.load(src, (tt) => onImg?.(tt.image as HTMLImageElement));
t.colorSpace = THREE.NoColorSpace; // the photo's own sRGB values, shown exactly as shot
t.anisotropy = 4;
disposables.push(t);
return t;
};
type Garm = {
x: Spring; turn: Spring; sw: Spring; sc: Spring; y: Spring; fade: Spring;
geo: THREE.BufferGeometry; mat: THREE.ShaderMaterial; shadowMat: THREE.ShaderMaterial; mesh: THREE.Mesh; shadow: THREE.Mesh;
p: Float32Array; q: Float32Array; rest: Float32Array; pin: Uint8Array; shade: Float32Array;
lvx: number; lsv: number; lturn: number;
};
// cloth constraints (shared by all garments: same grid)
const cons: [number, number, number][] = [];
const node = (i: number, j: number) => j * GX + i;
for (let j = 0; j < GY; j++)
for (let i = 0; i < GX; i++) {
if (i + 1 < GX) cons.push([node(i, j), node(i + 1, j), 1]);
if (j + 1 < GY) cons.push([node(i, j), node(i, j + 1), 1]);
if (i + 1 < GX && j + 1 < GY) cons.push([node(i, j), node(i + 1, j + 1), 0.7], [node(i + 1, j), node(i, j + 1), 0.7]);
if (i + 2 < GX) cons.push([node(i, j), node(i + 2, j), 0.35]);
if (j + 2 < GY) cons.push([node(i, j), node(i, j + 2), 0.35]);
}
const conLen = cons.map(([a, b]) => {
const ua = (a % GX) / (GX - 1), va = Math.floor(a / GX) / (GY - 1), ub = (b % GX) / (GX - 1), vb = Math.floor(b / GX) / (GY - 1);
return Math.hypot((ua - ub) * cw, (va - vb) * ch);
});
const gs: Garm[] = items.map((it, gi) => {
const geo = new THREE.PlaneGeometry(1, 1, GX - 1, GY - 1);
const nv = GX * GY;
const shade = new Float32Array(nv).fill(1);
geo.setAttribute("shade", new THREE.BufferAttribute(shade, 1).setUsage(THREE.DynamicDrawUsage));
(geo.attributes.position as THREE.BufferAttribute).setUsage(THREE.DynamicDrawUsage);
const uW = new THREE.Vector3(0.22, 0.6, 0.78);
const uniforms = {
tS: { value: tex(it.side, (img) => (uW.x = widthOf(img))) },
tM: { value: tex(it.mid ?? it.front, (img) => it.mid && (uW.y = widthOf(img))) },
tF: { value: tex(it.front, (img) => (uW.z = widthOf(img))) },
uHasMid: { value: it.mid ? 1 : 0 },
uT: { value: 1 },
uFade: { value: 1 },
uSeed: { value: gi * 7.31 },
uShadow: { value: 0 },
uW: { value: uW },
};
const mk = (shadow: boolean) =>
new THREE.ShaderMaterial({
vertexShader: VERT,
fragmentShader: FRAG,
uniforms: { ...uniforms, uShadow: { value: shadow ? 1 : 0 } },
transparent: true,
premultipliedAlpha: true,
blending: THREE.CustomBlending,
blendSrc: THREE.OneFactor,
blendDst: THREE.OneMinusSrcAlphaFactor,
depthTest: false,
depthWrite: false,
side: THREE.DoubleSide,
});
const mat = mk(false), shadowMat = mk(true);
const mesh = new THREE.Mesh(geo, mat), shadow = new THREE.Mesh(geo, shadowMat);
mesh.frustumCulled = shadow.frustumCulled = false;
scene.add(shadow, mesh);
disposables.push(geo, mat, shadowMat);
// cloth: rest grid in local px (origin at the hook)
const rest = new Float32Array(nv * 2), pin = new Uint8Array(nv);
for (let j = 0; j < GY; j++)
for (let i = 0; i < GX; i++) {
const k = node(i, j);
rest[k * 2] = (i / (GX - 1)) * cw - hookX;
rest[k * 2 + 1] = (j / (GY - 1)) * ch - hookY;
pin[k] = j / (GY - 1) <= PIN_V ? 1 : 0;
}
return {
x: { x: 0, v: 0, t: 0 }, turn: { x: 1, v: 0, t: 1 }, sw: { x: 0, v: 0, t: 0 }, sc: { x: 1, v: 0, t: 1 }, y: { x: 0, v: 0, t: 0 }, fade: { x: 1, v: 0, t: 1 },
geo, mat, shadowMat, mesh, shadow, p: rest.slice(), q: rest.slice(), rest, pin, shade, lvx: 0, lsv: 0, lturn: 1,
};
});
let hov = -1, sel = -1;
const layout = () => {
const total = cw * (SIDE_SLOT * (n - 1) + (hov >= 0 ? FRONT_SLOT : SIDE_SLOT));
let x = cx - total / 2;
gs.forEach((G, i) => {
const w = cw * (i === hov ? FRONT_SLOT : SIDE_SLOT);
G.x.t = x + w / 2;
x += w;
});
};
const order = () => {
// stable depth: left to right, the hovered / opened one on top
gs.forEach((G, i) => {
const o = i === sel ? 100 : i === hov ? 90 : i * 2;
G.shadow.renderOrder = o;
G.mesh.renderOrder = o + 1;
});
};
const apply = () => {
layout();
order();
gs.forEach((G, i) => {
if (sel >= 0) {
const on = i === sel;
G.turn.t = on ? 0 : 1;
G.sc.t = on ? big : 1;
G.y.t = on ? H * 0.035 : 0;
G.fade.t = on ? 1 : 0.16;
if (on) G.x.t = cx;
} else {
G.turn.t = i === hov ? 0 : 1;
G.sc.t = 1;
G.y.t = 0;
G.fade.t = 1;
}
});
};
apply();
gs.forEach((G) => (G.x.x = G.x.t));
// wind: the cursor brushing through, and the odd breeze
const wind = { x: 0, y: 0, vx: 0, on: false };
let lastPt: { x: number; y: number; t: number } | null = null;
let nextGust = performance.now() + 3500, gustT0 = -1e9;
const GRAV = 900 * (cw / 320);
let labelOn = -1;
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
const now = performance.now();
if (breeze && !still && now > nextGust && sel < 0) {
gustT0 = now;
nextGust = now + 6500 + Math.random() * 3500;
}
gs.forEach((G, gi) => {
const px = G.x.x, psw = G.sw.x;
if (still) {
G.x.x = G.x.t, G.turn.x = G.turn.t, G.sc.x = G.sc.t, G.y.x = G.y.t, G.fade.x = G.fade.t, G.sw.x = 0;
} else {
step(G.x, 120, 16, dt); // slides apart
step(G.turn, 120, 10, dt); // turns, overshoots a little past front, settles
step(G.sc, 150, 14, dt);
step(G.y, 150, 15, dt);
step(G.fade, 110, 21, dt);
const vx0 = (G.x.x - px) / Math.max(dt, 1e-3);
G.sw.v -= clamp(-900, 900, vx0) * 0.004; // the hanger swings on its hook
step(G.sw, 40, 5, dt);
}
// anchor motion felt by the cloth (inertia → follow-through)
const vx = (G.x.x - px) / Math.max(dt, 1e-3);
const ax = (vx - G.lvx) / Math.max(dt, 1e-3);
G.lvx = vx;
const sv = (G.sw.x - psw) / Math.max(dt, 1e-3);
const sa = (sv - G.lsv) / Math.max(dt, 1e-3);
G.lsv = sv;
const tv = (G.turn.x - G.lturn) / Math.max(dt, 1e-3);
G.lturn = G.turn.x;
// --- cloth step (Verlet, local px around the hook) ---
const { p, q, rest, pin } = G;
const h = dt;
const gust = gustT0 > 0 ? Math.max(0, Math.sin(((now - gustT0 - gi * 110) / 900) * Math.PI)) * ((now - gustT0 - gi * 110) < 900 && now - gustT0 - gi * 110 > 0 ? 1 : 0) : 0;
const sc = G.sc.x;
for (let k = 0; k < GX * GY; k++) {
const i2 = k * 2;
if (pin[k] || still) {
p[i2] = q[i2] = rest[i2];
p[i2 + 1] = q[i2 + 1] = rest[i2 + 1];
continue;
}
const vxk = (p[i2] - q[i2]) * 0.955, vyk = (p[i2 + 1] - q[i2 + 1]) * 0.955;
q[i2] = p[i2];
q[i2 + 1] = p[i2 + 1];
const ly = rest[i2 + 1], lx = rest[i2];
let fx = -ax * 0.55; // the rail's motion drags the cloth behind
fx += -sa * (Math.PI / 180) * ly * 0.5; // so does the hanger's swing
fx += tv * lx * 0.9; // turning flares it out a little
// a hand brushing through: push along the cursor's motion
if (wind.on) {
const wx = G.x.x + lx * sc - wind.x, wy = top + hookY + G.y.x + ly * sc - wind.y;
const d2 = wx * wx + wy * wy, R = cw * 0.45;
if (d2 < R * R) fx += wind.vx * (1 - Math.sqrt(d2) / R) * 4;
}
fx += gust * cw * 2.2 * (0.6 + 0.4 * Math.sin(now * 0.004 + ly * 0.02));
p[i2] += vxk + fx * h * h;
p[i2 + 1] += vyk + GRAV * h * h;
}
if (!still)
for (let it = 0; it < 5; it++) {
for (let c = 0; c < cons.length; c++) {
const [a, b, kk] = cons[c];
const ia = a * 2, ib = b * 2;
const dx = p[ib] - p[ia], dy = p[ib + 1] - p[ia + 1];
const len = Math.hypot(dx, dy) || 1e-6;
const wa = pin[a] ? 0 : 1, wb = pin[b] ? 0 : 1;
if (!(wa + wb)) continue;
const corr = ((len - conLen[c]) / len) * kk / (wa + wb);
p[ia] += dx * corr * wa;
p[ia + 1] += dy * corr * wa;
p[ib] -= dx * corr * wb;
p[ib + 1] -= dy * corr * wb;
}
// never longer than it hangs (no sag): distance from its column's top pin
for (let k = 0; k < GX * GY; k++) {
if (pin[k]) continue;
const i = k % GX, j0 = Math.floor((PIN_V * (GY - 1)));
const pk = node(i, j0) * 2, i2 = k * 2;
const dx = p[i2] - p[pk], dy = p[i2 + 1] - p[pk + 1];
const L = rest[i2 + 1] - rest[pk + 1], len = Math.hypot(dx, dy);
if (len > L && len > 0) {
p[i2] = p[pk] + (dx * L) / len;
p[i2 + 1] = p[pk + 1] + (dy * L) / len;
}
}
}
// --- mesh: local cloth → world (scale, swing on the hook, slot) ---
const pos = G.geo.attributes.position as THREE.BufferAttribute;
const arr = pos.array as Float32Array;
const ang = (clamp(-7, 7, G.sw.x) * Math.PI) / 180, ca = Math.cos(ang), sa2 = Math.sin(ang);
const ox = G.x.x, oy = top + hookY + G.y.x;
for (let k = 0; k < GX * GY; k++) {
const lx = p[k * 2] * sc, ly = p[k * 2 + 1] * sc;
arr[k * 3] = ox + lx * ca - ly * sa2;
arr[k * 3 + 1] = oy + lx * sa2 + ly * ca;
arr[k * 3 + 2] = 0;
// folds: where the cloth bunches it darkens a touch, where it stretches it catches light
const i = k % GX;
const dl = i > 0 ? p[k * 2] - p[(k - 1) * 2] : p[(k + 1) * 2] - p[k * 2];
const restDx = cw / (GX - 1);
const dxShift = p[k * 2] - rest[k * 2];
G.shade[k] = clamp(0.86, 1.06, 1 + (dl / restDx - 1) * 0.5 - Math.abs(dxShift) * 0.0012);
}
pos.needsUpdate = true;
(G.geo.attributes.shade as THREE.BufferAttribute).needsUpdate = true;
G.mat.uniforms.uT.value = G.shadowMat.uniforms.uT.value = G.turn.x;
G.mat.uniforms.uFade.value = G.shadowMat.uniforms.uFade.value = clamp(0, 1, G.fade.x);
// the shadow: same silhouette, a little down-right, falling on the wall and the clothes behind
G.shadow.position.set(cw * 0.06 * sc, cw * 0.045 * sc, 0);
});
wind.vx *= Math.pow(0.03, dt);
renderer.render(scene, camera);
const li = sel >= 0 ? -1 : hov;
if (li >= 0) label.style.transform = `translate3d(${gs[li].x.x.toFixed(1)}px,0,0) translateX(-50%)`;
if (li !== labelOn) {
labelOn = li;
label.style.opacity = li >= 0 ? "1" : "0";
}
};
gsap.ticker.add(tick);
// pointer: nearest garment along the rail, with hysteresis
const pick = (clientX: number, clientY: number) => {
const r = root.getBoundingClientRect();
const x = clientX - r.left, y = clientY - r.top;
if (y < railY - 10 || y > top + ch * HEM_Y + 8) return -1;
let bi = -1, bd = Infinity;
gs.forEach((G, i) => {
const d = Math.abs(x - G.x.x) - (i === hov ? cw * 0.2 : 0);
if (d < bd) (bd = d), (bi = i);
});
return bd < cw * 0.45 ? bi : -1;
};
const setHov = (i: number) => {
if (i === hov) return;
if (i >= 0 && !still) gs[i].turn.v += 2.2; // anticipation: winds back before turning to you
hov = i;
setHover(i);
apply();
root.style.cursor = i >= 0 ? "pointer" : "";
};
const openAt = (i: number) => {
sel = i;
hov = -1;
setHover(-1);
setOpen(i);
if (!still) {
gs[i].y.v -= 260;
gs[i].sw.v += 12;
}
apply();
};
const close = () => {
if (sel < 0) return;
const i = sel;
sel = -1;
setOpen(-1);
if (!still) gs[i].sw.v -= 8;
apply();
};
const go = (d: number) => {
if (sel < 0) return;
const prev = sel;
const i = (sel + d + n) % n;
sel = i;
setOpen(i);
if (!still) {
gs[i].x.x = cx + d * cw * 0.7;
gs[i].turn.x = 1;
gs[i].sw.v += d * 14;
gs[prev].sw.v -= d * 10;
}
apply();
};
api.current = { close, go };
const onMove = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
const x = e.clientX - r.left, y = e.clientY - r.top, t = performance.now();
if (lastPt) {
const ddt = Math.max(8, t - lastPt.t) / 1000;
wind.vx = wind.vx * 0.5 + clamp(-1500, 1500, (x - lastPt.x) / ddt) * 0.5;
}
lastPt = { x, y, t };
wind.x = x;
wind.y = y;
wind.on = sel < 0;
if (sel < 0) setHov(pick(e.clientX, e.clientY));
};
const onLeave = () => {
wind.on = false;
lastPt = null;
if (sel < 0) setHov(-1);
};
const onClick = (e: MouseEvent) => {
if (sel >= 0 || (e.target as HTMLElement).closest("button,a")) return;
const i = pick(e.clientX, e.clientY);
if (i >= 0) openAt(i);
};
const onKey = (e: KeyboardEvent) => {
if (sel >= 0) {
if (e.key === "Escape") close();
if (e.key === "ArrowRight") go(1);
if (e.key === "ArrowLeft") go(-1);
return;
}
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
e.preventDefault();
setHov(clamp(0, n - 1, (hov < 0 ? -1 : hov) + (e.key === "ArrowRight" ? 1 : -1)));
}
if (e.key === "Enter" && hov >= 0) openAt(hov);
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("click", onClick);
root.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("click", onClick);
root.removeEventListener("keydown", onKey);
disposables.forEach((d) => d.dispose());
renderer.dispose();
canvas.remove();
};
}, [W, H, n, items, cw, ch, top, railY, big, aspect, breeze]);
const close = useCallback(() => api.current.close(), []);
const sel = open >= 0 ? items[open] : null;
const hemTop = top + ch * 0.93; // below the longest hem
const bigHem = top + H * 0.035 + ch * HEM_Y * big;
return (
<div
ref={rootRef}
tabIndex={0}
role="region"
aria-label="Collection"
className={["relative w-full overflow-hidden outline-none select-none", className].filter(Boolean).join(" ")}
style={{ height: H, background, color: ink, backgroundImage: `radial-gradient(${ink}12 1px, transparent 1.3px)`, backgroundSize: `${Math.round(fs * 2.4)}px ${Math.round(fs * 2.4)}px` }}
>
{/* the rail: polished chrome on wall brackets (the hooks are drawn over it) */}
<div aria-hidden="true" className="absolute transition-opacity duration-500" style={{ left: (W - railW) / 2, width: railW, top: railY - Math.round(fs * 0.27), height: Math.max(5, Math.round(fs * 0.55)), opacity: open >= 0 ? 0.16 : 1 }}>
<div className="absolute inset-0 rounded-full" style={{ background: "linear-gradient(180deg,#ffffff 0%,#d6d8dc 22%,#9b9ea4 48%,#e8e9eb 62%,#b6b9be 82%,#8a8d93 100%)", boxShadow: "0 6px 10px -4px rgba(40,40,50,.28), 0 14px 22px -10px rgba(40,40,50,.18)" }} />
<div className="absolute inset-x-[2%] top-[18%] h-px rounded-full bg-white/90" />
{[0, 1].map((k) => (
<div key={k} className="absolute top-1/2 -translate-y-1/2" style={{ [k ? "right" : "left"]: -Math.round(fs * 0.35), width: Math.round(fs * 0.8), height: Math.round(fs * 1.75) } as React.CSSProperties}>
<div className="absolute inset-0 rounded-[4px]" style={{ background: "linear-gradient(90deg,#8d9096,#f1f2f4 45%,#a3a6ab 75%,#7f8288)", boxShadow: "0 4px 8px -2px rgba(40,40,50,.3)" }} />
</div>
))}
</div>
<div ref={hostRef} aria-hidden="true" className="absolute inset-0" />
{/* the hovered garment's name, under its hem */}
<div ref={labelRef} aria-live="polite" className="pointer-events-none absolute left-0 whitespace-nowrap transition-opacity duration-300" style={{ top: hemTop + fs * 0.7, opacity: 0, zIndex: 25 }}>
<span className="tracking-[0.01em]" style={{ fontSize: fs * 0.78, opacity: 0.62 }}>
{hover >= 0 ? items[hover].title : " "}
</span>
</div>
{/* close-up */}
<div className="pointer-events-none absolute inset-0 transition-opacity duration-500" style={{ opacity: sel ? 1 : 0, zIndex: 40 }}>
{sel && (
<>
<button type="button" onClick={close} className="pointer-events-auto absolute font-medium uppercase transition-opacity hover:opacity-55" style={{ top: railY - fs * 2.6, right: "5%", fontSize: fs * 0.66, letterSpacing: "0.14em" }}>
Close
</button>
{[-1, 1].map((d) => (
<button
key={d}
type="button"
aria-label={d < 0 ? "Previous" : "Next"}
onClick={() => api.current.go(d)}
className="pointer-events-auto absolute grid place-items-center rounded-full transition-[transform,background-color] duration-300 hover:scale-110 hover:bg-white/60 active:scale-95"
style={{ top: top + ch * 0.45 * big, left: `calc(50% ${d < 0 ? "-" : "+"} ${Math.round(cw * 0.62 * big)}px)`, width: fs * 2.1, height: fs * 2.1, marginLeft: -fs * 1.05, marginTop: -fs * 1.05, border: `1px solid ${ink}40` }}
>
<svg viewBox="0 0 24 24" width={fs * 0.95} height={fs * 0.95} fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d={d < 0 ? "M19 12H5M11 6l-6 6 6 6" : "M5 12h14M13 6l6 6-6 6"} />
</svg>
</button>
))}
<div className="absolute inset-x-0 flex flex-col items-center text-center" style={{ top: Math.min(bigHem + fs * 0.9, H - fs * 6.4) }}>
<div className="tabular-nums" style={{ fontSize: fs * 0.62, letterSpacing: "0.12em", opacity: 0.55 }}>
{String(open + 1).padStart(2, "0")} / {String(n).padStart(2, "0")}
</div>
<div key={open} className="leading-none" style={{ fontFamily: titleFont, fontStyle: "italic", fontSize: fs * 2.05, marginTop: fs * 0.45, animation: "closetRise .6s cubic-bezier(.2,.9,.25,1.15) both" }}>
{sel.title}
</div>
<a
href={sel.href ?? "#"}
onClick={(e) => !sel.href && e.preventDefault()}
className="pointer-events-auto rounded-full font-medium uppercase transition-colors duration-300 hover:bg-white/70"
style={{ marginTop: fs * 0.85, fontSize: fs * 0.6, letterSpacing: "0.14em", padding: `${fs * 0.45}px ${fs * 1.2}px`, border: `1px solid ${ink}55` }}
>
{sel.cta ?? "See availability"}
</a>
</div>
</>
)}
</div>
<style>{`@keyframes closetRise{from{opacity:0;transform:translateY(${Math.round(fs * 0.8)}px)}to{opacity:1;transform:none}}`}</style>
</div>
);
}
export default ClosetRack;
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
7 propsitems{ side: string; mid?: string; front: string; title: string; href?: string; cta?: string }[]Per garment: side, partly turned and front cut-outs on the same canvas, hook at the top centre.heightnumberHeight, px.default 560default 560backgroundstringWall colour.default "#ebeae5"default "#ebeae5"inkstringText colour.default "#36457a"default "#36457a"titleFontstringFont for the close-up title.default "Instrument Serif", Georgia, serifdefault "Instrument Serif", Georgia, serifaspectnumberPhoto canvas aspect (height / width).default 880 / 720default 880 / 720classNamestringExtra classes.