Liquid Segmented
A segmented control in Apple-style liquid glass. The track is clear, light glass with a hairline rim that glints where it faces the light, the glints sliding as your cursor moves. The chosen option sits under a lens: frosted at rest, it lifts off the track the moment you touch it, swelling past the edges with an elastic give, turning clear and magnifying the labels beneath it, squeezing and bending them at its curved rim with a slight colour fringe. Tap another option and it lifts, glides across with a soft bounce and sinks back as it lands; drag it and it follows your finger. A proper radio group, driven by arrows, Home and End.
Tweak
LIVELIVEOptions
Glass
Light
Usage
Follows your tweaks.
import { useState } from "react";
import { LiquidSegmented } from "@/components/inreact/liquid-segmented";
export function MailHeader() {
const [view, setView] = useState("inbox");
return (
<LiquidSegmented
aria-label="Mailbox"
options={[{ value: "inbox", label: "Inbox" }, { value: "draft", label: "Draft" }]}
value={view}
onValueChange={setView}
/>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/liquid-segmented.jsonOr copy the source
Install the dependencies, then save this as components/inreact/liquid-segmented.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { useCallback, useEffect, useRef, useState, type KeyboardEvent, type PointerEvent as RPointerEvent } from "react";
/**
* Liquid Segmented: a segmented control cut from thick, polished glass.
*
* A pill of real glass, rendered on the GPU, with a broad rounded bevel that
* reflects a studio of soft lights: crisp, fresnel-bright rims, deep inner
* reflections like a slab of crystal, and a highlight that slides toward your
* cursor as you move. The chosen option sits under a thumb, a lens of frosted
* glass set into the pill. The labels are drawn inside the glass, so the thumb
* truly optically covers them: a label turns bright exactly where the thumb's
* glass passes over it, and is magnified and bent at its curved edge.
*
* It moves like a rigid piece of glass: the thumb glides on a firm, damped
* spring (no stretch, no wobble). Press it, or grab and drag it, and it lifts a
* little, magnifying the label beneath it as it follows your finger, then
* settles into the nearest option.
*
* <LiquidSegmented
* options={[{ value: "inbox", label: "Inbox" }, { value: "draft", label: "Draft" }]}
* value={tab}
* onValueChange={setTab}
* />
*
* A radio group: arrows, Home and End change the choice; the real labels stay
* in the document for screen readers. Over a light page the body frosts what is
* behind it. Reduced motion: no springs. WebGL2; without it, a static frosted
* control with plain labels.
*/
export interface LiquidSegmentedOption {
value: string;
label: string;
}
export interface LiquidSegmentedProps {
options?: LiquidSegmentedOption[];
/** Controlled value. */
value?: string;
/** Initial value when uncontrolled. */
defaultValue?: string;
/** Called with the chosen value. */
onValueChange?: (value: string) => void;
/** Height of the control in px. */
size?: number;
/** Colour of the glass (its body and inner light). */
tint?: string;
/** Colour of the thumb's frosted glass. */
thumb?: string;
/** Colour of the chosen label (under the thumb). */
activeColor?: string;
/** Colour of the other labels. */
labelColor?: string;
/** Strength of the studio reflections. */
shine?: number;
/** How strongly the thumb magnifies the label under it. */
magnify?: number;
className?: string;
"aria-label"?: string;
}
const DEFAULT_OPTIONS: LiquidSegmentedOption[] = [
{ value: "inbox", label: "Inbox" },
{ value: "draft", label: "Draft" },
];
const M = 32; // room around the pill for the lifted lens and its edge, css px
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function hex(c: string): [number, number, number] {
let h = c.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (x) => x + x);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
const VERT = `#version 300 es
in vec2 aQ;
void main() { gl_Position = vec4(aQ, 0.0, 1.0); }`;
const FRAG = `#version 300 es
precision highp float;
uniform vec2 uRes, uOrigin, uSize; // canvas px; the control's box (css px, canvas space)
uniform float uDpr, uLight, uLift, uShine, uMag, uHover;
uniform vec4 uPill, uThumb; // centre x, y, half width, half height
uniform vec3 uTint, uThumbTint, uActive, uIdle;
uniform sampler2D uText; // the labels, drawn white into alpha
out vec4 o;
float sdCaps(vec2 p, vec4 c) {
vec2 q = abs(p - c.xy);
float r = c.w;
return length(vec2(max(q.x - (c.z - r), 0.0), q.y)) - r;
}
// outward direction of a capsule's edge at p
vec2 capsN(vec2 p, vec4 c) {
vec2 q = p - c.xy;
float hx = c.z - c.w;
vec2 k = vec2(q.x - clamp(q.x, -hx, hx), q.y);
float l = length(k);
return l > 1e-4 ? k / l : vec2(0.0, -1.0);
}
float label(vec2 p) {
vec2 uv = (p - uOrigin) / uSize;
if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) return 0.0;
return texture(uText, uv).a;
}
// Apple's glass edge: a hairline of light, brightest where the edge faces the light (top-left)
// and, more softly, on the opposite side where light bounces back out (bottom-right)
float rimLight(vec2 n, float d) {
vec2 Ld = vec2(cos(uLight), sin(uLight));
float face = pow(max(dot(n, Ld), 0.0), 1.5) + 0.5 * pow(max(dot(n, -Ld), 0.0), 2.0) + 0.1;
return exp(-pow((d + 0.55) / 0.42, 2.0)) * face;
}
void main() {
vec2 frag = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y) / uDpr;
float aa = 0.8 / uDpr;
float d = sdCaps(frag, uPill);
float dT = sdCaps(frag, uThumb);
float coverP = 1.0 - smoothstep(-aa, aa, d);
float inT = 1.0 - smoothstep(-aa, aa, dT);
float cover = max(coverP, inT); // a lifted lens may rise past the track's edge
if (cover < 0.002) { o = vec4(0.0); return; }
float yrel = clamp((frag.y - uPill.y) / uPill.w, -1.0, 1.0);
// the track: clear, light glass; a soft sheen just inside the upper edge
vec3 col = uTint * (0.085 - 0.025 * yrel) * coverP;
col += uTint * 0.05 * exp(-pow((d + 3.2) / 2.4, 2.0)) * smoothstep(0.3, -1.0, yrel) * coverP;
// the labels outside the lens
float L0 = label(frag) * (1.0 - inT);
col = mix(col, uIdle * (0.92 + 0.08 * uHover), L0 * coverP);
// a lifted lens casts a faint shadow onto the track around it
col *= 1.0 - 0.45 * uLift * exp(-max(dT, 0.0) / 7.0) * (1.0 - inT) * coverP;
col += rimLight(capsN(frag, uPill), d) * 0.85 * uShine * coverP * (1.0 - inT);
// the lens: frosted at rest; lifted, it clears and magnifies, the content squeezed and bent at its curved rim
if (inT > 0.001) {
vec2 nT = capsN(frag, uThumb);
float tEdge = clamp(-dT / (uThumb.w * 0.6), 0.0, 1.0);
float mag = 1.0 + uMag * (0.06 + 0.26 * uLift);
float bend = pow(1.0 - tEdge, 2.2) * uThumb.w * (0.22 + 0.4 * uLift);
vec2 q = uThumb.xy + (frag - uThumb.xy) / mag + nT * bend;
float fr = bend * 0.025 * (0.3 + uLift); // each colour bends a touch differently at the rim
vec3 Lc = vec3(label(q + nT * fr), label(q), label(q - nT * fr));
float clear = smoothstep(0.0, 1.0, uLift);
// seen through the clear lens: the glass track beneath, refracted along with the labels
float qy = clamp((q.y - uPill.y) / uPill.w, -1.0, 1.0);
float under = 1.0 - smoothstep(-1.0, 1.0, sdCaps(q, uPill));
vec3 through = uTint * (0.085 - 0.025 * qy) * under + uTint * 0.03;
vec3 frost = mix(uThumbTint * 0.15 + 0.03, through, clear);
vec3 tcol = frost + Lc * uActive * (1.0 - frost);
// inner sheen along the lens's top, deeper when lifted
float ty = clamp((frag.y - uThumb.y) / uThumb.w, -1.0, 1.0);
tcol += 0.07 * (1.0 + clear) * exp(-pow((dT + 2.6) / 2.2, 2.0)) * smoothstep(0.3, -1.0, ty);
tcol += 0.05 * clear * exp(-pow((dT + 2.6) / 2.6, 2.0)) * smoothstep(0.3, 1.0, ty);
tcol += rimLight(nT, dT) * (0.7 + 0.45 * clear) * uShine;
col = mix(col, tcol, inT);
}
// over a light page the track is see-through (the browser frosts what is behind)
float a = cover * clamp(0.9 + 0.1 * max(max(col.r, col.g), col.b), 0.0, 1.0);
o = vec4(col, a);
}`;
export function LiquidSegmented({
options = DEFAULT_OPTIONS,
value,
defaultValue,
onValueChange,
size = 64,
tint = "#ffffff",
thumb = "#ffffff",
activeColor = "#ffffff",
labelColor = "#8e8e93",
shine = 1,
magnify = 1,
className,
"aria-label": ariaLabel = "Choose a view",
}: LiquidSegmentedProps) {
const rootRef = useRef<HTMLDivElement>(null);
const segRefs = useRef<(HTMLButtonElement | null)[]>([]);
const [inner, setInner] = useState(defaultValue ?? options[0]?.value);
const current = value !== undefined ? value : inner;
const idx = Math.max(0, options.findIndex((o) => o.value === current));
const [gpu, setGpu] = useState(true);
const pad = Math.round(size * 0.1);
const fs = Math.round(size * 0.31);
const props = useRef({ tint, thumb, activeColor, labelColor, shine, magnify });
props.current = { tint, thumb, activeColor, labelColor, shine, magnify };
const labelsKey = options.map((o) => o.label).join("|");
const sim = useRef({
wake: () => {},
redrawText: () => {},
target: 0,
drag: null as null | { x: number },
held: false,
hover: -1,
setLift: (_t: number) => {},
travel: () => {},
});
const centerOf = useCallback((i: number) => {
const b = segRefs.current[i];
return b ? b.offsetLeft + b.offsetWidth / 2 : 0;
}, []);
const idxRef = useRef(idx);
idxRef.current = idx;
const choose = useCallback(
(i: number) => {
const o = options[Math.max(0, Math.min(options.length - 1, i))];
if (!o) return;
if (value === undefined) setInner(o.value);
if (o.value !== current) onValueChange?.(o.value);
},
[current, onValueChange, options, value],
);
const firstIdx = useRef(true);
useEffect(() => {
sim.current.target = centerOf(idx);
if (!firstIdx.current && !sim.current.drag) sim.current.travel();
firstIdx.current = false;
sim.current.wake();
}, [idx, centerOf, options.length, size]);
useEffect(() => {
sim.current.redrawText();
}, [labelsKey, size]);
// ---- renderer ----
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.className = "pointer-events-none absolute";
canvas.style.left = `${-M}px`;
canvas.style.top = `${-M}px`;
// above the frosting layer (which only blurs the page behind), below the real labels
root.insertBefore(canvas, segRefs.current[0] ?? null);
const gl = canvas.getContext("webgl2", { alpha: true, premultipliedAlpha: true, antialias: false });
if (!gl) {
canvas.remove();
setGpu(false);
return;
}
const compile = (type: number, src: string) => {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
return sh;
};
const prog = gl.createProgram()!;
const vs = compile(gl.VERTEX_SHADER, VERT), fsh = compile(gl.FRAGMENT_SHADER, FRAG);
gl.attachShader(prog, vs);
gl.attachShader(prog, fsh);
gl.bindAttribLocation(prog, 0, "aQ");
gl.linkProgram(prog);
gl.useProgram(prog);
const U = Object.fromEntries(
["uRes", "uOrigin", "uSize", "uDpr", "uLight", "uLift", "uShine", "uMag", "uHover", "uPill", "uThumb", "uTint", "uThumbTint", "uActive", "uIdle", "uText"].map((k) => [k, gl.getUniformLocation(prog, k)]),
) as Record<string, WebGLUniformLocation | null>;
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
const vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const textTex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, textTex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.uniform1i(U.uText, 0);
const textCanvas = document.createElement("canvas");
const still = reduced();
let W = 1, H = 1, dpr = 1;
const th = { x: sim.current.target, v: 0, lift: 0, hover: 0 };
let travelling = false;
sim.current.setLift = (t: number) => {
if (still) return;
gsap.to(th, {
lift: t,
duration: t > 0 ? 0.6 : 0.5,
ease: t > 0 ? "elastic.out(1, 0.55)" : "power3.out",
overwrite: true,
onUpdate: () => {
awake = 3;
},
});
};
sim.current.travel = () => {
if (still) return;
travelling = true;
sim.current.setLift(1);
};
const light = { a: -2.3 };
const lightTo = gsap.quickTo(light, "a", { duration: 0.7, ease: "power3.out" });
let awake = 3;
// the labels, drawn into a texture so the glass can bend them
const drawText = () => {
const tw = Math.max(1, Math.round(W * dpr)), thh = Math.max(1, Math.round(H * dpr));
textCanvas.width = tw;
textCanvas.height = thh;
const ctx = textCanvas.getContext("2d")!;
ctx.clearRect(0, 0, tw, thh);
const cs = getComputedStyle(segRefs.current[0] ?? root);
ctx.font = `${cs.fontWeight || 400} ${fs * dpr}px ${cs.fontFamily}`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#fff";
segRefs.current.forEach((b) => {
if (!b) return;
const label = b.textContent ?? "";
ctx.fillText(label, (b.offsetLeft + b.offsetWidth / 2) * dpr, (H / 2 + fs * 0.04) * dpr);
});
gl.bindTexture(gl.TEXTURE_2D, textTex);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, textCanvas);
awake = 3;
};
const resize = () => {
const r = root.getBoundingClientRect();
W = r.width;
H = r.height;
dpr = Math.min(Math.max(window.devicePixelRatio || 1, 1.5), 2.5); // supersampled a touch for crisp rims
canvas.style.width = `${W + 2 * M}px`;
canvas.style.height = `${H + 2 * M}px`;
canvas.width = Math.round((W + 2 * M) * dpr);
canvas.height = Math.round((H + 2 * M) * dpr);
sim.current.target = centerOf(idxRef.current);
drawText();
};
resize();
th.x = sim.current.target;
const ro = new ResizeObserver(resize);
ro.observe(root);
sim.current.redrawText = drawText;
sim.current.wake = () => {
awake = 3;
};
document.fonts?.ready.then(() => drawText());
const onMove = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
const x = e.clientX - (r.left + r.width / 2), y = e.clientY - (r.top + r.height / 2);
// the light stays above-left, leaning a little toward the cursor: the rim glints slide as you move
const lean = Math.max(-1, Math.min(1, x / Math.max(1, r.width))) * 0.55 + Math.max(-1, Math.min(1, y / 200)) * 0.25;
if (!still) lightTo(-2.3 + lean);
awake = 3;
};
window.addEventListener("pointermove", onMove, { passive: true });
let raf = 0;
let prev = performance.now();
let visible = true;
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
awake = 3;
});
io.observe(root);
const frame = () => {
raf = requestAnimationFrame(frame);
const now = performance.now();
const dt = Math.min(1 / 30, (now - prev) / 1000);
prev = now;
if (!visible) return;
const P = props.current;
const S = sim.current;
// the lens glides with a soft, slightly bouncy give, and lands
const tgt = S.drag ? S.drag.x : S.target;
if (still) {
th.x = tgt;
th.v = 0;
} else {
const k = S.drag ? 1100 : 230, c = 2 * Math.sqrt(k) * (S.drag ? 0.9 : 0.68);
th.v += (k * (tgt - th.x) - c * th.v) * dt;
th.x += th.v * dt;
}
// a tapped lens lifts off, travels, and sinks back once it has landed
if (travelling && !S.drag && Math.abs(tgt - th.x) < 2.5 && Math.abs(th.v) < 60) {
travelling = false;
if (!S.held) S.setLift(0);
}
th.hover += ((S.hover >= 0 ? 1 : 0) - th.hover) * (1 - Math.exp(-dt * 10));
const lightMoving = gsap.isTweening(light) || gsap.isTweening(th);
const energy = Math.abs(th.v) + Math.abs(tgt - th.x);
if (energy > 0.02 || lightMoving || S.drag) awake = 3;
if (awake <= 0) return;
awake--;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.uniform2f(U.uRes, canvas.width, canvas.height);
gl.uniform2f(U.uOrigin, M, M);
gl.uniform2f(U.uSize, W, H);
gl.uniform1f(U.uDpr, dpr);
gl.uniform1f(U.uLight, light.a);
gl.uniform1f(U.uLift, Math.max(0, th.lift));
gl.uniform1f(U.uShine, Math.max(0, P.shine));
gl.uniform1f(U.uMag, Math.max(0, P.magnify));
gl.uniform1f(U.uHover, th.hover);
gl.uniform4f(U.uPill, M + W / 2, M + H / 2, W / 2, H / 2);
const segW = segRefs.current[0]?.offsetWidth ?? W / 2;
// lifted, the lens swells past the track; moving, it leans into its travel a little
const lift = Math.max(0, th.lift);
const sq = still ? 0 : Math.min(Math.abs(th.v) / 2600, 0.1);
gl.uniform4f(U.uThumb, M + th.x, M + H / 2, (segW / 2 - pad * 0.15) * (1 + 0.07 * lift) * (1 + sq), (H / 2 - pad) * (1 + 0.22 * lift) * (1 - sq * 0.45));
gl.uniform3fv(U.uTint, hex(P.tint));
gl.uniform3fv(U.uThumbTint, hex(P.thumb));
gl.uniform3fv(U.uActive, hex(P.activeColor));
gl.uniform3fv(U.uIdle, hex(P.labelColor));
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, textTex);
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
raf = requestAnimationFrame(frame);
return () => {
cancelAnimationFrame(raf);
sim.current.wake = () => {};
sim.current.redrawText = () => {};
ro.disconnect();
io.disconnect();
window.removeEventListener("pointermove", onMove);
gsap.killTweensOf(light);
gsap.killTweensOf(th);
gl.deleteTexture(textTex);
gl.deleteProgram(prog);
gl.deleteShader(vs);
gl.deleteShader(fsh);
gl.deleteBuffer(vbo);
gl.deleteVertexArray(vao);
gl.getExtension("WEBGL_lose_context")?.loseContext();
canvas.remove();
};
}, [centerOf, fs, pad]);
// ---- press and drag the thumb ----
const dragState = useRef<{ id: number; startX: number; moved: boolean; offset: number } | null>(null);
const suppressClick = useRef(false);
const onPointerDown = (e: RPointerEvent<HTMLDivElement>) => {
const r = rootRef.current?.getBoundingClientRect();
if (!r) return;
const x = e.clientX - r.left;
const thumbX = centerOf(idx);
const segW = segRefs.current[0]?.offsetWidth ?? 0;
// touched, the lens lifts off the track
sim.current.held = true;
sim.current.setLift(1);
sim.current.wake();
if (Math.abs(x - thumbX) < segW / 2) {
dragState.current = { id: e.pointerId, startX: x, moved: false, offset: thumbX - x };
if (e.pointerType === "mouse") e.preventDefault();
}
};
const onPointerMove = (e: RPointerEvent<HTMLDivElement>) => {
const d = dragState.current;
const r = rootRef.current?.getBoundingClientRect();
if (!d || !r || d.id !== e.pointerId) return;
const x = e.clientX - r.left;
if (!d.moved && Math.abs(x - d.startX) > 4) {
d.moved = true;
(e.currentTarget as HTMLDivElement).setPointerCapture(e.pointerId);
}
if (!d.moved) return;
const first = centerOf(0), last = centerOf(options.length - 1);
const segW = segRefs.current[0]?.offsetWidth ?? 0;
// held, the lens lifts fully; at the ends it meets the rim with a firm, short give
let tx = x + d.offset;
if (tx < first) tx = first - Math.min(segW * 0.06, (first - tx) * 0.2);
if (tx > last) tx = last + Math.min(segW * 0.06, (tx - last) * 0.2);
sim.current.drag = { x: tx };
sim.current.wake();
};
const release = (e: RPointerEvent<HTMLDivElement>) => {
sim.current.held = false;
sim.current.setLift(0);
sim.current.wake();
const d = dragState.current;
if (!d || d.id !== e.pointerId) return;
dragState.current = null;
const drag = sim.current.drag;
sim.current.drag = null;
if (d.moved && drag) {
let best = 0, bd = Infinity;
options.forEach((_, i) => {
const dd = Math.abs(centerOf(i) - drag.x);
if (dd < bd) {
bd = dd;
best = i;
}
});
suppressClick.current = true;
choose(best);
}
};
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
const n = options.length;
let next = idx;
if (e.key === "ArrowRight" || e.key === "ArrowDown") next = (idx + 1) % n;
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") next = (idx - 1 + n) % n;
else if (e.key === "Home") next = 0;
else if (e.key === "End") next = n - 1;
else return;
e.preventDefault();
choose(next);
segRefs.current[next]?.focus();
};
const radius = size / 2;
return (
<div
ref={rootRef}
role="radiogroup"
aria-label={ariaLabel}
onKeyDown={onKeyDown}
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={release}
onPointerCancel={release}
onPointerLeave={() => {
sim.current.hover = -1;
sim.current.wake();
}}
className={["relative inline-grid select-none", className].filter(Boolean).join(" ")}
style={{ height: size, padding: pad, borderRadius: radius, gridAutoFlow: "column", gridAutoColumns: "1fr", touchAction: "pan-y" }}
>
{/* behind the glass: over a light page the body is frosted by the browser */}
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0"
style={{
borderRadius: radius,
backdropFilter: "blur(18px) saturate(1.4)",
WebkitBackdropFilter: "blur(18px) saturate(1.4)",
background: gpu ? undefined : `rgba(${hex(tint).map((v) => Math.round(v * 60)).join(",")}, 0.85)`,
boxShadow: gpu ? undefined : "inset 0 1px 0.5px rgba(255,255,255,0.45), inset 0 -1px 1px rgba(255,255,255,0.12)",
}}
/>
{!gpu && (
<div
aria-hidden="true"
className="pointer-events-none absolute transition-[left] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)]"
style={{
top: pad,
bottom: pad,
left: segRefs.current[idx]?.offsetLeft ?? pad,
width: segRefs.current[idx]?.offsetWidth ?? 0,
borderRadius: radius,
background: `rgba(${hex(thumb).map((v) => Math.round(v * 255)).join(",")}, 0.45)`,
boxShadow: "inset 0 1px 0.5px rgba(255,255,255,0.3)",
}}
/>
)}
{options.map((o, i) => {
const on = i === idx;
return (
<button
key={o.value}
ref={(el) => {
segRefs.current[i] = el;
}}
type="button"
role="radio"
aria-checked={on}
tabIndex={on ? 0 : -1}
onPointerEnter={() => {
sim.current.hover = i;
sim.current.wake();
}}
onClick={() => {
if (suppressClick.current) {
suppressClick.current = false;
return;
}
choose(i);
}}
className="relative z-10 grid h-full place-items-center rounded-full font-normal tracking-[-0.01em] whitespace-nowrap outline-none focus-visible:shadow-[inset_0_0_0_1px_rgba(255,255,255,0.42)]"
// the visible labels are drawn inside the glass; these stay for screen readers, selection and the fallback
style={{ paddingInline: Math.round(size * 0.42), minWidth: Math.round(size * 1.7), fontSize: fs, color: gpu ? "transparent" : on ? activeColor : labelColor }}
>
{o.label}
</button>
);
})}
</div>
);
}
export default LiquidSegmented;
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
13 propsoptions{ value: string; label: string }[]The choices.default Inbox, Draftdefault Inbox, DraftvaluestringControlled value.defaultValuestringInitial value when uncontrolled.onValueChange(value: string) => voidCalled with the chosen value.sizenumberHeight of the control, px.default 64default 64tintstringColour of the glass track.default "#ffffff"default "#ffffff"thumbstringColour of the lens's frosted glass at rest.default "#ffffff"default "#ffffff"activeColorstringColour of the chosen label (under the thumb).default "#ffffff"default "#ffffff"labelColorstringColour of the other labels.default "#8e8e93"default "#8e8e93"shinenumberStrength of the rim light.default 1default 1magnifynumberHow strongly the lifted lens magnifies the labels under it.default 1default 1aria-labelstringAccessible name of the group.default "Choose a view"default "Choose a view"classNamestringExtra classes on the control.