Components
Slider
Unstable: a value in a range on a native range input, its name and value written out above the track. Import it from @nizivo/react/unstable/slider.
Examples
Basic
A slider: the name and the value above the track, the value always written out.
import type { JSX } from 'react';
import { Slider } from '@nizivo/react/unstable/slider';
export function SliderExample(): JSX.Element {
return (
<div style={{ display: 'grid', gap: 24, inlineSize: 320 }}>
<Slider label="Discount" defaultValue={30} format={{ style: 'unit', unit: 'percent' }} />
<Slider label="Volume" defaultValue={70} disabled />
</div>
);
}
Import
import { Slider } from '@nizivo/react/unstable/slider';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/slider.css';Static or interactive
Client. It holds the value; the input is the browser's own <input type="range">, so its
role, keys (the arrows step, Page Up and Page Down jump, Home and End go to the ends) and form
submission are native. How to choose.
Value
value, defaultValue and onValueChange hold the number; min, max and step set the range,
and keyStep makes the arrow keys move further than one step (a media scrubber steps 1 second and
seeks 5).
The value is always written out above the track: format (Intl number options) or valueText (a
function) gives the words, which a screen reader hears as aria-valuetext ("30%"). label names it,
or aria-label when there is no visible name.
Fill
The fill is drawn from a custom property set when the slider hydrates (no style attribute, so it works under a strict CSP); Firefox draws its own. Before hydration the track shows no fill.
Props
Client component Renders data-slot="slider" with the class nz-slider. Props: SliderProps. Source: src/unstable/slider/slider.client.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
aria-label | string | – | Names the input when there is no |
defaultValue | number | min | The value at first (uncontrolled). |
disabled | boolean | false | |
format | Intl.NumberFormatOptions | – | Number format for the default value text. |
keyStep | number | step | How far the arrow keys move it, when not one |
label | ReactNode | – | The visible name. Without it, name the slider with |
locale | string | 'en-US' | BCP 47 tag for the default value text. |
max | number | 100 | |
min | number | 0 | |
name | string | – | The input's |
onValueChange | (value: number) => void | – | |
render | RenderProp<SliderState> | – | Must render a |
showValue | boolean | true | Shows the value text above the track. |
step | number | 1 | |
value | number | – | The value (controlled). |
valueText | (value: number) => string | the number, formatted | The value in words, shown above the track and read by a screen reader. |
- Also takes every attribute of
<div>exceptchildren,defaultValue,onChange;aria-labelis redeclared above. (Omit<ComponentPropsWithRef<"div">, "defaultValue" | "onChange" | "children">)
render takes an element, or, in client code, a function of the props and this state (SliderState):
| Name | Type | Default | Description |
|---|---|---|---|
disabledrequired | boolean | – | |
valuerequired | number | – |
Other exports
SliderPropstypeimport type { SliderProps } from '@nizivo/react/unstable/slider'The props of
Slider, listed above.SliderStatetypeimport type { SliderState } from '@nizivo/react/unstable/slider'The render state of
Slider, listed above.
Data attributes and slots
Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.
| Slot | Rendered by | Data attributes |
|---|---|---|
slider.nz-slider | Sliderroot (takes render) |
|
slider-input.nz-slider-input | Sliderinner element (CSS only); interactive, focus: self | none |
slider-label.nz-slider-label | Sliderinner element (CSS only) | none |
slider-value.nz-slider-value | Sliderinner element (CSS only) | none |
CSS hooks
Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.
This stylesheet reads no public hook.
Layers: nz.components. Classes: .nz-slider, .nz-slider-input, .nz-slider-label, .nz-slider-top, .nz-slider-value.
Tokens this stylesheet reads (11)
--nz-bg-brand, --nz-chart-track, --nz-font-label-m, --nz-radius-full, --nz-space-1, --nz-space-2, --nz-space-3, --nz-space-5, --nz-space-6, --nz-text-primary, --nz-text-secondary
Accessibility
These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:
slider-input: draws the focus outline itself on keyboard focus.
Keyboard
To be written.
Skeleton
One placeholder block, always hidden from assistive technology. The region it stands in for sets aria-busy and carries visually hidden "Loading …" text (§16.5). There is no style prop path: size it with a class, or with --nz-skeleton-width, --nz-skeleton-height and --nz-skeleton-radius.
SourceCard
Unstable: where an AI answer came from, a web page or a file, as one link with its domain, title and number. A web source opens in a new tab and says so. Import it from @nizivo/react/unstable/source-card.