Slider
A slider for selecting a number within a range. Also supports range selection with start and end points.
View in Storybook (opens in a new tab)
Installation
import { Slider } from "@ginga-ui/core";Basic usage
A simple slider example.
slider.tsx
import { Slider, SliderLabel, SliderOutput, SliderThumb, SliderTrack } from "@ginga-ui/core";
export function BasicExample() {
return (
<Slider defaultValue={50}>
<SliderLabel>Volume</SliderLabel>
<SliderOutput />
<SliderTrack>
<SliderThumb />
</SliderTrack>
</Slider>
);
}Custom range
A slider with custom minimum and maximum values.
slider.tsx
import { Slider, SliderLabel, SliderOutput, SliderThumb, SliderTrack } from "@ginga-ui/core";
export function CustomRangeExample() {
return (
<Slider defaultValue={0} minValue={-50} maxValue={50}>
<SliderLabel>Balance</SliderLabel>
<SliderOutput />
<SliderTrack>
<SliderThumb />
</SliderTrack>
</Slider>
);
}Range selection
Pass an array to defaultValue and place two SliderThumb elements to create a range slider with start and end points.
slider.tsx
import { Slider, SliderLabel, SliderOutput, SliderThumb, SliderTrack } from "@ginga-ui/core";
export function RangeExample() {
return (
<Slider defaultValue={[20, 80]}>
<SliderLabel>Price range</SliderLabel>
<SliderOutput />
<SliderTrack>
<SliderThumb index={0} />
<SliderThumb index={1} />
</SliderTrack>
</Slider>
);
}With steps
A slider with a specified step.
slider.tsx
import { Slider, SliderLabel, SliderOutput, SliderThumb, SliderTrack } from "@ginga-ui/core";
export function WithStepsExample() {
return (
<Slider defaultValue={50} step={10}>
<SliderLabel>Volume level (steps of 10)</SliderLabel>
<SliderOutput />
<SliderTrack>
<SliderThumb />
</SliderTrack>
</Slider>
);
}Disabled
A disabled slider.
slider.tsx
import { Slider, SliderLabel, SliderOutput, SliderThumb, SliderTrack } from "@ginga-ui/core";
export function DisabledExample() {
return (
<Slider defaultValue={50} disabled>
<SliderLabel>Disabled slider</SliderLabel>
<SliderOutput />
<SliderTrack>
<SliderThumb />
</SliderTrack>
</Slider>
);
}Props
Slider
| Name | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables the slider. |
Also accepts the props of React Aria's Slider (opens in a new tab).
SliderLabel
Accepts the props of React Aria's Label (opens in a new tab).
SliderOutput
Accepts the props of React Aria's SliderOutput (opens in a new tab).
SliderTrack
Accepts the props of React Aria's SliderTrack (opens in a new tab).
SliderThumb
Accepts the props of React Aria's SliderThumb (opens in a new tab).