A floating panel that opens from a control and stays
Press the trigger, or focus it and press Enter · Esc closes
pnpm dlx shadcn@latest add https://notchset.dev/r/popover.jsonContent that opens from a control and stays while you read it.
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 { cn } from "@/lib/utils";
import { IconButton } from "@/components/ui/notchset/icon-button";
import { useLessMotion } from "@/lib/notchset/motion";
import { PartOfWhole, Popover } from "@/components/ui/notchset/popover";
import { RollingNumber } from "@/components/ui/notchset/rolling-number";
import { SegmentedControl } from "@/components/ui/notchset/segmented-control";
import { useSelfPlay } from "./self-play";
/*
* A win rate on a report, with its "i" beside the figure (never over it). The press opens the popover in the bloom: what
* the figure means, a picture of the part won, and its period. A new period rolls the figure on the page and the
* picture with it; the numbers add up in every period. Esc, a press outside or the "i" again folds it back into the "i".
* One look at a time, each resting closed: "Showpiece" draws fifty squares that drop, flip and gather, and its trigger
* wears its figure (a 4 x 4 of those squares); "Plain" draws a split bar under a quiet words trigger. The figure's label
* names the popover; it draws no title of its own. On arrival it opens once and folds back.
*/
type Period = "30" | "90" | "365";
const DEALS: Record<Period, { won: number; closed: number }> = {
"30": { won: 8, closed: 19 },
"90": { won: 19, closed: 50 },
"365": { won: 68, closed: 200 },
};
const rateOf = (p: Period) => Math.round((DEALS[p].won / DEALS[p].closed) * 100);
const PERIODS = [
{ value: "30" as const, label: "30" },
{ value: "90" as const, label: "90" },
{ value: "365" as const, label: "365" },
];
const WON = "bg-[var(--ns-btn-ok)]";
const LOST = "bg-[color-mix(in_oklab,var(--ns-ink)_11%,transparent)]";
const BEATS = [500, 2200];
/* the showpiece's trigger wears its figure: a 4 x 4 of the surface's squares, the won share filled green */
function TileGlyph({ part }: { part: number }) {
const on = Math.round((part / 100) * 16);
return (
<span aria-hidden data-slot="popover-demo-glyph" className="grid grid-cols-4 gap-[2px]">
{Array.from({ length: 16 }, (_, k) => (
<span key={k} className={cn("size-[4px] rounded-[1px] [transition:background-color_var(--ns-time-color)]", k < on ? WON : LOST)} />
))}
</span>
);
}
function WinRate({ look }: { look: "plain" | "showpiece" }) {
const less = useLessMotion();
const [period, setPeriod] = React.useState<Period>("90");
const [open, setOpen] = React.useState(false);
const rate = rateOf(period);
const { won, closed } = DEALS[period];
const root = React.useRef<HTMLDivElement>(null);
/* the arrival: it opens once, then folds back into its trigger */
const play = useSelfPlay(root, { beats: BEATS, off: less });
React.useEffect(() => {
if (play.mine || play.step < 0) return;
// eslint-disable-next-line react-hooks/set-state-in-effect -- each step of the arrival lands on its beat, as a hand's would
setOpen(play.step === 0);
}, [play.step, play.mine]);
const showpiece = look === "showpiece";
return (
/* it rests closed, centred, with room under it for the surface to open inside the stage */
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex justify-center py-[186px]">
<div data-slot="popover-demo-look" data-look={look} className="flex flex-col items-start">
<span className="text-[length:var(--ns-text-small)] leading-4 font-[number:var(--ns-weight-medium)] text-[var(--ns-ink-3)]">Win rate</span>
<div className={cn("mt-1 flex gap-1", showpiece ? "items-center" : "flex-col items-start")}>
<span data-slot="popover-demo-figure" className="inline-flex items-baseline text-[56px] leading-[60px] font-[number:var(--ns-weight-medium)] tracking-[-0.035em] text-[var(--ns-ink)] tabular-nums">
<RollingNumber value={String(rate)} />%
</span>
<Popover
look={look}
label="Win rate"
align={showpiece ? "center" : "start"}
open={open}
onOpenChange={setOpen}
className="w-[min(292px,calc(100vw-32px))] p-3.5"
trigger={
showpiece ? (
<IconButton intent="ghost" size="sm" label="About win rate" className="text-[var(--ns-ink-3)] data-popup-open:bg-[var(--ns-hover)] data-popup-open:text-[var(--ns-ink)]">
<TileGlyph part={rate} />
</IconButton>
) : (
<button type="button" aria-label="About win rate" data-slot="popover-demo-words" className="inline-flex h-7 cursor-pointer items-center rounded-[6px] px-1 text-[length:var(--ns-text-small)] leading-5 font-[number:var(--ns-weight-medium)] text-[var(--ns-ink-3)] underline decoration-[color-mix(in_oklab,var(--ns-ink)_28%,transparent)] decoration-dotted underline-offset-[5px] outline-hidden [transition:color_var(--ns-time-color)] hover:text-[var(--ns-ink)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ns-signal)] data-popup-open:text-[var(--ns-ink)] pointer-coarse:min-h-11">
How it is counted
</button>
)
}
>
<p className="m-0 text-[length:var(--ns-text-small)] leading-[18px] text-[var(--ns-ink-2)]">
Won deals / closed deals, last <span className="font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">{period} days</span>
</p>
<div className={showpiece ? "mt-3" : "mt-4 mb-1"}>
<PartOfWhole part={rate} label={`${won} won of ${closed} closed deals, ${rate}%`} />
</div>
<div className="mt-3 flex items-center justify-between gap-3 border-t border-[var(--ns-line)] pt-3">
<span data-slot="popover-demo-count" className="inline-flex items-center gap-1.5 text-[length:var(--ns-text-meta)] leading-4 font-[number:var(--ns-weight-medium)] whitespace-nowrap text-[var(--ns-ink-3)] tabular-nums">
<span aria-hidden className="size-2 rounded-full bg-[var(--ns-btn-ok)]" />
<span>
<span className="text-[var(--ns-ink)]">{won} won</span> of {closed}
</span>
</span>
<SegmentedControl label="Period in days" size="sm" options={PERIODS} value={period} onValueChange={setPeriod} />
</div>
</Popover>
</div>
</div>
</div>
);
}
export default function PopoverDemo() {
const look = ("showpiece" as string) === "plain" ? "plain" : "showpiece";
return <WinRate key={look} look={look} />;
}"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
import { IconButton } from "@/components/ui/notchset/icon-button";
import { useLessMotion } from "@/lib/notchset/motion";
import { PartOfWhole, Popover } from "@/components/ui/notchset/popover";
import { RollingNumber } from "@/components/ui/notchset/rolling-number";
import { SegmentedControl } from "@/components/ui/notchset/segmented-control";
import { useSelfPlay } from "./self-play";
/*
* A win rate on a report, with its "i" beside the figure (never over it). The press opens the popover in the bloom: what
* the figure means, a picture of the part won, and its period. A new period rolls the figure on the page and the
* picture with it; the numbers add up in every period. Esc, a press outside or the "i" again folds it back into the "i".
* One look at a time, each resting closed: "Showpiece" draws fifty squares that drop, flip and gather, and its trigger
* wears its figure (a 4 x 4 of those squares); "Plain" draws a split bar under a quiet words trigger. The figure's label
* names the popover; it draws no title of its own. On arrival it opens once and folds back.
*/
type Period = "30" | "90" | "365";
const DEALS: Record<Period, { won: number; closed: number }> = {
"30": { won: 8, closed: 19 },
"90": { won: 19, closed: 50 },
"365": { won: 68, closed: 200 },
};
const rateOf = (p: Period) => Math.round((DEALS[p].won / DEALS[p].closed) * 100);
const PERIODS = [
{ value: "30" as const, label: "30" },
{ value: "90" as const, label: "90" },
{ value: "365" as const, label: "365" },
];
const WON = "bg-[var(--ns-btn-ok)]";
const LOST = "bg-[color-mix(in_oklab,var(--ns-ink)_11%,transparent)]";
const BEATS = [500, 2200];
/* the showpiece's trigger wears its figure: a 4 x 4 of the surface's squares, the won share filled green */
function TileGlyph({ part }: { part: number }) {
const on = Math.round((part / 100) * 16);
return (
<span aria-hidden data-slot="popover-demo-glyph" className="grid grid-cols-4 gap-[2px]">
{Array.from({ length: 16 }, (_, k) => (
<span key={k} className={cn("size-[4px] rounded-[1px] [transition:background-color_var(--ns-time-color)]", k < on ? WON : LOST)} />
))}
</span>
);
}
function WinRate({ look }: { look: "plain" | "showpiece" }) {
const less = useLessMotion();
const [period, setPeriod] = React.useState<Period>("90");
const [open, setOpen] = React.useState(false);
const rate = rateOf(period);
const { won, closed } = DEALS[period];
const root = React.useRef<HTMLDivElement>(null);
/* the arrival: it opens once, then folds back into its trigger */
const play = useSelfPlay(root, { beats: BEATS, off: less });
React.useEffect(() => {
if (play.mine || play.step < 0) return;
// eslint-disable-next-line react-hooks/set-state-in-effect -- each step of the arrival lands on its beat, as a hand's would
setOpen(play.step === 0);
}, [play.step, play.mine]);
const showpiece = look === "showpiece";
return (
/* it rests closed, centred, with room under it for the surface to open inside the stage */
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex justify-center py-[186px]">
<div data-slot="popover-demo-look" data-look={look} className="flex flex-col items-start">
<span className="text-[length:var(--ns-text-small)] leading-4 font-[number:var(--ns-weight-medium)] text-[var(--ns-ink-3)]">Win rate</span>
<div className={cn("mt-1 flex gap-1", showpiece ? "items-center" : "flex-col items-start")}>
<span data-slot="popover-demo-figure" className="inline-flex items-baseline text-[56px] leading-[60px] font-[number:var(--ns-weight-medium)] tracking-[-0.035em] text-[var(--ns-ink)] tabular-nums">
<RollingNumber value={String(rate)} />%
</span>
<Popover
look={look}
label="Win rate"
align={showpiece ? "center" : "start"}
open={open}
onOpenChange={setOpen}
className="w-[min(292px,calc(100vw-32px))] p-3.5"
trigger={
showpiece ? (
<IconButton intent="ghost" size="sm" label="About win rate" className="text-[var(--ns-ink-3)] data-popup-open:bg-[var(--ns-hover)] data-popup-open:text-[var(--ns-ink)]">
<TileGlyph part={rate} />
</IconButton>
) : (
<button type="button" aria-label="About win rate" data-slot="popover-demo-words" className="inline-flex h-7 cursor-pointer items-center rounded-[6px] px-1 text-[length:var(--ns-text-small)] leading-5 font-[number:var(--ns-weight-medium)] text-[var(--ns-ink-3)] underline decoration-[color-mix(in_oklab,var(--ns-ink)_28%,transparent)] decoration-dotted underline-offset-[5px] outline-hidden [transition:color_var(--ns-time-color)] hover:text-[var(--ns-ink)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ns-signal)] data-popup-open:text-[var(--ns-ink)] pointer-coarse:min-h-11">
How it is counted
</button>
)
}
>
<p className="m-0 text-[length:var(--ns-text-small)] leading-[18px] text-[var(--ns-ink-2)]">
Won deals / closed deals, last <span className="font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">{period} days</span>
</p>
<div className={showpiece ? "mt-3" : "mt-4 mb-1"}>
<PartOfWhole part={rate} label={`${won} won of ${closed} closed deals, ${rate}%`} />
</div>
<div className="mt-3 flex items-center justify-between gap-3 border-t border-[var(--ns-line)] pt-3">
<span data-slot="popover-demo-count" className="inline-flex items-center gap-1.5 text-[length:var(--ns-text-meta)] leading-4 font-[number:var(--ns-weight-medium)] whitespace-nowrap text-[var(--ns-ink-3)] tabular-nums">
<span aria-hidden className="size-2 rounded-full bg-[var(--ns-btn-ok)]" />
<span>
<span className="text-[var(--ns-ink)]">{won} won</span> of {closed}
</span>
</span>
<SegmentedControl label="Period in days" size="sm" options={PERIODS} value={period} onValueChange={setPeriod} />
</div>
</Popover>
</div>
</div>
</div>
);
}
export default function PopoverDemo() {
const look = ("showpiece" as string) === "plain" ? "plain" : "showpiece";
return <WinRate key={look} look={look} />;
}"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 Icon button, Rolling number, Segmented control. This command installs them with it, so the example pastes as it is:
pnpm dlx shadcn@latest add https://notchset.dev/r/popover.json https://notchset.dev/r/icon-button.json https://notchset.dev/r/rolling-number.json https://notchset.dev/r/segmented-control.jsoncomponents/ui/notchset/popover.tsx
LevelAtom: uses no other piece.
Made ofNothing else from the library: the foundation alone.
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.
The sound you hear is this page's: the piece you install plays none, and calls onFeedback on each move so you can add your own.
trigger–
React.ReactElementThe control that opens it: one element that takes a ref (a Button, a chip, a link).
title–
React.ReactNodeIts heading, read out as its name.
label–
stringIts name when it draws no title (the trigger's figure already says it).
side–
"top" | "bottom" | "inline-start" | "inline-end"Where it opens; inline-start and inline-end follow the reading direction.
align–
"start" | "center" | "end"How it lines up with the trigger along that side.
open–
booleanopen, when the host holds it (with onOpenChange)
defaultOpen–
booleanopen on first render, then it opens and closes on its own
onOpenChange–
(open: boolean) => voidcalled with the next open state: the trigger, Escape or a click outside
on–
"press" | "hover"press (the default): a press opens it; hover: hover or focus opens it as a read-only preview
delay–
numberhover only: how long the pointer or focus rests on the trigger before it opens, in ms (Base UI's 600 when left out)
look–
"plain" | "showpiece"how much its picture plays: "plain" (the default, in an app) or "showpiece" (a PartOfWhole's grid drops, flips and gathers)
onFeedback–
(e: FeedbackEvent) => voidcalled once per move, for your sound or haptics
Three useswho is on a record · a filter's few fields · a date's or a figure's details
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)v1.1.0 · 2026-11-17
New props: delay, label, look, onFeedback. Ships bloom.ts (BloomSkin, bloomClose, bloomOpen, BeforeFold, useBloom), which it now uses. Ships feedback.ts (FeedbackEvent, FeedbackProps), which it now uses. Ships media.ts (CONFIRM_MS, HOLD_MS, MARK_MS, MEDIA, matches, useMedia), which it now uses. Ships motion.ts (EASE, lessMotion, roleTiming, useLessMotion), which it now uses. popover.tsx now exports PartOfWhole, PartOfWholeProps. Ships portal.ts (useStagePlacement), which it now uses.
v1.0.0 · 2026-11-09
Released free with the Notchset system.