A colour picker card saying whether the colour still reads
← → ↑ ↓ move the knob · # types a hex · Enter keeps · Esc discards
pnpm dlx shadcn@latest add @notchset-pro/color-pickerAny colour picked by hand, that says how it reads as text.
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 { ColorPicker } from "@/components/ui/notchset/color-picker";
import { useLessMotion } from "@/lib/notchset/motion";
import { pressIn, useSelfPlay } from "./self-play";
/*
* The colour picker alone, resting open. On view the large card's knob is pressed, drawn through the blues and let go;
* then the coral recent colour is picked: the knob flies there and the chip floods. The plain card picks violet once.
* The first touch makes it yours; less motion rests on the end. The stage keeps the large card's height in both looks.
*/
const START = "#3B82D6";
const CORAL = "#EE5A3C";
const VIOLET = "#6D4FE8";
/* the drag through the blues: clearness and brightness, a smooth curve through these points */
const PATH: [number, number][] = [[0.7, 0.84], [0.82, 0.74], [0.62, 0.62], [0.74, 0.5], [0.9, 0.46]];
const DRAG = 1150;
/* one step each: show drags, lets go and 840ms later picks coral; plain picks violet */
const BEATS = { show: [2300], plain: [2300] } as const;
const THEN = 840;
function along(k: number): [number, number] {
const seg = PATH.length - 1;
const f = Math.min(1, Math.max(0, k)) * seg;
const i = Math.min(seg - 1, Math.floor(f));
const u = f - i;
const p = (j: number) => PATH[Math.min(seg, Math.max(0, j))]!;
const [a, b, c, d] = [p(i - 1), p(i), p(i + 1), p(i + 2)];
const cr = (w: number, x: number, y: number, z: number) => 0.5 * (2 * x + (-w + y) * u + (2 * w - 5 * x + 4 * y - z) * u * u + (-w + 3 * x - 3 * y + z) * u * u * u);
return [cr(a[0], b[0], c[0], d[0]), cr(a[1], b[1], c[1], d[1])];
}
/* the dragged blue, as the knob leaves it */
function draggedHex(): string {
const [s, v] = PATH.at(-1)!;
const h = 212;
const f = (n: number) => {
const k = (n + h / 60) % 6;
return Math.round(255 * (v - v * s * Math.max(0, Math.min(k, 4 - k, 1))));
};
return "#" + [f(5), f(3), f(1)].map((n) => n.toString(16).padStart(2, "0")).join("").toUpperCase();
}
/* the picker's own recent colours, coral first */
const RECENT = [
"#EE5A3C", "#FFB020", "#2FBF71", "#14B8C4",
"#6D4FE8", "#F25AA8", "#1E2A44", "#E8E2D6",
];
export default function ColorPickerDemo() {
const look = "show" as "show" | "plain";
return (
/* the large card's height at this width, in both looks, so the page never moves */
<div className="flex w-full items-center justify-center [container-type:inline-size]" style={{ minHeight: "calc(232px + (min(580px, 100cqw) - 40px) * .6)" }}>
<Picker key={look} look={look} />
</div>
);
}
function Picker({ look }: { look: "show" | "plain" }) {
const less = useLessMotion();
const root = React.useRef<HTMLDivElement>(null);
const play = useSelfPlay(root, { beats: BEATS[look], off: less });
/* less motion: the end of the moment at once */
const [value, setValue] = React.useState(less ? (look === "show" ? CORAL : VIOLET) : START);
const recent = less && look === "show" ? [draggedHex(), ...RECENT].slice(0, 8) : RECENT;
React.useEffect(() => {
if (play.mine || play.step < 0) return undefined;
if (look === "plain") return void pressIn(root.current, `[data-swatch="${VIOLET}"]`);
/* the press, the drag through the blues and the release, as a hand would do them */
const el = root.current?.querySelector<HTMLElement>("[data-slot=color-picker-area]");
if (!el || typeof PointerEvent === "undefined") return undefined;
const point = (s: number, v: number) => {
const r = el.getBoundingClientRect();
return { clientX: r.left + s * r.width, clientY: r.top + (1 - v) * r.height, pointerId: 41, bubbles: true, button: 0, isPrimary: true };
};
let raf = 0;
let later = 0;
el.dispatchEvent(new PointerEvent("pointerdown", point(PATH[0]![0], PATH[0]![1])));
const t0 = performance.now() + 140;
const step = (now: number) => {
const k = Math.min(1, Math.max(0, (now - t0) / DRAG));
const [s, v] = along(0.5 - 0.5 * Math.cos(Math.PI * k));
el.dispatchEvent(new PointerEvent("pointermove", point(s, v)));
if (k < 1) raf = requestAnimationFrame(step);
else {
el.dispatchEvent(new PointerEvent("pointerup", point(s, v)));
later = window.setTimeout(() => pressIn(root.current, `[data-swatch="${CORAL}"]`), THEN);
}
};
raf = requestAnimationFrame(step);
return () => (cancelAnimationFrame(raf), window.clearTimeout(later));
}, [play.step, play.mine, look]);
/* only a person's own touch hands it over: the script's pointer events are not trusted */
const mine = (e: React.SyntheticEvent) => e.nativeEvent.isTrusted && play.handOver();
return (
<div ref={root} className="flex max-w-full justify-center" onPointerDownCapture={mine} onKeyDownCapture={mine} onFocusCapture={mine}>
<ColorPicker look={look} value={value} onValueChange={setValue} recent={recent} />
</div>
);
}"use client";
import * as React from "react";
import { ColorPicker } from "@/components/ui/notchset/color-picker";
import { useLessMotion } from "@/lib/notchset/motion";
import { pressIn, useSelfPlay } from "./self-play";
/*
* The colour picker alone, resting open. On view the large card's knob is pressed, drawn through the blues and let go;
* then the coral recent colour is picked: the knob flies there and the chip floods. The plain card picks violet once.
* The first touch makes it yours; less motion rests on the end. The stage keeps the large card's height in both looks.
*/
const START = "#3B82D6";
const CORAL = "#EE5A3C";
const VIOLET = "#6D4FE8";
/* the drag through the blues: clearness and brightness, a smooth curve through these points */
const PATH: [number, number][] = [[0.7, 0.84], [0.82, 0.74], [0.62, 0.62], [0.74, 0.5], [0.9, 0.46]];
const DRAG = 1150;
/* one step each: show drags, lets go and 840ms later picks coral; plain picks violet */
const BEATS = { show: [2300], plain: [2300] } as const;
const THEN = 840;
function along(k: number): [number, number] {
const seg = PATH.length - 1;
const f = Math.min(1, Math.max(0, k)) * seg;
const i = Math.min(seg - 1, Math.floor(f));
const u = f - i;
const p = (j: number) => PATH[Math.min(seg, Math.max(0, j))]!;
const [a, b, c, d] = [p(i - 1), p(i), p(i + 1), p(i + 2)];
const cr = (w: number, x: number, y: number, z: number) => 0.5 * (2 * x + (-w + y) * u + (2 * w - 5 * x + 4 * y - z) * u * u + (-w + 3 * x - 3 * y + z) * u * u * u);
return [cr(a[0], b[0], c[0], d[0]), cr(a[1], b[1], c[1], d[1])];
}
/* the dragged blue, as the knob leaves it */
function draggedHex(): string {
const [s, v] = PATH.at(-1)!;
const h = 212;
const f = (n: number) => {
const k = (n + h / 60) % 6;
return Math.round(255 * (v - v * s * Math.max(0, Math.min(k, 4 - k, 1))));
};
return "#" + [f(5), f(3), f(1)].map((n) => n.toString(16).padStart(2, "0")).join("").toUpperCase();
}
/* the picker's own recent colours, coral first */
const RECENT = [
"#EE5A3C", "#FFB020", "#2FBF71", "#14B8C4",
"#6D4FE8", "#F25AA8", "#1E2A44", "#E8E2D6",
];
export default function ColorPickerDemo() {
const look = "show" as "show" | "plain";
return (
/* the large card's height at this width, in both looks, so the page never moves */
<div className="flex w-full items-center justify-center [container-type:inline-size]" style={{ minHeight: "calc(232px + (min(580px, 100cqw) - 40px) * .6)" }}>
<Picker key={look} look={look} />
</div>
);
}
function Picker({ look }: { look: "show" | "plain" }) {
const less = useLessMotion();
const root = React.useRef<HTMLDivElement>(null);
const play = useSelfPlay(root, { beats: BEATS[look], off: less });
/* less motion: the end of the moment at once */
const [value, setValue] = React.useState(less ? (look === "show" ? CORAL : VIOLET) : START);
const recent = less && look === "show" ? [draggedHex(), ...RECENT].slice(0, 8) : RECENT;
React.useEffect(() => {
if (play.mine || play.step < 0) return undefined;
if (look === "plain") return void pressIn(root.current, `[data-swatch="${VIOLET}"]`);
/* the press, the drag through the blues and the release, as a hand would do them */
const el = root.current?.querySelector<HTMLElement>("[data-slot=color-picker-area]");
if (!el || typeof PointerEvent === "undefined") return undefined;
const point = (s: number, v: number) => {
const r = el.getBoundingClientRect();
return { clientX: r.left + s * r.width, clientY: r.top + (1 - v) * r.height, pointerId: 41, bubbles: true, button: 0, isPrimary: true };
};
let raf = 0;
let later = 0;
el.dispatchEvent(new PointerEvent("pointerdown", point(PATH[0]![0], PATH[0]![1])));
const t0 = performance.now() + 140;
const step = (now: number) => {
const k = Math.min(1, Math.max(0, (now - t0) / DRAG));
const [s, v] = along(0.5 - 0.5 * Math.cos(Math.PI * k));
el.dispatchEvent(new PointerEvent("pointermove", point(s, v)));
if (k < 1) raf = requestAnimationFrame(step);
else {
el.dispatchEvent(new PointerEvent("pointerup", point(s, v)));
later = window.setTimeout(() => pressIn(root.current, `[data-swatch="${CORAL}"]`), THEN);
}
};
raf = requestAnimationFrame(step);
return () => (cancelAnimationFrame(raf), window.clearTimeout(later));
}, [play.step, play.mine, look]);
/* only a person's own touch hands it over: the script's pointer events are not trusted */
const mine = (e: React.SyntheticEvent) => e.nativeEvent.isTrusted && play.handOver();
return (
<div ref={root} className="flex max-w-full justify-center" onPointerDownCapture={mine} onKeyDownCapture={mine} onFocusCapture={mine}>
<ColorPicker look={look} value={value} onValueChange={setValue} recent={recent} />
</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/color-picker.tsx
This component is included with Pro.
Try the live preview above. Get Pro to install the source.
LevelAtom: uses no other piece.
Made ofTooltip
Needs your registry key. Every components.json style gets the same files.
Works with React 18.3 or 19 on Tailwind CSS v4, in any shadcn project. What's tested
The 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.
value–
stringThe kept colour, as the hex field shows it: #RRGGBB, or #RRGGBBAA under 100% opacity.
defaultValue–
stringonValueChange–
(value: string) => voidA colour kept: on letting go of a knob, on Enter, on a recent colour or the eyedropper.
look"plain"
"plain" | "show"plain (the form default): the compact card; show: the large card with the knob's trail, for a public page.
recentRECENT
readonly string[]The recent colours it opens with (eight at most); a kept colour joins the front.
labels–
Partial<ColorPickerLabels>Three usesa label's colour · a workspace's brand colour · a chart series' colour
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)One payment, lifetime.
v2.0.0 · 2026-10-13
Released with the Notchset system.