videorc/ui

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.

Microphone
−6.0 dB

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, not bg-primary.
  • The default thumb is a chrome-bead on 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 on rounded-row.

Installation

$ pnpm dlx shadcn@latest add @videorc/fader

The 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:

components.json
{
  "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.

Microphone gain

Console faders

Vertical faders with variant="console" and taper="audio", which gives more travel around 0 dB, like a mixing console.

0.0 dB
Mic
−12.0 dB
System
−18.0 dB
Camera

Theming

Token or attributeMeaning
chrome-fillThe range
bg-input/90The track
chrome-beadThe default thumb
ring-knob-ringThe default thumb's hairline rim; a 4 px ring on hover, focus and drag
rounded-chipThe console thumb's cap
rounded-rowThe value, its editor and Reset
--fader-track-size, --fader-thumb-sizeSet by size
data-orientation, data-variant, data-sizeThe current settings
data-draggingThe thumb is held
data-at-detentThe value sits on a detent
data-silentThe value is -Infinity
data-disabledDims to 50%
data-slotfader, fader-label, fader-control, fader-track, fader-range, fader-thumb, fader-scale, fader-value, fader-value-input, fader-reset

Keyboard

KeyAction
← → ↑ ↓Changes the value by step
Shift with an arrow, Page Up Page DownChanges it by largeStep
Alt with an arrowChanges it by fineStep
Home EndMoves 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.