A folding line for showing a reply's thinking and duration
Enter opens the thoughts · R thinks again
pnpm dlx shadcn@latest add https://notchset.dev/r/thinking-fold.jsonA reply's thinking, folded: one live line, then "Thought for 7 s".
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 { useLessMotion } from "@/lib/notchset/motion";
import { ThinkingFold } from "@/components/ui/notchset/thinking-fold";
import { PlayOnce, useSelfPlay } from "./self-play";
/*
* The fold alone, over the answer it folds above. On view it thinks once: "Thinking 4 s" counts while the thoughts
* arrive one line at a time, then it settles in place to "Thought for 7 s" and the answer rises in under it. The hand
* opens it; R thinks again. With "Next one stops" on, that next one stops mid-thought: it keeps what it had and says
* where it stopped.
*/
const LINES = [
"Lisbon is on UTC+0 in November, New York on UTC−5 and Tokyo on UTC+9.",
"A 9:00 start in New York is 14:00 in Lisbon and 23:00 in Tokyo: too late there.",
"8:00 in New York is 13:00 in Lisbon and 22:00 in Tokyo, the latest a call there should run.",
];
const ANSWER = "Start at 8:00 in New York: it is 13:00 in Lisbon and 22:00 in Tokyo, inside everyone's day.";
const clock = () => Date.now();
type Run = { phase: "live" | "done" | "stopped"; n: number; began: number; ms: number };
const END: Run = { phase: "done", n: LINES.length, began: 0, ms: 7000 };
export default function ThinkingFoldDemo() {
const stops = false as boolean;
const root = React.useRef<HTMLDivElement>(null);
const less = useLessMotion();
const settle = Boolean(React.useContext(PlayOnce)?.settle);
const play = useSelfPlay(root, { beats: [0], off: less });
const [run, setRun] = React.useState<Run>(END);
const timers = React.useRef<number[]>([]);
React.useEffect(() => () => timers.current.forEach(clearTimeout), []);
const think = React.useCallback(
(stop: boolean, instant: boolean) => {
timers.current.forEach(clearTimeout);
timers.current = [];
const began = clock() - 4000;
const at = (ms: number, f: () => void) => timers.current.push(window.setTimeout(f, ms));
if (instant) {
at(0, () => setRun(stop ? { phase: "stopped", n: 2, began, ms: 5700 } : { ...END, began }));
return;
}
at(0, () => setRun({ phase: "live", n: 1, began, ms: 0 }));
at(1000, () => setRun((r) => ({ ...r, n: 2 })));
if (stop) {
at(1700, () => setRun((r) => ({ ...r, phase: "stopped", ms: 5700 })));
return;
}
at(2000, () => setRun((r) => ({ ...r, n: 3 })));
at(3100, () => setRun((r) => ({ ...r, phase: "done", ms: 7000 })));
},
[],
);
/* the arrival: one think, or its end at once */
const step = play.step;
React.useEffect(() => {
if (step === 0) think(false, less || settle);
}, [step, think, less, settle]);
const live = run.phase === "live";
const text = LINES.slice(0, run.n).join("\n");
return (
<div
ref={root}
onPointerDownCapture={play.handOver}
onKeyDownCapture={play.handOver}
onKeyDown={(e) => {
if (e.key !== "r" && e.key !== "R") return;
if (e.metaKey || e.ctrlKey || e.altKey) return;
e.preventDefault();
think(stops, less);
}}
className="flex w-[min(100%,520px)] flex-col gap-2"
>
<ThinkingFold
key={run.began}
part={{ type: "reasoning", text, state: live ? "streaming" : "done", ...(run.phase === "done" ? { durationMs: run.ms } : {}) }}
startedAt={run.phase === "live" ? run.began : undefined}
interrupted={run.phase === "stopped"}
stoppedNote="Stopped by you, before it found a time"
labels={run.phase === "stopped" ? { stoppedNoTime: `Stopped thinking at ${Math.round(run.ms / 1000)} s` } : undefined}
/>
<p className="m-0 min-h-[3lh] text-[length:var(--ns-text-body)] leading-[var(--ns-leading-prose)] text-[var(--ns-ink)]">
{run.phase === "done" ? (
<span key={run.began} className="block [animation:ns-rise_var(--ns-time-page)_var(--ns-ease)_both]">
{ANSWER}
</span>
) : run.phase === "stopped" ? (
<span className="text-[var(--ns-ink-3)]">You stopped this reply.</span>
) : null}
</p>
</div>
);
}"use client";
import * as React from "react";
import { useLessMotion } from "@/lib/notchset/motion";
import { ThinkingFold } from "@/components/ui/notchset/thinking-fold";
import { PlayOnce, useSelfPlay } from "./self-play";
/*
* The fold alone, over the answer it folds above. On view it thinks once: "Thinking 4 s" counts while the thoughts
* arrive one line at a time, then it settles in place to "Thought for 7 s" and the answer rises in under it. The hand
* opens it; R thinks again. With "Next one stops" on, that next one stops mid-thought: it keeps what it had and says
* where it stopped.
*/
const LINES = [
"Lisbon is on UTC+0 in November, New York on UTC−5 and Tokyo on UTC+9.",
"A 9:00 start in New York is 14:00 in Lisbon and 23:00 in Tokyo: too late there.",
"8:00 in New York is 13:00 in Lisbon and 22:00 in Tokyo, the latest a call there should run.",
];
const ANSWER = "Start at 8:00 in New York: it is 13:00 in Lisbon and 22:00 in Tokyo, inside everyone's day.";
const clock = () => Date.now();
type Run = { phase: "live" | "done" | "stopped"; n: number; began: number; ms: number };
const END: Run = { phase: "done", n: LINES.length, began: 0, ms: 7000 };
export default function ThinkingFoldDemo() {
const stops = false as boolean;
const root = React.useRef<HTMLDivElement>(null);
const less = useLessMotion();
const settle = Boolean(React.useContext(PlayOnce)?.settle);
const play = useSelfPlay(root, { beats: [0], off: less });
const [run, setRun] = React.useState<Run>(END);
const timers = React.useRef<number[]>([]);
React.useEffect(() => () => timers.current.forEach(clearTimeout), []);
const think = React.useCallback(
(stop: boolean, instant: boolean) => {
timers.current.forEach(clearTimeout);
timers.current = [];
const began = clock() - 4000;
const at = (ms: number, f: () => void) => timers.current.push(window.setTimeout(f, ms));
if (instant) {
at(0, () => setRun(stop ? { phase: "stopped", n: 2, began, ms: 5700 } : { ...END, began }));
return;
}
at(0, () => setRun({ phase: "live", n: 1, began, ms: 0 }));
at(1000, () => setRun((r) => ({ ...r, n: 2 })));
if (stop) {
at(1700, () => setRun((r) => ({ ...r, phase: "stopped", ms: 5700 })));
return;
}
at(2000, () => setRun((r) => ({ ...r, n: 3 })));
at(3100, () => setRun((r) => ({ ...r, phase: "done", ms: 7000 })));
},
[],
);
/* the arrival: one think, or its end at once */
const step = play.step;
React.useEffect(() => {
if (step === 0) think(false, less || settle);
}, [step, think, less, settle]);
const live = run.phase === "live";
const text = LINES.slice(0, run.n).join("\n");
return (
<div
ref={root}
onPointerDownCapture={play.handOver}
onKeyDownCapture={play.handOver}
onKeyDown={(e) => {
if (e.key !== "r" && e.key !== "R") return;
if (e.metaKey || e.ctrlKey || e.altKey) return;
e.preventDefault();
think(stops, less);
}}
className="flex w-[min(100%,520px)] flex-col gap-2"
>
<ThinkingFold
key={run.began}
part={{ type: "reasoning", text, state: live ? "streaming" : "done", ...(run.phase === "done" ? { durationMs: run.ms } : {}) }}
startedAt={run.phase === "live" ? run.began : undefined}
interrupted={run.phase === "stopped"}
stoppedNote="Stopped by you, before it found a time"
labels={run.phase === "stopped" ? { stoppedNoTime: `Stopped thinking at ${Math.round(run.ms / 1000)} s` } : undefined}
/>
<p className="m-0 min-h-[3lh] text-[length:var(--ns-text-body)] leading-[var(--ns-leading-prose)] text-[var(--ns-ink)]">
{run.phase === "done" ? (
<span key={run.began} className="block [animation:ns-rise_var(--ns-time-page)_var(--ns-ease)_both]">
{ANSWER}
</span>
) : run.phase === "stopped" ? (
<span className="text-[var(--ns-ink-3)]">You stopped this reply.</span>
) : null}
</p>
</div>
);
}"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 };components/ui/notchset/thinking-fold.tsx
LevelMolecule: made of atoms only.
Made ofLive label
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 lucide-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.
onFeedback–
(e: FeedbackEvent) => voidcalled once per move, for your sound or haptics
part–
ReasoningPartthe reasoning part: streaming is live, done is finished
startedAt–
numberwhen the thinking began (ms), for the live seconds
steps–
readonly ThinkingStep[]the steps it took
interruptedfalse
booleanthe reply ended mid-thought
stoppedNote–
stringwhere it stopped, under the thoughts
open–
booleanopened or folded (folded by default)
onOpenChange–
(open: boolean) => voidlabels–
Partial<ThinkingFoldLabels>Three usesan assistant's reply in a chat · a health coach's answer · a CRM question answered in a panel
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)v1.2.0 · 2026-11-17
Ships controllable.ts (useControllable, useControllableOpen), which it now uses. Ships disclosure-parts.tsx (DisclosureScope, disclosureScope, disclosureTrigger, partId, DisclosureScopeProps, OpenProps, useDisclosure), which it now uses. Internal files split; installs smaller; no change to the piece's own API.
v1.1.0 · 2026-11-17
New props: onFeedback, steps. Ships feedback.ts (FeedbackEvent, FeedbackProps), which it now uses. Ships motion.ts (EASE, lessMotion, roleTiming, useLessMotion), which it now uses. Ships stream-text-parts.tsx (StreamText, StreamTextProps), which it now uses. thinking-fold.tsx now exports ThinkingStep, ThinkingStepKind.
v1.0.0 · 2026-11-09
Released free with the Notchset system.