Components69 / 118
Reveal Tabs
Quiet icon chips that open up to say what they are. Point at one and its label resolves letter by letter out of a blur while the last folds away, on springs that overshoot and squash. Each icon acts out its meaning: the office lights its windows, the cap is tossed and lands, the sun flares, the cloud lets a little rain go.
TabsTabsIconsIconsSpringsSpringsSquash & stretchSquash & stretchKeyboardKeyboardGSAPGSAP
Point at a chipOr use the arrow keys
Tweak
LIVELIVELook
48px
Page
Behaviour
Opens on
Usage
Follows your tweaks.
usage.tsx
import { RevealTabs } from "@/components/inreact/reveal-tabs";
const places = [
{ label: "Office", icon: "office" },
{ label: "School", icon: "school" },
{ label: "Garden", icon: "garden" },
{ label: "Cloud", icon: "cloud" },
] as const;
export function Places() {
return <RevealTabs items={[...places]} onChange={(i) => setPlace(i)} size={48} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/reveal-tabs.jsonOr copy the source
Install the dependencies, then save this as components/inreact/reveal-tabs.tsx.
terminal
npm install gsapcomponents/inreact/reveal-tabs.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
/**
* Reveal Tabs: icon chips that open up to say what they are.
*
* A row of quiet icon chips. Point at one (or click, or use the arrow keys)
* and it opens up to show its label, letter by letter out of a blur, while the
* last one folds back to just its icon. Widths ride springs, so a chip
* overshoots as it opens and squashes as it grows; the row flows around it.
* And each built-in icon acts out what it means: the office lights its
* windows, the cap gets tossed and lands, the sun flares and turns, the cloud
* bobs and lets a little rain go. Custom icons get a squash-and-stretch hop.
*
* <RevealTabs items={[{ label: "Office", icon: "office" }, { label: "Cloud", icon: "cloud" }]} />
*/
export type RevealIcon = "office" | "school" | "garden" | "cloud";
export interface RevealTabsItem {
label: string;
/** A built-in icon (it acts when chosen) or your own node. */
icon: RevealIcon | ReactNode;
}
export interface RevealTabsProps {
items: RevealTabsItem[];
/** Starting tab. */
defaultIndex?: number;
onChange?: (index: number) => void;
/** Open on hover (the default) or only on click. */
trigger?: "hover" | "click";
/** Chip height, px. */
size?: number;
tone?: "light" | "dark";
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
/* ---------------- icons (24 box, drawn to act) ---------------- */
const S = { fill: "none", stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" } as const;
function Glyph({ icon }: { icon: RevealIcon }) {
if (icon === "office")
return (
<g data-part="body">
<rect x="5.5" y="3" width="13" height="18" rx="1.6" {...S} />
{[7, 10.5, 14].map((y) =>
[8.7, 13.3].map((x) => <rect key={`${x}${y}`} data-part="win" x={x} y={y} width="2" height="2" rx=".4" fill="currentColor" opacity=".35" />),
)}
<path d="M10.5 21v-3h3v3" {...S} />
</g>
);
if (icon === "school")
return (
<>
<path d="M6.5 11.2v3.6c0 1.5 2.5 2.8 5.5 2.8s5.5-1.3 5.5-2.8v-3.6" {...S} />
<g data-part="cap">
<path d="M12 4.5 21.5 9 12 13.5 2.5 9Z" {...S} />
<path data-part="tassel" d="M21.5 9v4.6" {...S} />
</g>
</>
);
if (icon === "garden")
return (
<>
<circle data-part="core" cx="12" cy="12" r="3.6" {...S} />
<g data-part="rays">
{Array.from({ length: 8 }, (_, i) => {
const a = (i * Math.PI) / 4, c = Math.cos(a), s = Math.sin(a);
return <path key={i} d={`M${(12 + c * 6.2).toFixed(2)} ${(12 + s * 6.2).toFixed(2)}L${(12 + c * 8.4).toFixed(2)} ${(12 + s * 8.4).toFixed(2)}`} {...S} />;
})}
</g>
</>
);
return (
<>
{[9, 12.5, 16].map((x, i) => (
<path key={i} data-part="drop" d={`M${x} 18.6v1.6`} {...S} opacity="0" />
))}
<path data-part="cloud" d="M7.2 17.2h10a3.9 3.9 0 0 0 .5-7.77A5.4 5.4 0 0 0 7.3 9.1a4.05 4.05 0 0 0-.1 8.1Z" {...S} />
</>
);
}
// Each moving part gets a proxy {x, y, r, sx, sy} that GSAP tweens; we write
// the SVG transform ourselves about a fixed origin, so every act lands back
// exactly at rest (no origin drift between chained tweens).
type Pose = { x: number; y: number; r: number; sx: number; sy: number; ox: number; oy: number; el: SVGElement };
const poses = new WeakMap<SVGElement, Pose>();
const pose = (el: SVGElement, ox: number, oy: number) => {
let p = poses.get(el);
if (!p) {
p = { x: 0, y: 0, r: 0, sx: 1, sy: 1, ox, oy, el };
poses.set(el, p);
}
p.ox = ox;
p.oy = oy;
return p;
};
const draw = function (this: gsap.core.Tween) {
for (const p of this.targets() as Pose[]) {
p.el.setAttribute(
"transform",
`translate(${(p.x + p.ox).toFixed(3)} ${(p.y + p.oy).toFixed(3)}) rotate(${p.r.toFixed(2)}) scale(${p.sx.toFixed(4)} ${p.sy.toFixed(4)}) translate(${-p.ox} ${-p.oy})`,
);
}
};
const REST = { x: 0, y: 0, r: 0, sx: 1, sy: 1 };
// each icon's little act, played when its tab is chosen
function act(svg: SVGSVGElement, icon: RevealIcon | null) {
const q = (p: string) => Array.from(svg.querySelectorAll<SVGElement>(`[data-part="${p}"]`));
const P = (part: string, ox: number, oy: number) => q(part).map((el) => pose(el, ox, oy));
const tl = gsap.timeline({ defaults: { onUpdate: draw } });
if (icon === "office") {
// the building stretches up as the lights come on, floor by floor
const body = P("body", 12, 21);
gsap.killTweensOf(body);
tl.fromTo(body, { ...REST, sy: 0.84, sx: 1.1 }, { ...REST, duration: 0.7, ease: "elastic.out(1.1, 0.4)" }, 0)
.fromTo(q("win").reverse(), { opacity: 0.35 }, { opacity: 1, duration: 0.12, stagger: 0.05, ease: "power1.out", onUpdate: undefined }, 0.06)
.to(q("win"), { opacity: 0.35, duration: 0.5, stagger: 0.03, ease: "power2.inOut", onUpdate: undefined }, 0.75);
} else if (icon === "school") {
// the cap is tossed: crouch, fly with a spin, land with a squash
const cap = P("cap", 12, 13.5);
const tassel = P("tassel", 21.5, 9);
gsap.killTweensOf([...cap, ...tassel]);
tl.set(cap, { ...REST })
.to(cap, { sy: 0.78, sx: 1.12, y: 0.8, duration: 0.09, ease: "power2.in" })
.to(cap, { y: -6.5, r: -24, sy: 1.12, sx: 0.92, duration: 0.26, ease: "power2.out" })
.to(cap, { y: 0, r: 0, sy: 1, sx: 1, duration: 0.24, ease: "power2.in" })
.to(cap, { sy: 0.8, sx: 1.14, duration: 0.07, ease: "power1.out" })
.to(cap, { ...REST, duration: 0.5, ease: "elastic.out(1, 0.35)" })
.fromTo(tassel, { ...REST }, { keyframes: { r: [24, -16, 9, -4, 0] }, duration: 0.8, ease: "none" }, 0.32);
} else if (icon === "garden") {
// the sun flares out and turns, its core pops
const rays = P("rays", 12, 12), core = P("core", 12, 12);
gsap.killTweensOf([...rays, ...core]);
tl.fromTo(rays, { ...REST, sx: 0.7, sy: 0.7 }, { ...REST, r: 90, duration: 0.85, ease: "elastic.out(1.05, 0.45)" }, 0)
.fromTo(core, { ...REST, sx: 0.7, sy: 0.7 }, { ...REST, duration: 0.6, ease: "elastic.out(1.2, 0.4)" }, 0.04)
.set(rays, { r: 0 }); // 90° looks the same as 0°; reset so the next act starts clean
} else if (icon === "cloud") {
// the cloud bobs, squashes as it settles and lets a little rain go
const cloud = P("cloud", 12, 17), drops = P("drop", 12, 19);
gsap.killTweensOf([...cloud, ...drops]);
tl.set(cloud, { ...REST })
.to(cloud, { y: -2.4, sx: 0.92, sy: 1.1, duration: 0.18, ease: "power2.out" })
.to(cloud, { y: 0, sx: 1.1, sy: 0.88, duration: 0.16, ease: "power2.in" })
.to(cloud, { ...REST, duration: 0.55, ease: "elastic.out(1, 0.38)" })
.fromTo(drops, { ...REST, y: -2 }, { y: 4, duration: 0.22, stagger: 0.08, ease: "power1.in" }, 0.3)
.fromTo(q("drop"), { opacity: 0 }, { opacity: 1, duration: 0.1, stagger: 0.08, onUpdate: undefined }, 0.3)
.to(q("drop"), { opacity: 0, duration: 0.18, stagger: 0.08, onUpdate: undefined }, 0.48)
.set(drops, { ...REST }, ">");
} else {
// anything else: a squash-and-stretch hop (the whole icon, CSS transform)
tl.to(svg, { scaleY: 0.8, scaleX: 1.12, y: 1, duration: 0.09, ease: "power2.in", onUpdate: undefined })
.to(svg, { scaleY: 1.14, scaleX: 0.9, y: -3, duration: 0.18, ease: "power2.out", onUpdate: undefined })
.to(svg, { scaleY: 1, scaleX: 1, y: 0, duration: 0.6, ease: "elastic.out(1, 0.4)", onUpdate: undefined });
}
return tl;
}
/* ---------------- the tabs ---------------- */
export function RevealTabs({ items, defaultIndex = 0, onChange, trigger = "hover", size = 44, tone = "light", className }: RevealTabsProps) {
const n = items.length;
const [active, setActive] = useState(() => Math.max(0, Math.min(n - 1, defaultIndex)));
const chips = useRef<(HTMLButtonElement | null)[]>([]);
const bodies = useRef<(HTMLSpanElement | null)[]>([]);
const wraps = useRef<(HTMLSpanElement | null)[]>([]);
const labels = useRef<(HTMLSpanElement | null)[]>([]);
const icons = useRef<(SVGSVGElement | null)[]>([]);
const target = useRef(active);
const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
const first = useRef(true);
const H = size;
const padX = Math.round(H * 0.3);
const iconS = Math.round(H * 0.44);
const gapIn = Math.round(H * 0.17);
// springs for each chip's opening, and the layout loop
useEffect(() => {
const still = reduced();
const sp = items.map((_, k) => ({ a: k === target.current ? 1 : 0, v: 0 }));
let widths = labels.current.map((el) => (el ? el.offsetWidth : 40));
const measure = () => {
widths = labels.current.map((el) => (el ? el.offsetWidth : 40));
};
document.fonts?.ready.then(measure).catch(() => {});
const last = items.map(() => "");
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30) / 2;
for (let k = 0; k < n; k++) {
const s = sp[k];
const goal = k === target.current ? 1 : 0;
if (still) {
s.a = goal;
s.v = 0;
} else {
// opening overshoots a little; closing is firmer
const kk = goal ? 230 : 300, c = 2 * (goal ? 0.5 : 0.72) * Math.sqrt(kk);
for (let i = 0; i < 2; i++) {
s.v += (kk * (goal - s.a) - c * s.v) * dt;
s.a += s.v * dt;
}
}
const w = Math.max(0, widths[k] * s.a); // the label's width includes its gap
// squash as it grows, stretch as it folds (volume-preserving)
const sq = still ? 0 : Math.max(-0.07, Math.min(0.07, s.v * 0.018));
const css = `${w.toFixed(2)}|${sq.toFixed(4)}`;
if (css !== last[k]) {
const wrap = wraps.current[k], body = bodies.current[k];
if (wrap) wrap.style.width = `${w.toFixed(2)}px`;
if (body) body.style.transform = `scale(${(1 + sq * 0.5).toFixed(4)},${(1 - sq).toFixed(4)})`;
last[k] = css;
}
}
};
gsap.ticker.add(tick);
return () => gsap.ticker.remove(tick);
}, [items, n]);
// the letters resolve in; the icon acts
useEffect(() => {
target.current = active;
if (first.current) {
first.current = false;
labels.current.forEach((el, k) => gsap.set(el?.children ?? [], { opacity: k === active ? 1 : 0, filter: "blur(0px)" }));
return;
}
const still = reduced();
labels.current.forEach((el, k) => {
if (!el) return;
const letters = Array.from(el.children);
gsap.killTweensOf(letters);
if (k === active) {
if (still) gsap.set(letters, { opacity: 1, y: 0, filter: "blur(0px)" });
else gsap.fromTo(letters, { opacity: 0, y: 3, filter: "blur(4px)" }, { opacity: 1, y: 0, filter: "blur(0px)", duration: 0.42, stagger: 0.03, ease: "power3.out", delay: 0.05 });
} else if (still) gsap.set(letters, { opacity: 0 });
else gsap.to(letters, { opacity: 0, filter: "blur(3px)", duration: 0.16, stagger: { each: 0.012, from: "end" }, ease: "power2.in" });
});
const svg = icons.current[active];
const it = items[active];
if (svg && !still) act(svg, typeof it.icon === "string" ? (it.icon as RevealIcon) : null);
}, [active, items]);
const choose = (k: number) => {
if (k === target.current) return;
target.current = k;
setActive(k);
onChangeRef.current?.(k);
};
const onKey = (e: KeyboardEvent) => {
const d = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
if (!d) return;
e.preventDefault();
const k = (active + d + n) % n;
choose(k);
chips.current[k]?.focus();
};
const light = tone === "light";
return (
<div role="tablist" onKeyDown={onKey} className={["inline-flex items-center", className].filter(Boolean).join(" ")} style={{ gap: Math.round(H * 0.18) }}>
{items.map((it, k) => (
<button
key={k}
ref={(el) => void (chips.current[k] = el)}
type="button"
role="tab"
aria-selected={k === active}
aria-label={it.label}
tabIndex={k === active ? 0 : -1}
onPointerEnter={(e) => trigger === "hover" && e.pointerType === "mouse" && choose(k)}
onClick={() => choose(k)}
className="group/tab relative shrink-0 cursor-pointer outline-none [-webkit-tap-highlight-color:transparent]"
style={{ height: H }}
>
<span
ref={(el) => void (bodies.current[k] = el)}
className={[
"flex h-full items-center transition-colors duration-200 will-change-transform group-focus-visible/tab:ring-2",
light ? "bg-[#f1f1f3] text-[#2a2a30] group-hover/tab:bg-[#eaeaee] ring-black/20" : "bg-[#1a1a1e] text-[#e9e9ee] group-hover/tab:bg-[#222227] ring-white/25",
].join(" ")}
style={{ padding: `0 ${padX}px`, borderRadius: Math.round(H * 0.3), boxShadow: light ? "inset 0 1px 0 rgba(255,255,255,.75)" : "inset 0 1px 0 rgba(255,255,255,.05)" }}
>
<svg ref={(el) => void (icons.current[k] = el)} viewBox="0 0 24 24" aria-hidden="true" className="shrink-0 overflow-visible" style={{ width: iconS, height: iconS }}>
{typeof it.icon === "string" ? <Glyph icon={it.icon as RevealIcon} /> : <foreignObject width="24" height="24">{it.icon}</foreignObject>}
</svg>
<span ref={(el) => void (wraps.current[k] = el)} className="block overflow-hidden" style={{ width: k === active ? undefined : 0 }}>
<span
ref={(el) => void (labels.current[k] = el)}
className="inline-block whitespace-nowrap font-medium"
style={{ paddingLeft: gapIn, fontSize: Math.round(H * 0.34), letterSpacing: "-0.005em" }}
>
{Array.from(it.label).map((ch, i) => (
<span key={i} className="inline-block" style={{ whiteSpace: "pre" }}>
{ch}
</span>
))}
</span>
</span>
</span>
</button>
))}
</div>
);
}
export default RevealTabs;
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{ label: string; icon: "office" | "school" | "garden" | "cloud" | ReactNode }[]The tabs (keep the array stable).defaultIndexnumberStarting tab.default 0default 0onChange(index: number) => voidCalled when the tab changes.trigger"hover" | "click"Open on hover, or only on click.default "hover"default "hover"sizenumberChip height, px.default 44default 44tone"light" | "dark"Colours for the page.default "light"default "light"classNamestringExtra classes.