
Corporate
Our new studio opens in Lisbon
Category tabs whose pill travels like an inchworm: the leading edge reaches out first, the trailing edge catches up, and it squashes as it lands with a small bounce. Labels flip colour exactly where the pill covers them, and the pill leans toward the tab you point at.
















Tweak
LIVELIVELook
Follows your tweaks.
import { useState } from "react";
import { FilterTabs } from "@/components/inreact/filter-tabs";
export function Journal() {
const [filter, setFilter] = useState("All");
return (
<>
<FilterTabs tabs={["All", "Corporate", "Engineering", "Industry", "Product"]} value={filter} onValueChange={setFilter} />
{/* ...your posts, filtered by `filter` */}
</>
);
}npx shadcn@latest add https://inreact.vercel.app/r/filter-tabs.jsonInstall the dependencies, then save this as components/inreact/filter-tabs.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
/**
* Filter Tabs: a row of category tabs with a pill that travels like an inchworm.
*
* The chosen tab sits in a solid pill. Pick another and the pill's leading
* edge reaches out first while its trailing edge catches up a beat later, so
* it stretches across, then squashes as it lands and settles with a small
* bounce. The label flips colour exactly where the pill covers it (letters
* turn over mid-slide as it passes). Point at a tab and the pill leans toward
* it in anticipation; press and it squashes like jelly. A proper tab list:
* arrows, Home and End move the choice.
*
* <FilterTabs tabs={["All", "Corporate", "Engineering", "Industry", "Product"]} onValueChange={setFilter} />
*/
export interface FilterTabsProps {
tabs: string[];
value?: string;
defaultValue?: string;
onValueChange?: (v: string) => void;
/** Text size, px (everything scales from it). */
size?: number;
/** Pill colour. */
pill?: string;
/** Text on the pill. */
ink?: string;
/** Text off the pill. */
muted?: string;
className?: string;
"aria-label"?: 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));
};
export function FilterTabs({
tabs,
value,
defaultValue,
onValueChange,
size = 14,
pill = "#ececec",
ink = "#111111",
muted = "rgba(255,255,255,.78)",
className,
"aria-label": ariaLabel = "Filter",
}: FilterTabsProps) {
const rootRef = useRef<HTMLDivElement>(null);
const pillRef = useRef<HTMLSpanElement>(null);
const overRef = useRef<HTMLDivElement>(null);
const btnRefs = useRef<(HTMLButtonElement | null)[]>([]);
const [inner, setInner] = useState(defaultValue ?? tabs[0]);
const cur = value ?? inner;
const idx = Math.max(0, tabs.indexOf(cur));
const api = useRef<{ to: (i: number, lean?: boolean) => void; press: () => void }>({ to: () => {}, press: () => {} });
const choose = useCallback(
(i: number) => {
const v = tabs[i];
if (v === undefined) return;
if (value === undefined) setInner(v);
onValueChange?.(v);
},
[tabs, value, onValueChange],
);
// the pill: two edges on their own springs (the leading one quicker), plus a squash spring
useLayoutEffect(() => {
const root = rootRef.current, p = pillRef.current, over = overRef.current;
if (!root || !p || !over) return;
const still = reduced();
const L: Spring = { x: 0, v: 0, t: 0 }, R: Spring = { x: 0, v: 0, t: 0 }, sq: Spring = { x: 0, v: 0, t: 0 };
let dir = 0, sel = idx, lean = 0, last = "";
const rect = (i: number) => {
const b = btnRefs.current[i];
return b ? { l: b.offsetLeft, r: b.offsetLeft + b.offsetWidth } : { l: 0, r: 0 };
};
const place = (i: number, jump: boolean) => {
const r = rect(i);
dir = Math.sign(r.l - L.t);
L.t = r.l;
R.t = r.r;
if (jump || still) (L.x = L.t), (R.x = R.t);
};
place(idx, true);
const to = (i: number, leanOnly = false) => {
if (leanOnly) {
// anticipation: lean a few px toward the tab you're pointing at
lean = i < 0 || i === sel ? 0 : Math.sign(i - sel) * size * 0.35;
return;
}
sel = i;
lean = 0;
place(i, false);
if (!still) sq.v -= 2.2;
};
api.current.to = to;
api.current.press = () => {
if (!still) sq.v += 4.5;
};
const h = Math.round(size * 1.7);
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
const tl = L.t + (lean < 0 ? lean : 0), tr = R.t + (lean > 0 ? lean : 0);
if (still) (L.x = tl), (R.x = tr), (sq.x = 0);
else {
// the leading edge reaches first, the trailing edge follows (inchworm)
const lead = 240, trail = 120;
const lt = { ...L, t: tl }, rt = { ...R, t: tr };
step(lt, dir < 0 ? lead : trail, dir < 0 ? 24 : 15, dt);
step(rt, dir > 0 ? lead : trail, dir > 0 ? 24 : 15, dt);
(L.x = lt.x), (L.v = lt.v), (R.x = rt.x), (R.v = rt.v);
step(sq, 300, 12, dt); // squash on landing, jelly on press
}
const w = Math.max(h, R.x - L.x);
const base = Math.max(h, R.t - L.t);
const stretch = clamp(1, 2.2, w / base);
// keep its volume: a stretched pill gets a touch thinner, a squash a touch fatter
const sy = clamp(0.72, 1.15, 1 / Math.pow(stretch, 0.32) + sq.x * 0.06);
const ph = h * sy;
const key = `${L.x.toFixed(2)}|${w.toFixed(2)}|${ph.toFixed(2)}`;
if (key === last) return;
last = key;
p.style.transform = `translate3d(${L.x.toFixed(2)}px,-50%,0)`;
p.style.width = `${w.toFixed(2)}px`;
p.style.height = `${ph.toFixed(2)}px`;
// the inverted labels show only where the pill is
const W = root.clientWidth, top = (root.clientHeight - ph) / 2;
over.style.clipPath = `inset(${top.toFixed(2)}px ${(W - L.x - w).toFixed(2)}px ${top.toFixed(2)}px ${L.x.toFixed(2)}px round ${(ph / 2).toFixed(2)}px)`;
};
gsap.ticker.add(tick);
const ro = new ResizeObserver(() => place(sel, true));
ro.observe(root);
return () => {
gsap.ticker.remove(tick);
ro.disconnect();
};
}, [size, tabs.join("|")]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
api.current.to(idx);
}, [idx]);
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
const k = e.key;
let n = -1;
if (k === "ArrowRight") n = (idx + 1) % tabs.length;
if (k === "ArrowLeft") n = (idx - 1 + tabs.length) % tabs.length;
if (k === "Home") n = 0;
if (k === "End") n = tabs.length - 1;
if (n < 0) return;
e.preventDefault();
choose(n);
btnRefs.current[n]?.focus();
};
const padX = size * 0.86, gap = size * 0.28;
const row = (inverted: boolean) =>
tabs.map((t) => (
<span key={t} className="relative z-10 block whitespace-nowrap" style={{ padding: `0 ${padX}px`, lineHeight: `${size * 2.4}px`, color: inverted ? ink : undefined }}>
{t}
</span>
));
return (
<div
ref={rootRef}
role="tablist"
aria-label={ariaLabel}
onKeyDown={onKey}
onPointerLeave={() => api.current.to(-1, true)}
className={["relative inline-flex select-none items-center font-medium", className].filter(Boolean).join(" ")}
style={{ fontSize: size, gap, color: muted }}
>
<span ref={pillRef} aria-hidden="true" className="pointer-events-none absolute top-1/2 left-0 rounded-full will-change-transform" style={{ background: pill }} />
{tabs.map((t, i) => (
<button
key={t}
ref={(el) => void (btnRefs.current[i] = el)}
type="button"
role="tab"
aria-selected={i === idx}
tabIndex={i === idx ? 0 : -1}
onClick={() => {
choose(i);
api.current.press();
}}
onPointerEnter={() => api.current.to(i, true)}
className="relative z-0 cursor-pointer rounded-full border-0 bg-transparent p-0 outline-none transition-colors duration-200 hover:text-white focus-visible:ring-2 focus-visible:ring-white/40"
style={{ color: "inherit", font: "inherit" }}
>
<span className="block whitespace-nowrap" style={{ padding: `0 ${padX}px`, lineHeight: `${size * 2.4}px` }}>
{t}
</span>
</button>
))}
{/* the same labels in the pill's ink, revealed only inside the pill */}
<div ref={overRef} aria-hidden="true" className="pointer-events-none absolute inset-0 flex items-center" style={{ gap }}>
{row(true)}
</div>
</div>
);
}
export default FilterTabs;
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
tabsstring[]valuestringdefaultValuestringonValueChange(value) => voidsizenumberpillstringinkstringmutedstringclassNamestring