Joined options for switching between views of one thing
← → move the pick; Home and End jump to the ends
pnpm dlx shadcn@latest add https://notchset.dev/r/segmented-control.jsonTwo to five views of the same thing; one always chosen.
Every shadcn style · one file
Import it and pass your content. The props that matter most are listed next.
"use client";
import * as React from "react";
import { Card, CardHeader } from "@/components/ui/notchset/card";
import { ButtonRoll } from "@/lib/notchset/button-look";
import { SegmentedControl } from "@/components/ui/notchset/segmented-control";
import { useLessMotion } from "@/lib/notchset/motion";
import { useSelfPlay } from "./self-play";
/*
* One segmented control alone, enlarged: Day, Week, Month on the ink thumb, one always chosen, with one quiet line
* under it naming the pick, which rolls as the thumb lands. On arrival the thumb glides once from Day to Week. The
* arrow keys walk the options and pick as they go.
*/
const SPAN = { label: "Span", chosen: "week", options: [{ value: "day", label: "Day" }, { value: "week", label: "Week" }, { value: "month", label: "Month" }] };
const SAYS: Record<string, string> = { day: "Showing today", week: "Showing this week", month: "Showing all of November" };
export default function SegmentedControlDemo() {
const group = SPAN;
const root = React.useRef<HTMLDivElement>(null);
const less = useLessMotion();
const play = useSelfPlay(root, { beats: [400], off: less });
/* before its glide the thumb waits on Day; the play (or a hand) takes it to Week */
const [picked, setPicked] = React.useState<string | null>(null);
const resting = play.taken === 0 && play.control !== "replay";
const pick = picked ?? (resting ? "day" : group.chosen);
const say = SAYS[pick];
return (
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex flex-col items-center gap-4">
<div className="">
<SegmentedControl label={group.label} look="ink" value={pick} onValueChange={setPicked} options={group.options} />
</div>
{say ? (
<span aria-live="polite" className="flex text-[15px] leading-5 text-[var(--ns-ink-2)]">
<ButtonRoll k={pick}>{say}</ButtonRoll>
</span>
) : null}
</div>
);
}
/*
* At work: the view switch heading a project's tasks.
* Each view is real: List, Board and Calendar show the same six tasks their own way.
*/
const VIEWS = [{ value: "list", label: "List" }, { value: "board", label: "Board" }, { value: "calendar", label: "Calendar" }];
type Task = { title: string; status: "todo" | "doing" | "done"; day: number };
const TASKS: Task[] = [
{ title: "Draft the launch post", status: "doing", day: 1 },
{ title: "Price page copy", status: "todo", day: 3 },
{ title: "Press list", status: "todo", day: 4 },
{ title: "Onboarding email", status: "done", day: 0 },
{ title: "Demo video cut", status: "doing", day: 2 },
{ title: "Changelog entry", status: "done", day: 1 },
];
const LANES = [{ id: "todo", label: "To do" }, { id: "doing", label: "Doing" }, { id: "done", label: "Done" }] as const;
const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri"];
export function AtWork() {
const [view, setView] = React.useState("board");
return (
<Card inset className="w-[min(100%,var(--ns-width-lg))] gap-4">
<CardHeader
title="Q4 launch"
count="6 tasks"
aside={<SegmentedControl label="View" size="sm" value={view} onValueChange={setView} options={VIEWS} />}
/>
{view === "list" && (
<ul className="m-0 flex list-none flex-col p-0">
{TASKS.map((t) => (
<li key={t.title} className="flex items-center justify-between border-b border-[var(--ns-line-soft)] py-2 text-[length:var(--ns-text-small)] text-[var(--ns-ink)] last:border-b-0">
{t.title}
<span className="text-[var(--ns-ink-3)]">{LANES.find((l) => l.id === t.status)?.label}</span>
</li>
))}
</ul>
)}
{view === "board" && (
<div className="grid grid-cols-3 gap-2">
{LANES.map((lane) => (
<div key={lane.id} className="flex flex-col gap-1.5 rounded-[var(--ns-radius-control)] bg-[var(--ns-well)] p-2">
<p className="m-0 px-1 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{lane.label}</p>
{TASKS.filter((t) => t.status === lane.id).map((t) => (
<p key={t.title} className="m-0 rounded-[calc(var(--ns-radius-control)-2px)] bg-[var(--ns-panel)] px-2.5 py-2 text-[length:var(--ns-text-small)] text-[var(--ns-ink)] shadow-[var(--ns-tile-shadow)]">
{t.title}
</p>
))}
</div>
))}
</div>
)}
{view === "calendar" && (
<div className="grid grid-cols-5 gap-2">
{DAYS.map((d, i) => (
<div key={d} className="flex min-h-24 min-w-0 flex-col gap-1.5 rounded-[var(--ns-radius-control)] bg-[var(--ns-well)] p-2">
<p className="m-0 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{d}</p>
{TASKS.filter((t) => t.day === i).map((t) => (
<p key={t.title} className="m-0 truncate text-[length:var(--ns-text-small)] text-[var(--ns-ink)]" title={t.title}>
{t.title}
</p>
))}
</div>
))}
</div>
)}
</Card>
);
}"use client";
import * as React from "react";
import { Card, CardHeader } from "@/components/ui/notchset/card";
import { ButtonRoll } from "@/lib/notchset/button-look";
import { SegmentedControl } from "@/components/ui/notchset/segmented-control";
import { useLessMotion } from "@/lib/notchset/motion";
import { useSelfPlay } from "./self-play";
/*
* One segmented control alone, enlarged: Day, Week, Month on the ink thumb, one always chosen, with one quiet line
* under it naming the pick, which rolls as the thumb lands. On arrival the thumb glides once from Day to Week. The
* arrow keys walk the options and pick as they go.
*/
const SPAN = { label: "Span", chosen: "week", options: [{ value: "day", label: "Day" }, { value: "week", label: "Week" }, { value: "month", label: "Month" }] };
const SAYS: Record<string, string> = { day: "Showing today", week: "Showing this week", month: "Showing all of November" };
export default function SegmentedControlDemo() {
const group = SPAN;
const root = React.useRef<HTMLDivElement>(null);
const less = useLessMotion();
const play = useSelfPlay(root, { beats: [400], off: less });
/* before its glide the thumb waits on Day; the play (or a hand) takes it to Week */
const [picked, setPicked] = React.useState<string | null>(null);
const resting = play.taken === 0 && play.control !== "replay";
const pick = picked ?? (resting ? "day" : group.chosen);
const say = SAYS[pick];
return (
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex flex-col items-center gap-4">
<div className="">
<SegmentedControl label={group.label} look="ink" value={pick} onValueChange={setPicked} options={group.options} />
</div>
{say ? (
<span aria-live="polite" className="flex text-[15px] leading-5 text-[var(--ns-ink-2)]">
<ButtonRoll k={pick}>{say}</ButtonRoll>
</span>
) : null}
</div>
);
}
/*
* At work: the view switch heading a project's tasks.
* Each view is real: List, Board and Calendar show the same six tasks their own way.
*/
const VIEWS = [{ value: "list", label: "List" }, { value: "board", label: "Board" }, { value: "calendar", label: "Calendar" }];
type Task = { title: string; status: "todo" | "doing" | "done"; day: number };
const TASKS: Task[] = [
{ title: "Draft the launch post", status: "doing", day: 1 },
{ title: "Price page copy", status: "todo", day: 3 },
{ title: "Press list", status: "todo", day: 4 },
{ title: "Onboarding email", status: "done", day: 0 },
{ title: "Demo video cut", status: "doing", day: 2 },
{ title: "Changelog entry", status: "done", day: 1 },
];
const LANES = [{ id: "todo", label: "To do" }, { id: "doing", label: "Doing" }, { id: "done", label: "Done" }] as const;
const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri"];
export function AtWork() {
const [view, setView] = React.useState("board");
return (
<Card inset className="w-[min(100%,var(--ns-width-lg))] gap-4">
<CardHeader
title="Q4 launch"
count="6 tasks"
aside={<SegmentedControl label="View" size="sm" value={view} onValueChange={setView} options={VIEWS} />}
/>
{view === "list" && (
<ul className="m-0 flex list-none flex-col p-0">
{TASKS.map((t) => (
<li key={t.title} className="flex items-center justify-between border-b border-[var(--ns-line-soft)] py-2 text-[length:var(--ns-text-small)] text-[var(--ns-ink)] last:border-b-0">
{t.title}
<span className="text-[var(--ns-ink-3)]">{LANES.find((l) => l.id === t.status)?.label}</span>
</li>
))}
</ul>
)}
{view === "board" && (
<div className="grid grid-cols-3 gap-2">
{LANES.map((lane) => (
<div key={lane.id} className="flex flex-col gap-1.5 rounded-[var(--ns-radius-control)] bg-[var(--ns-well)] p-2">
<p className="m-0 px-1 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{lane.label}</p>
{TASKS.filter((t) => t.status === lane.id).map((t) => (
<p key={t.title} className="m-0 rounded-[calc(var(--ns-radius-control)-2px)] bg-[var(--ns-panel)] px-2.5 py-2 text-[length:var(--ns-text-small)] text-[var(--ns-ink)] shadow-[var(--ns-tile-shadow)]">
{t.title}
</p>
))}
</div>
))}
</div>
)}
{view === "calendar" && (
<div className="grid grid-cols-5 gap-2">
{DAYS.map((d, i) => (
<div key={d} className="flex min-h-24 min-w-0 flex-col gap-1.5 rounded-[var(--ns-radius-control)] bg-[var(--ns-well)] p-2">
<p className="m-0 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{d}</p>
{TASKS.filter((t) => t.day === i).map((t) => (
<p key={t.title} className="m-0 truncate text-[length:var(--ns-text-small)] text-[var(--ns-ink)]" title={t.title}>
{t.title}
</p>
))}
</div>
))}
</div>
)}
</Card>
);
}"use client";
import * as React from "react";
/*
* A demo that plays itself until the first touch: the script lives in the demo, never in the piece, which only gets
* the props a person would give it. It moves 0.4 s after the piece is first seen, then takes each step on its beat;
* off screen or paused it waits. The first press, key or focus on the piece (bind `handOver` to it; a scroll over it never counts) makes it the
* visitor's for good and drops every queued step; with less motion (`off`) it never plays and rests in its first frame.
* A host can hand it over from outside the piece too (a settings panel beside it the visitor has used): under
* <HandedOver value>, it never plays, a remount included.
*
* const play = useSelfPlay(root, { beats: [2800, 2800], loop: true, off: less });
* <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} onFocusCapture={play.handOver}>
* play.step // the step it is at, -1 before its first
* play.control // "pause" while it plays, "play" once paused (a new take), "replay" once it is over or yours
*
* Each step presses the piece's own controls (pressIn), so the script shows exactly what a hand can do.
*
* A host that shows the piece once (<PlayOnce value={{ settle }}>) changes three things: the script starts when the
* piece is first half in view and never again on coming back, it never loops, and with less motion (or `settle`) it
* takes every step at once, so the piece rests on the END of its moment. `hold` is a reason not to play at all that is
* not motion (a mode with nothing to show): it holds in every host. Under <PlayOnce value={{ active: false }}> (a look
* that is mounted but not shown) it waits until it is shown.
*/
type SelfPlayOptions = {
/** how long each step waits after the one before it, in ms; the first step waits 0.4 s after the piece is seen */
beats: readonly number[];
/** starts over after the last step; without it the script plays once and rests */
loop?: boolean | undefined;
/** no self-play at all (less motion): the piece is the visitor's from the start */
off: boolean;
/** no self-play for a reason other than motion (a mode with nothing to show), in every host */
hold?: boolean | undefined;
};
/** How a host shows the piece: once on arrival (see useSelfPlay). */
type PlayOnceHost = {
/** rest on the end at once, without playing (less motion, or a reset) */
settle?: boolean | undefined;
/** false while the piece is mounted but not shown: it waits */
active?: boolean | undefined;
};
const START = 400;
/**
* Whether a demo plays itself at all. Off: every piece rests in its first frame and is
* the visitor's from the start; nothing presses its controls for them.
*/
const SELF_PLAY: boolean = false;
/** True where the visitor has already taken the piece from outside it: nothing under it plays itself. */
const HandedOver = React.createContext(false);
/** A host that shows the piece once: play once on arrival, rest on the end (null: play as the demo asks). */
const PlayOnce = React.createContext<PlayOnceHost | null>(null);
function useSelfPlay(root: React.RefObject<Element | null>, { beats, loop: looped = false, off: still, hold = false }: SelfPlayOptions) {
const once = React.useContext(PlayOnce);
const active = once?.active !== false;
/* shown once: less motion (or a settled host) takes every step at once and rests on the end */
const quick = once != null && (still || Boolean(once.settle));
const loop = once == null && looped;
/* the first touch hands it over for good */
const [mine, setMine] = React.useState(false);
const handOver = React.useCallback(() => setMine(true), []);
const handedOver = React.useContext(HandedOver);
const off = !SELF_PLAY || hold || (quick ? false : still) || mine || (handedOver && !quick);
const [seen, setSeen] = React.useState(false);
const [paused, setPaused] = React.useState(false);
const [taken, setTaken] = React.useState(0);
const n = Math.max(1, beats.length);
const done = !loop && taken >= n;
React.useEffect(() => {
const el = root.current;
if (!active) return;
/* without an observer (an old browser, a test) it counts as seen */
if (!el || typeof IntersectionObserver === "undefined" || quick) {
const t = window.setTimeout(() => setSeen(true));
return () => window.clearTimeout(t);
}
/* shown once: first half in view starts it, and leaving never stops or restarts it */
const io = once
? new IntersectionObserver((es) => {
if (es.some((e) => e.isIntersecting && e.intersectionRatio >= 0.5)) {
setSeen(true);
io.disconnect();
}
}, { threshold: 0.5 })
: new IntersectionObserver((es) => setSeen(es.some((e) => e.isIntersecting)));
io.observe(el);
return () => io.disconnect();
}, [root, active, once, quick]);
const playing = !off && seen && active && !paused && !done;
const delay = quick ? 0 : taken === 0 ? START : (beats[taken % n] ?? START);
React.useEffect(() => {
if (!playing) return;
const t = window.setTimeout(() => setTaken((k) => k + 1), delay);
return () => window.clearTimeout(t);
}, [playing, taken, delay]);
/* one control in one place: Pause while it plays, Play (a new take) once paused, Replay once it is over or yours */
/* self-play off: never "over", so a demo rests in its FIRST frame, not its end frame */
const control: "pause" | "play" | "replay" = paused || !SELF_PLAY ? "play" : off || done ? "replay" : "pause";
return { step: taken === 0 ? -1 : (taken - 1) % n, taken, playing, control, mine, handOver, pause: () => setPaused(true) };
}
/**
* Presses a real control inside `root`, as the visitor would: the first match of `selector`, or the one whose text is
* `text`. A click only, so it never counts as the visitor's touch.
*/
function pressIn(root: Element | null, selector: string, text?: string) {
const all = [...(root?.querySelectorAll<HTMLElement>(selector) ?? [])];
(text == null ? all[0] : all.find((el) => el.textContent?.trim() === text))?.click();
}
export { HandedOver, PlayOnce, pressIn, useSelfPlay, type PlayOnceHost, type SelfPlayOptions };This example also uses Card. This command installs them with it, so the example pastes as it is:
pnpm dlx shadcn@latest add https://notchset.dev/r/segmented-control.json https://notchset.dev/r/card.jsoncomponents/ui/notchset/segmented-control.tsx
LevelAtom: uses no other piece.
Made ofTooltip
Free, no account or key. One command for every shadcn style. With the @notchset registry added, @notchset/<name> works too.
Works with React 18.3 or 19 on Tailwind CSS v4, in any shadcn project. What's tested
pnpm add @base-ui/react@^1The CLI adds the styles to the CSS file named in components.json (tailwind.css). Check that it points at your global stylesheet, that the project uses Tailwind CSS v4, and that the file is imported in your root layout. Installed by hand: paste styles.css into that file.
options–
Option<V>[]Required.
value–
Vthe chosen option (controlled), with onValueChange
defaultValue–
Vthe option chosen first when it keeps its own choice (uncontrolled); the first option without one
onValueChange–
(value: V) => voidlabel–
stringNames the group for screen readers ("View").
size"md"
"md" | "sm"md is a button's height, sm a small button's
look"signal"
"signal" | "quiet" | "ink"signal fills the chosen option in the Signature; quiet draws it as ink on the canvas, for a row of states or views; ink rides an ink thumb on the tonal track, for a control shown on its own
iconOnlyfalse
booleaneach option is its icon alone: its `label` (a string) names it and shows as its tooltip
locale–
stringhow the counts are written (en-US by default, never the viewer's)
name–
stringthe form field name: a form sends the chosen value
Three usesa view (List | Board) · a period (This quarter | This year) · a unit (°C | °F)
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)v1.1.0 · 2026-11-17
New props: iconOnly. Ships motion.ts (EASE, lessMotion, roleTiming, useLessMotion), which it now uses.
v1.0.0 · 2026-11-09
Released free with the Notchset system.