audio/ui
Toggle Mode D
Audio UI
Copy Registry URL
A numeric field for an audio parameter: a tempo, a gain, a transpose, a cutoff, a pan, a velocity. It reads as a DAW's does, the name at its start, the value in monospace figures, the unit after it, and every way in a DAW to change it.
Overview
- Typing: type a value and press Enter, or leave the field. What is typed stays in the field until it is committed, so a half-typed number never reaches
onValueChange. - Stepping: the arrow keys step by
step, with Shift bylargeStepand with Alt bysmallStep; the Page keys bylargeStep; Home and End go tominandmax.steppersadds a minus and a plus either side. The wheel never changes the value. - Scrubbing: drag the label or the unit sideways (
scrub="horizontal", right is more) or up and down ("vertical", up is more), one step everyscrubSensitivitypixels; hold Shift for large steps, Alt for small ones. The pointer is hidden while it drags, so it can go on past the screen's edge. - Display:
precisiondigits after the point (as many asstephas by default, or asformatsays when it is given), andformatfor the rest, such as a sign (signDisplay) or a percent. Figures are not grouped (1200 Hz, not 1,200 Hz) unlessformatsays so.
Installation
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/parameter-field
Usage
Copy to Clipboardimport { ParameterField } from "@/components/audio-ui/parameter-field";
Uncontrolled: set only the initial value.
Copy to Clipboard<ParameterField defaultValue={-6} label="Gain" max={24} min={-36} precision={1} step={0.1} unit="dB" />
Controlled: drive the value from state, and close an undo step when a gesture ends.
Copy to Clipboardconst [bpm, setBpm] = useState(120); <ParameterField label="Tempo" max={999} min={20} onValueChange={setBpm} onValueCommitted={commitTempo} precision={2} steppers unit="BPM" value={bpm} />
Dense: size="sm" for a panel of many, and hideLabel where the label sits elsewhere; the label still names the field.
Copy to Clipboard<ParameterField hideLabel label="Transpose" scrub="vertical" size="sm" unit="st" />
Text of its own: formatValue and parseValue write the value as text and read typed text back, such as a position in bars.beats.16ths, with the same look, keys and scrubbing. shortLabel shows a shorter word than the accessible name.
Copy to Clipboard<ParameterField formatValue={(seconds) => formatBars(seconds, meter, "position")} label="Clip start" onValueChange={setStart} parseValue={(text) => parseBars(text, meter, "position")} shortLabel="Start" size="sm" step={sixteenth} value={start} />
API reference
Props · 19
Names the field, shown at its start unless
hideLabel: drag it to scrub.The value, when it is held outside, and every change, as a scrub or a step goes; a typed value once it is committed.
The value it starts at, when it keeps its own value.
A gesture that changed the value ended: a scrub let go, a step, a typed value committed.
The range of the value.
The step of the arrow keys, the steppers and a scrub.
The step of Shift, the Page keys, and a scrub with Shift held.
The step of Alt, and of a scrub with Alt held.
Digits after the point. With
format, as many as it says unless precision is given too.How the value is shown and read back, past
precision: a sign, a percent, grouping (off by default).The unit after the value, such as "dB", "Hz" or "BPM": drag it to scrub.
Which way a drag on the label or the unit moves the value: sideways (right is more) or up and down (up is more).
false for no scrubbing.Pixels of drag per step when scrubbing.
Adds a decrement and an increment button either side, named "Decrease" and "Increase" and the label, or by
decrement and increment, with icons in place of the minus and the plus, as a zoom's magnifiers."sm" for a dense panel.
What the field shows at its start, when the label is longer than the room: "Start" for "Clip start".
Write the value as text of its own and read typed text back: the field keeps the same look, keys and scrubbing, and
format, precision and steppers are left aside. null keeps the value as it was.Keeps the label out of sight: it still names the field.
Takes no input, and does not scrub.