Fader
audiocn's volume fader in decibels, restyled for Videorc. The range is the chrome fill and the thumb a chrome bead, with tapers, detents, a scale, reset and an editable value.
This is a fork of audiocn's Fader (MIT). Its behaviour, parts and props are upstream's; only the paint differs:
- The range is
chrome-fill, notbg-primary. - The default thumb is a
chrome-beadon the knob's hairline rim (ring-knob-ring), like every Videorc slider. - The console thumb's cap is
rounded-chip, and the value, its editor and Reset sit onrounded-row.
Installation
$ pnpm dlx shadcn@latest add @videorc/faderThe fader builds on audiocn's core (@audiocn/core, @audiocn/use-audio-config and @audiocn/db-scale), so add the @audiocn namespace to components.json as well:
{
"registries": {
"@videorc": "https://ui.videorc.com/r/{name}.json",
"@audiocn": "https://audiocn.dev/r/{name}.json"
}
}Usage
import {
Fader,
FaderLabel,
FaderRange,
FaderThumb,
FaderTrack,
FaderValue,
} from "@/components/ui/fader";const [volumeDb, setVolumeDb] = useState(0);
<Fader onValueChange={setVolumeDb} value={volumeDb}>
<FaderLabel>Microphone</FaderLabel>
<FaderValue />
<FaderTrack>
<FaderRange />
<FaderThumb />
</FaderTrack>
</Fader>;The value is always in dB. The taper decides where each value sits on the travel. The thumb snaps to its detents (0 dB by default) while dragging, and double-clicking it resets.
Anatomy
<Fader>
<FaderLabel />
<FaderReset />
<FaderValue />
<FaderTrack>
<FaderRange />
<FaderThumb />
</FaderTrack>
<FaderScale />
</Fader>FaderTrack takes any children, so a level meter can sit inside it.
Examples
Bipolar gain
Videorc's Gain faders: origin={0} grows the fill from the middle, whole-dB steps, a detent at 0 dB and a value you can type into.
Console faders
Vertical faders with variant="console" and taper="audio", which gives more travel around 0 dB, like a mixing console.
Theming
| Token or attribute | Meaning |
|---|---|
chrome-fill | The range |
bg-input/90 | The track |
chrome-bead | The default thumb |
ring-knob-ring | The default thumb's hairline rim; a 4 px ring on hover, focus and drag |
rounded-chip | The console thumb's cap |
rounded-row | The value, its editor and Reset |
--fader-track-size, --fader-thumb-size | Set by size |
data-orientation, data-variant, data-size | The current settings |
data-dragging | The thumb is held |
data-at-detent | The value sits on a detent |
data-silent | The value is -Infinity |
data-disabled | Dims to 50% |
data-slot | fader, fader-label, fader-control, fader-track, fader-range, fader-thumb, fader-scale, fader-value, fader-value-input, fader-reset |
Keyboard
| Key | Action |
|---|---|
| ← → ↑ ↓ | Changes the value by step |
| Shift with an arrow, Page Up Page Down | Changes it by largeStep |
| Alt with an arrow | Changes it by fineStep |
| Home End | Moves to the minimum (or silence) or the maximum |
Holding Alt while dragging uses fineStep too.
Accessibility
The thumb holds a native range input with role="slider", and its aria-valuetext is the formatted value, such as "−6.0 dB" or "Silent". Name the fader with FaderLabel or aria-label. The editable value's input is named "Value in dB".
API reference
Fader
Every Base UI Slider root prop, plus:
Prop
Type
FaderValue
The value is as wide as the longest text the fader's range can show, and right-aligned, so moving the fader never shifts the layout. The editor opens at the same width.
Prop
Type
FaderScale
Takes audiocn's DbScale props. The range, taper and orientation come from the fader.