videorc/ui

Power Slider

A labelled slider for one engine setting. The value with its unit or a typed number, a reset to the default, marks under the track, and a live preview apart from the commit.

Beta
60%
0%100%

Installation

$ pnpm dlx shadcn@latest add @videorc/power-slider

It installs lib/power-slider-math.ts, the value math, beside the component.

Usage

import { PowerSlider } from "@/components/power-slider";
<PowerSlider
  defaultValue={40}
  label="Noise cleanup"
  max={100}
  min={0}
  onChange={setPreview}
  onCommit={saveNoiseCleanup}
  suffix="%"
  value={value}
/>

onChange is the live preview, fired while dragging and on every key: keep it cheap. onCommit fires on release, on a key, on reset and on a typed number, so write the expensive update (the engine, a saved setting) there and a drag can't flood it. Without onCommit, onChange does both.

Use it for a setting with a range, a unit and a default: noise cleanup, gain, exposure, delays. Use a plain Slider for a scrubber or a level with no label row. Don't ship a slider with nothing behind it.

Examples

Bipolar, with marks

bipolar signs positive values ("+0.5 EV"). marks puts labelled points under the track; rangeHints puts the ends there instead (and the middle, when bipolar).

+0.5 EV
DarkerAutoBrighter

Typed numbers and disabled

numericInput replaces the readout with a field: Enter or leaving the field commits, clamped and snapped to the step; Esc drops the draft. A disabled slider says why under the track, and status adds a chip after the label.

Saved: 120 ms. The live value follows the drag; the saved one changes on release.

No microphone
0 dB

Turn on a microphone to adjust its gain.

The value math

lib/power-slider-math.ts is pure and framework-free, so the exact clamping, stepping and formatting the slider relies on is tested directly.

FunctionWhat it does
clampToRange(value, range)Clamps into the range and snaps to the step grid from min, without floating-point drift. NaN reads as min
stepValue(value, range, direction, { large?, largeStep? })One keyboard move; the large one is 10 steps unless given
parseNumericInput(raw, range)A typed number, clamped and snapped, or null for blank and non-numeric input
formatValue(value, { suffix?, decimals?, bipolar?, step? })The readout, with decimals from the step and a "+" on a positive bipolar value
valuePercent(value, range)Where a value sits along the track, 0 to 100

Theming

Token or attributeMeaning
chrome-fill, chrome-beadThe range and the thumb, from Slider
text-labelThe marks under the track
--markEach mark's place along the track
data-slot="power-slider"The whole control

Keyboard

KeyAction
← → ↑ ↓Moves by one step
Shift + arrow, Page Up Page DownMoves by largeStep
Home EndGoes to min or max

A double-click on the track resets to defaultValue; the reset button is the keyboard way.

Accessibility

The thumb is named by the label. The reset button is named Reset {label} and the typed field {label} value. A disabled slider's reason is visible text under it.

API reference

Prop

Type