Krizaka UI
Krizaka UI
Composants

Slider

A value or a range chosen by dragging a thumb along a track — steps you can see, the value floating over the thumb, the brand’s gradient, horizontal or vertical — with arrows and Page keys.

Web + MobileBêtaFormulaires

Web et mobile — le même composant pour React et React Native. Bêta : son API peut encore changer à une version mineure.

Pourquoi il est là. Used by Orochia, krizaka.com.

Quand l’utiliser

  • For a value chosen by feel within bounds: volume, speed, brightness.
  • Two thumbs for a range: a price, a duration.

Quand ne pas l’utiliser

  • For an exact number the user knows: an input of type number.À la place : Field
  • For a few named options.À la place : Radio group

Installation

Installer

npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Importer

import { Slider } from "@krizaka/ui/slider";

Exemples

Default

The thumb alone, named by label.

With a label

showLabel: the label and the formatted value above the track.

Speed

Centred

origin={0} on a ± range.

Brightness

Range

Two thumbs, each named.

Price

Disabled

Not available.

Steps and marks

ticks draws a graduation per step, marks their words under the track.

Playback speed

Floating value

floatingValue: the value over the thumb while it is touched; size="lg".

Price range

Two thumbs, their values floating, the bounds written under the track.

Vertical

orientation="vertical": faders; tone="solid" for the accent alone.

Props

A slider on one value or a range: value/defaultValue + onValueChange, min, max, step, orientation.

PropTypeDéfautDescription
labelrequisstring—The accessible name — of the thumb, or of both thumbs of a range — passed translated.
defaultValueSliderValue—The value at first, uncontrolled: one number, or two for a range.
floatingValueboolean | "always"—Shows the value floating over the thumb while it is hovered, focused or held ("always": at all times).
formatValue((value: number) => string)—The value as words (aria-valuetext) and as shown: "1.5×", "−12 %", "3 min".
marksreadonly SliderMark[]—Words under the track at some values ([{ value: 0, label: "0" }, { value: 100, label: "100" }]). Horizontal only.
onValueChange((value: V) => void)—Called on every move, with one number or two.
onValueCommit((value: V) => void)—Called once the drag or the key press ends.
originnumber—Fills from this value instead of the minimum (a ±range from 0: brightness, balance). One horizontal thumb only.
showLabelboolean—Shows the label and the value above the track. Without it, label only names the thumb.
size"md" | "lg"mdmd · lg (a thicker track and thumb: a hero control, a touch screen).
thumbLabels[string, string]—For a range: each thumb's own name (["Minimum", "Maximum"]), passed translated.
ticksboolean | readonly number[]—Draws a graduation at every step (true, up to 40 of them) or at the values given.
tone"gradient" | "solid"gradientgradient (the brand's accent → accent-2, a glow) or solid (the accent alone).
valueSliderValue—One number (a thumb) or two (a range). Controlled with onValueChange.

Accessibilité

  • Radix Slider: each thumb is a slider named by label (or thumbLabels for a range).
  • formatValue also gives aria-valuetext: the value as it is read.

Clavier

TouchesAction
Arrow keysMove by one step.
Page Up / Page DownMove by a larger step.
Home / EndGo to the minimum or the maximum.

Bonnes pratiques

  • Show the value (showLabel) when it matters, formatted by formatValue.
  • Choose a step people can reach with the arrows; origin to fill from a centre on a ± range.
  • Show the steps (ticks) when there are few of them, and name the ends (marks) when the bounds are not obvious.

Générée depuis le code de @krizaka/ui 3.9.0 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page