Slider

Pick a number or a range by dragging, with steps, marks, the keyboard and the value over the thumb.

Price per night$80 – $320
Guests2 guests

253 stays match

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/slider

Usage

import { Slider } from "./ui/uicontext/components/Slider.ts"
const Message = UiSchema.TaggedEnum({ MovedVolume: { volume: Schema.Number } })export const VolumeSlider = (h: Html.H<typeof Message.Type>, volume: number) =>	Slider(h, {		label: "Volume",		value: volume,		format: (n) => `${n}%`,		onMove: (value) => Message.MovedVolume({ volume: value }),	})

Examples

Marks, and saving on release

Labelled stops under the track. onMove follows the thumb; onCommit saves once the drag or key press is done.

Creativity0.4

Saved: 0.4

Long labels, big numbers, disabled

Annual contract value for enterprise accounts in the EMEA region$250.0K – $4.5M
Seats (set by your plan)25

API reference

Options

Slider options
NameTypeDefaultDescription
keystring—Names the slider among others in the same view; needed for more than one.
labelrequiredstring—What it sets: "Volume", "Price". Shown above the track, and each thumb's name.
hideLabelboolean—Hide the label but keep it as the name, when the slider's meaning is plain from where it sits.
valuerequirednumber | Range—One number, or [low, high] for a range with two thumbs. The caller keeps it.
minnumber00 by default.
maxnumber100100 by default.
stepnumber1What a key press and a drag move by; 1 by default.
largeStepnumber—What Shift with an arrow, Page Up and Page Down move by; ten steps by default.
minStepsBetweennumber0For a range: the fewest steps between the two thumbs; 0 by default.
marksSliderMark[]—Points along the track, as ticks, with a label under the ones that have one.
format(value: number) => string—A value as people read it: (n) => \${n}%\`, (n) => \$${n}\`. A grouped number by default.
showValuebooleantrueThe value beside the label; true by default.
bubble"auto" | "never"autoThe bubble over the thumb: while held or focused, and on hover (auto), or never; auto by default.
disabledboolean——
namestring—The form field the value submits under; a range submits two values under it.
onMoverequired(value: number | Range) => Message—Each value the person moves to, during a drag and per key. Store it and pass it back as value.
onCommit(value: number | Range) => Message—The value once the person lets go or presses a key: save it here, not on every move.
styleStyle—StyleX styles applied after the slider's own.

Source