Names a control and its key, grown from the trigger
S saves it; hover or focus it to see its name; Esc closes it
pnpm dlx shadcn@latest add https://notchset.dev/r/tooltip.jsonA label for something with no words of its own.
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 { Bookmark } from "@/lib/notchset/icons";
import { IconButton } from "@/components/ui/notchset/icon-button";
import { useLessMotion } from "@/lib/notchset/motion";
import { Tooltip, TooltipProvider } from "@/components/ui/notchset/tooltip";
import { useSelfPlay } from "./self-play";
/*
* The tooltip as itself: one bookmark alone, shown enlarged. It opens once on its trigger when first seen and folds
* back, so the stage rests closed. Hover or focus it and the tip grows from the button, "Save for later S"; S
* anywhere over the stage (or with focus in it, never in a field) sinks the cap, the bookmark fills, and the tip's
* words become "Remove from saved". Esc closes the tip.
*/
const WORDS = { save: "Save for later", remove: "Remove from saved" };
export default function TooltipDemo() {
const words = WORDS;
const [saved, setSaved] = React.useState(false);
const [open, setOpen] = React.useState(false);
const here = React.useRef<HTMLDivElement>(null);
const [moved, setMoved] = React.useState(false);
const less = useLessMotion();
/* the arrival: the tip opens once on its trigger, then folds; the stage rests closed */
const play = useSelfPlay(here, { beats: [400, 1800], off: less });
const shown = open || (!play.mine && play.taken === 1);
/* the stage's key: S while the pointer is over the stage or focus is inside it */
React.useEffect(() => {
const area = here.current?.closest<HTMLElement>("[data-ns-stage-layer]") ?? here.current;
if (!area) return;
const onKey = (e: KeyboardEvent) => {
if (e.key.toLowerCase() !== "s" || e.metaKey || e.ctrlKey || e.altKey || e.repeat) return;
const t = document.activeElement;
if (t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
if (!area.matches(":hover") && !area.contains(t)) return;
e.preventDefault();
setMoved(true);
setSaved((v) => !v);
};
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
}, []);
const name = saved ? words.remove : words.save;
return (
<TooltipProvider>
<div ref={here} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} onPointerEnter={play.handOver} className="flex flex-col items-center">
<Tooltip label={name} shortcut="S" stayOnKey open={shown} onOpenChange={setOpen}>
<IconButton tooltip={false} label={name} shortcut="S" intent="secondary" aria-pressed={saved} onClick={() => (setMoved(true), setSaved((v) => !v))}>
{/* the bookmark fills ink with a pop as it changes (never on arrival) */}
<Bookmark key={String(saved)} fill={saved ? "currentColor" : "none"} className={moved ? "[animation:ns-pop_360ms_var(--ns-ease-arrive)]" : undefined} />
</IconButton>
</Tooltip>
</div>
</TooltipProvider>
);
}"use client";
import * as React from "react";
import { Bookmark } from "@/lib/notchset/icons";
import { IconButton } from "@/components/ui/notchset/icon-button";
import { useLessMotion } from "@/lib/notchset/motion";
import { Tooltip, TooltipProvider } from "@/components/ui/notchset/tooltip";
import { useSelfPlay } from "./self-play";
/*
* The tooltip as itself: one bookmark alone, shown enlarged. It opens once on its trigger when first seen and folds
* back, so the stage rests closed. Hover or focus it and the tip grows from the button, "Save for later S"; S
* anywhere over the stage (or with focus in it, never in a field) sinks the cap, the bookmark fills, and the tip's
* words become "Remove from saved". Esc closes the tip.
*/
const WORDS = { save: "Save for later", remove: "Remove from saved" };
export default function TooltipDemo() {
const words = WORDS;
const [saved, setSaved] = React.useState(false);
const [open, setOpen] = React.useState(false);
const here = React.useRef<HTMLDivElement>(null);
const [moved, setMoved] = React.useState(false);
const less = useLessMotion();
/* the arrival: the tip opens once on its trigger, then folds; the stage rests closed */
const play = useSelfPlay(here, { beats: [400, 1800], off: less });
const shown = open || (!play.mine && play.taken === 1);
/* the stage's key: S while the pointer is over the stage or focus is inside it */
React.useEffect(() => {
const area = here.current?.closest<HTMLElement>("[data-ns-stage-layer]") ?? here.current;
if (!area) return;
const onKey = (e: KeyboardEvent) => {
if (e.key.toLowerCase() !== "s" || e.metaKey || e.ctrlKey || e.altKey || e.repeat) return;
const t = document.activeElement;
if (t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
if (!area.matches(":hover") && !area.contains(t)) return;
e.preventDefault();
setMoved(true);
setSaved((v) => !v);
};
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
}, []);
const name = saved ? words.remove : words.save;
return (
<TooltipProvider>
<div ref={here} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} onPointerEnter={play.handOver} className="flex flex-col items-center">
<Tooltip label={name} shortcut="S" stayOnKey open={shown} onOpenChange={setOpen}>
<IconButton tooltip={false} label={name} shortcut="S" intent="secondary" aria-pressed={saved} onClick={() => (setMoved(true), setSaved((v) => !v))}>
{/* the bookmark fills ink with a pop as it changes (never on arrival) */}
<Bookmark key={String(saved)} fill={saved ? "currentColor" : "none"} className={moved ? "[animation:ns-pop_360ms_var(--ns-ease-arrive)]" : undefined} />
</IconButton>
</Tooltip>
</div>
</TooltipProvider>
);
}"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. This command installs them with it, so the example pastes as it is:
pnpm dlx shadcn@latest add https://notchset.dev/r/tooltip.json https://notchset.dev/r/icon-button.jsoncomponents/ui/notchset/tooltip.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.
label–
React.ReactNodeRequired.
shortcut–
ShortcutThe key that does the same ("S", "⌘K", { keys: "G", then: "P" }).
side"top"
"top" | "bottom" | "inline-start" | "inline-end"align"center"
"start" | "center" | "end"truncated–
booleanOpen only while the trigger's text is cut off.
open–
booleandefaultOpen–
booleanonOpenChange–
(open: boolean) => voidlabels–
Partial<KeyCapLabels>stayOnKey–
booleanIts key changes what the tip says (a toggle): key up lifts the cap and the tip stays until leave, Esc or press.
disabled–
booleanShows nothing; the trigger stays mounted.
Three usesa toolbar's icon buttons · a truncated name's full words · a chart mark's readout
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)v1.2.0 · 2026-11-17
New props: stayOnKey. Ships portal.ts (useStagePlacement), which it now uses.
v1.1.0 · 2026-11-11
disabled: the tip shows nothing while its trigger stays mounted. Hover-out closes the tip at once, and a shortcut with ⌘ ("⌘B") sinks its caps while it runs.
v1.0.0 · 2026-11-09
Released free with the Notchset system.