# Knobs (Notchset): prompt.md (v2.0.0)

- id: `knobs` · version 2.0.0 · component · free
- category: Inputs
- build: one set of files for every shadcn style
- install: `npx shadcn@latest add https://notchset.dev/r/knobs.json`
- npm dependencies: lucide-react@^1
- registry dependencies: utils, https://notchset.dev/r/notchset-foundation.json
- docs: https://notchset.dev/components/knobs
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

One Tune control, closed by default, that opens labelled sliders (each with its value written) or a choice of a few words for a showcase piece's physics (Tension, Damping), and the ghost cursor that acts a moment out while the piece plays. Keys move every knob..

## Build it
- Stack: React 18.3 or 19, TypeScript, Tailwind CSS v4 utility classes on the foundation's roles, a components.json (imports use its aliases).
- Packages: `lucide-react@^1`.
- Files: `components/ui/notchset/knobs.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `GhostCursor`, `Knobs`, and every exported type.
- CSS: the install adds the notchset foundation (its roles, keyframes and motion switch, reading your shadcn tokens for colour) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- This item reads `--ns-bezel`, `--ns-control-sm`, `--ns-ease`, `--ns-font-mono`, `--ns-hover`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-line-soft`, `--ns-panel`, `--ns-radius`, `--ns-raised`, `--ns-signal`, `--ns-text-meta`, `--ns-text-small`, `--ns-time-color`, `--ns-time-dialog`, `--ns-time-menu`, `--ns-well`.
- Retune it (on any ancestor) with the foundation's roles and hooks: `--ns-bad`, `--ns-bad-ink`, `--ns-band`, `--ns-band-edge`, `--ns-band-grade`, `--ns-band-optimal`, `--ns-beat`, `--ns-bezel`, `--ns-canvas`, `--ns-cat-1`, `--ns-cat-2`, `--ns-cat-3`, `--ns-cat-4`, `--ns-cat-5`, `--ns-cat-6`, `--ns-check`, `--ns-chip`, `--ns-control`, `--ns-control-pad`, `--ns-control-sm`, `--ns-deep`, `--ns-deep-ink`, `--ns-deep-ink-2`, `--ns-deep-line`, `--ns-dialog`, `--ns-dialog-lg`, `--ns-dialog-sm`, `--ns-ease`, `--ns-ease-in`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-field`, `--ns-flood-arc`, `--ns-flood-aurora`, `--ns-flood-behind-1`, `--ns-flood-behind-2`, `--ns-flood-bloom`, `--ns-flood-deep`, `--ns-flood-dial-bloom`, `--ns-flood-glass`, `--ns-flood-grain`, `--ns-flood-image`, `--ns-flood-ink`, `--ns-flood-ink-low`, `--ns-flood-light`, `--ns-flood-mid`, `--ns-flood-pale`, `--ns-flood-pane`, `--ns-flood-pane-edge`, `--ns-flood-pill-ink`, `--ns-flood-ribbon`, `--ns-flood-ribbon-core`, `--ns-flood-shadow`, `--ns-flood-sheen`, `--ns-flood-wash`, `--ns-font-body`, `--ns-font-display`, `--ns-font-mono`, `--ns-font-script`, `--ns-glass`, `--ns-glass-blur`, `--ns-glass-shadow`, `--ns-glow`, `--ns-grain`, `--ns-gutter`, `--ns-header`, `--ns-heat`, `--ns-hover`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-ink-4`, `--ns-leading`, `--ns-lift`, `--ns-light-1`, `--ns-light-2`, `--ns-light-3`, `--ns-light-spread`, `--ns-light-strength`, `--ns-line`, `--ns-line-soft`, `--ns-lit-edge`, `--ns-menu-dy`, `--ns-menu-row`, `--ns-mesh`, `--ns-mesh-frost`, `--ns-ok`, `--ns-ok-ink`, `--ns-orb-body`, `--ns-orb-cool`, `--ns-orb-core`, `--ns-orb-dawn`, `--ns-orb-deep`, `--ns-orb-edge`, `--ns-orb-grain`, `--ns-orb-ground`, `--ns-orb-halo`, `--ns-orb-inner`, `--ns-orb-key`, `--ns-orb-lift`, `--ns-orb-limb`, `--ns-orb-limb-from`, `--ns-orb-rim`, `--ns-orb-skin-hi`, `--ns-orb-skin-lo`, `--ns-orb-skin-mid`, `--ns-orb-warm`, `--ns-panel`, `--ns-panel-w`, `--ns-prism-edge`, `--ns-prism-glint`, `--ns-prism-sheen`, `--ns-prism-tint`, `--ns-pulse`, `--ns-radius`, `--ns-radius-card`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-sm`, `--ns-radius-xl`, `--ns-raised`, `--ns-range`, `--ns-row`, `--ns-row-compact`, `--ns-segment`, `--ns-selected`, `--ns-series`, `--ns-series-core`, `--ns-series-lilac`, `--ns-series-tint`, `--ns-shadow-dialog`, `--ns-shadow-float`, `--ns-shadow-panel`, `--ns-sheet`, `--ns-sheet-bottom`, `--ns-side`, `--ns-signal`, `--ns-sleep-awake`, `--ns-sleep-deep`, `--ns-sleep-light`, `--ns-sleep-rem`, `--ns-space-1`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-5`, `--ns-space-6`, `--ns-space-8`, `--ns-space-section`, `--ns-stack-on`, `--ns-standing-critical`, `--ns-standing-in`, `--ns-standing-out`, `--ns-state-doing`, `--ns-state-done`, `--ns-state-review`, `--ns-state-todo`, `--ns-switch-h`, `--ns-switch-w`, `--ns-text-body`, `--ns-text-control`, `--ns-text-display`, `--ns-text-figure`, `--ns-text-headline`, `--ns-text-hero`, `--ns-text-lede`, `--ns-text-meta`, `--ns-text-page`, `--ns-text-record`, `--ns-text-small`, `--ns-text-strong`, `--ns-text-sub`, `--ns-text-title`, `--ns-tile-shadow`, `--ns-time-born`, `--ns-time-color`, `--ns-time-dialog`, `--ns-time-menu`, `--ns-time-page`, `--ns-time-panel`, `--ns-time-toast`, `--ns-tint`, `--ns-tint-ink`, `--ns-toast-bottom`, `--ns-toast-left`, `--ns-touch`, `--ns-tracking-display`, `--ns-tracking-headline`, `--ns-warn`, `--ns-warn-ink`, `--ns-wash-clay`, `--ns-wash-dusk`, `--ns-wash-graphite`, `--ns-wash-ink`, `--ns-wash-sage`, `--ns-wash-sand`, `--ns-weight-light`, `--ns-weight-medium`, `--ns-weight-regular`, `--ns-weight-strong`, `--ns-well`.
- Never add Tailwind colour classes inside the component.

```tsx
import { GhostCursor, Knobs } from "@/components/ui/notchset/knobs";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/knobs.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when

### Not when

## Mistakes
- Recreating the component instead of installing it

## Usage

```tsx
"use client";
import * as React from "react";
import { GhostCursor, Knobs } from "@/components/ui/notchset/knobs";

export default function KnobsDemo() {
  const [tension, setTension] = React.useState(1);
  const [damping, setDamping] = React.useState(0.4);
  const [figure, setFigure] = React.useState("Body");
  return (
    <div className="flex max-w-[520px] flex-col gap-6">
      <div className="relative h-16 rounded-[12px] bg-[var(--ns-well)]">
        <GhostCursor x={80 + tension * 120} y={32} down={damping > 0.5} />
      </div>
      <Knobs defaultOpen
        knobs={[
          { label: "Tension", value: tension, min: 0.3, max: 2, onChange: setTension },
          { label: "Damping", value: damping, min: 0, max: 1, onChange: setDamping },
          { label: "Figure", value: figure, options: ["Body", "Plant", "None"], onChange: setFigure },
        ]}
      />
    </div>
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `knobs` | `Knob[]` |  | Required. |
| `defaultOpen` | `boolean` | `false` | open at first; closed by default behind one Tune control, so the piece is the object, not its sliders |

Full docs: https://notchset.dev/components/knobs

## Customising
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- Dark mode follows the `.dark` class or `data-theme="dark"` on an ancestor (the shadcn and next-themes conventions).
- Update later: Commit or stash local changes first (or copy the files), so the update can be undone. Read https://notchset.dev/r/changelog.json for the new versions: a major version, an entry marked breaking or a merge says what to change. Then re-run the install with `--overwrite`, on a branch. It replaces the component's files, the shared helper files they import, and the item's CSS rules in the global stylesheet, so review the whole diff (components, shared files, CSS), re-apply your own edits, and run the app's typecheck, tests and build.

## Accessibility contract (preserve when editing)

## Install

```bash
npx shadcn@latest add https://notchset.dev/r/knobs.json
```

Or add the `@notchset` registry to components.json and run `npx shadcn@latest add @notchset/knobs`. Every components.json style gets the same files.

## Continue the workflow

- [Card](https://notchset.dev/components/card)
- [Hover momentum](https://notchset.dev/components/hover-momentum)
- [Line figure](https://notchset.dev/components/line-figure)

## Source

### components/ui/notchset/knobs.tsx

```tsx
// Notchset knobs 2.0.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { SlidersHorizontal } from "lucide-react";
import { cn } from "@/lib/utils";

/*
 * Knobs and the ghost cursor: what a showcase piece is played with (SHOWCASE-RULES.md, "Knobs" and "It plays itself,
 * then hands over"). Knobs is one Tune control, closed by default, that opens a row of two to four labelled sliders for a piece's physics (Tension, Damping), each with
 * its value written; a knob may also be a choice of a few words. GhostCursor is the hand that acts the moment out
 * while a piece plays itself: a pointer drawn at a spot of the stage, pressed or not, hidden from screen readers.
 *
 *   <Knobs knobs={[{ label: "Tension", value: t, min: 0.2, max: 2, onChange: setT }, { label: "Figure", value: f, options: ["Body", "Plant", "None"], onChange: setF }]} />
 */
type SliderKnob = { label: string; value: number; min?: number | undefined; max?: number | undefined; step?: number | undefined; onChange: (v: number) => void; format?: ((v: number) => string) | undefined };
type ChoiceKnob = { label: string; value: string; options: string[]; onChange: (v: string) => void };
type Knob = SliderKnob | ChoiceKnob;
type KnobsProps = {
  knobs: Knob[];
  /** open at first; closed by default behind one Tune control, so the piece is the object, not its sliders */
  defaultOpen?: boolean | undefined;
  className?: string | undefined;
};

function Slider({ k }: { k: SliderKnob }) {
  const id = React.useId();
  const min = k.min ?? 0, max = k.max ?? 1;
  return (
    <div className="flex min-w-0 flex-col gap-1">
      <label htmlFor={id} className="flex items-baseline justify-between gap-2 text-[length:var(--ns-text-meta)] text-[var(--ns-ink-2)]">
        {k.label}
        <span className="font-[family-name:var(--ns-font-mono)] text-[var(--ns-ink-3)] tabular-nums">{k.format ? k.format(k.value) : k.value.toFixed(2)}</span>
      </label>
      <input
        id={id}
        type="range"
        min={min}
        max={max}
        step={k.step ?? (max - min) / 100}
        value={k.value}
        onChange={(e) => k.onChange(Number(e.target.value))}
        className="h-[var(--ns-control-sm)] w-full cursor-pointer accent-[var(--ns-signal)] outline-hidden focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ns-signal)]"
      />
    </div>
  );
}

function Choice({ k }: { k: ChoiceKnob }) {
  const id = React.useId();
  return (
    <div className="flex min-w-0 flex-col gap-1">
      <span id={id} className="text-[length:var(--ns-text-meta)] text-[var(--ns-ink-2)]">
        {k.label}
      </span>
      <div role="radiogroup" aria-labelledby={id} className="flex h-[var(--ns-control-sm)] items-center gap-0.5 rounded-[var(--ns-radius)] bg-[var(--ns-well)] p-0.5 shadow-[inset_0_0_0_1px_var(--ns-line-soft)]">
        {k.options.map((o, i) => (
          <button
            key={o}
            type="button"
            role="radio"
            aria-checked={k.value === o}
            tabIndex={k.value === o ? 0 : -1}
            onClick={() => k.onChange(o)}
            onKeyDown={(e) => {
              const d = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
              if (!d || e.nativeEvent.isComposing) return;
              e.preventDefault();
              const next = k.options[(i + d + k.options.length) % k.options.length]!;
              k.onChange(next);
              (e.currentTarget.parentElement?.children[(i + d + k.options.length) % k.options.length] as HTMLElement | undefined)?.focus();
            }}
            className="h-full min-w-0 flex-1 cursor-pointer truncate rounded-[calc(var(--ns-radius)-2px)] px-2 text-[length:var(--ns-text-meta)] text-[var(--ns-ink-2)] outline-hidden [transition:background-color_var(--ns-time-color),color_var(--ns-time-color)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] aria-checked:bg-[var(--ns-raised)] aria-checked:text-[var(--ns-ink)] aria-checked:shadow-[var(--ns-bezel)]"
          >
            {o}
          </button>
        ))}
      </div>
    </div>
  );
}

function Knobs({ knobs, defaultOpen = false, className }: KnobsProps) {
  const [open, setOpen] = React.useState(defaultOpen);
  const id = React.useId();
  return (
    <div data-slot="knobs" data-open={open || undefined} className={cn("flex w-full flex-col gap-3", className)}>
      <button
        type="button"
        aria-expanded={open}
        aria-controls={id}
        onClick={() => setOpen(!open)}
        className="inline-flex h-[var(--ns-control-sm)] cursor-pointer items-center gap-1.5 self-start rounded-[var(--ns-radius)] px-2 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)] outline-hidden [transition:background-color_var(--ns-time-color),color_var(--ns-time-color)] hover:bg-[var(--ns-hover)] hover:text-[var(--ns-ink)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] aria-expanded:text-[var(--ns-ink)]"
      >
        <SlidersHorizontal aria-hidden className="size-3.5" strokeWidth={1.75} />
        {open ? "Done tuning" : "Tune"}
      </button>
      {open && (
        <div id={id} data-ns-moves="" className={cn("grid w-full gap-x-5 gap-y-3 [animation:ns-fade_var(--ns-time-menu)_var(--ns-ease)]", knobs.length > 2 ? "grid-cols-3 max-[600px]:grid-cols-2" : "grid-cols-2")}>
          {knobs.map((k) => ("options" in k ? <Choice key={k.label} k={k} /> : <Slider key={k.label} k={k} />))}
        </div>
      )}
    </div>
  );
}

/** The hand that acts a moment out: drawn at (x, y) in pixels of its positioned parent, pressed or not. */
function GhostCursor({ x, y, down, hidden }: { x: number; y: number; down?: boolean | undefined; hidden?: boolean | undefined }) {
  return (
    <span
      aria-hidden
      data-slot="ghost-cursor"
      className="pointer-events-none absolute top-0 left-0 z-[5] block [transition:opacity_var(--ns-time-dialog)]"
      style={{ transform: `translate3d(${x.toFixed(1)}px,${y.toFixed(1)}px,0)`, opacity: hidden ? 0 : 1 }}
    >
      <span className="absolute top-0 left-0 block size-7 -translate-x-1/2 -translate-y-1/2 rounded-full bg-[color-mix(in_oklab,var(--ns-ink)_14%,transparent)] [transition:scale_120ms_var(--ns-ease),opacity_120ms]" style={{ scale: down ? "1" : "0.4", opacity: down ? 1 : 0 }} />
      <svg width="20" height="22" viewBox="0 0 20 22" className="relative -translate-x-[2px] -translate-y-[2px] drop-shadow-[0_2px_3px_rgb(0_0_0/0.28)]" style={{ scale: down ? "0.92" : "1", transition: "scale 120ms var(--ns-ease)" }}>
        <path d="M2.5 1.8 L2.5 17.2 L6.6 13.4 L9.3 19.6 L12.2 18.3 L9.5 12.3 L15.2 12.1 Z" fill="var(--ns-panel)" stroke="var(--ns-ink)" strokeWidth="1.4" strokeLinejoin="round" />
      </svg>
    </span>
  );
}

export { GhostCursor, Knobs, type Knob, type KnobsProps };
```

The foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://notchset.dev/r/notchset-foundation.json.
