A horizontal track with a thumb that can be moved between a minimum and a maximum value.
You should have the chayns-components
package installed. If that is not the
case already, run
yarn add chayns-components
or
npm i chayns-components
After the chayns-components
package is installed, you can import the component
and use it with React:
import React from 'react'
import { Slider } from 'chayns-components';
// ...
<Slider {...} />
The Slider
-component takes the following props:
Name | Type | Default | Required |
---|---|---|---|
min | number |
0 |
|
max | number |
100 |
|
step | number |
||
defaultValue | number |
0 |
|
value | number |
||
style | { [key: string]: number | string } |
||
className | string |
||
showLabel | boolean |
false |
|
valueFormatter | function |
(value1, value2) => value2 ? ${Math.round(value1)} - ${Math.round(value2)} : Math.round(value1)
|
|
labelStyle | { [key: string]: number | string } |
{ minWidth: '50px' } |
|
onChangeStart | function |
||
onChange | function |
||
onChangeEnd | function |
||
thumbStyle | { [key: string]: number | string } |
||
disabled | boolean |
false |
|
vertical | boolean |
false |
|
interval | boolean |
false |
|
minInterval | number |
||
maxInterval | number |
||
defaultStartValue | number |
0 |
|
defaultEndValue | number |
0 |
|
startValue | number |
||
endValue | number |
||
trackStyle | { [key: string]: number | string } |
||
innerTrackStyle | { [key: string]: number | string } |
||
showValueInThumb | boolean |
false |
|
scaleOnDown | boolean |
||
thumbWidth | number |
20 |
min?: number
The minimum value of the slider.
max?: number
The maximum value of the slider.
step?: number
The amount of steps that the slider should be divided into.
defaultValue?: number
A default value for the slider.
value?: number
The current value of the slider.
style?: { [key: string]: number | string }
A React style object that will be applied to root element.
className?: string
A classname string that will be applied to the root element.
showLabel?: boolean
Wether the label should be shown. Only applies to horizontal sliders.
valueFormatter?: function
A function to format the current value for display in the label.
labelStyle?: { [key: string]: number | string }
A React style object that will be applied to the label.
onChangeStart?: function
A callback that is invoked when the user starts changing the value.
onChange?: function
A callback that is invoked when the user changes the value of the slider.
onChangeEnd?: function
A callback that is invoked when the user stops changing the slider value.
thumbStyle?: { [key: string]: number | string }
A React style object that will be applied to the thumb.
disabled?: boolean
Wether to ignore any user interaction and render the slider with a disabled style.
vertical?: boolean
Wether the slider should be vertical instead of horizontal.
interval?: boolean
Wether the slider should select a range instead of a single value. This will add a second thumb for the user to adjust.
minInterval?: number
The minimum range that can be selected by the two thumbs.
maxInterval?: number
The maximum range that can be selected by the two thumbs.
defaultStartValue?: number
The default value for the left thumb.
defaultEndValue?: number
The default value for the right thumb.
startValue?: number
The current value of the left thumb.
endValue?: number
The current value of the right thumb.
trackStyle?: { [key: string]: number | string }
A React style object that will be applied to the track.
innerTrackStyle?: { [key: string]: number | string }
A React style object that will be applied ot the inner track.
showValueInThumb?: boolean
Wether the current value should be shown inside the thumb.
scaleOnDown?: boolean
Wether the slider should be scaled when the user grabs it on mobile devices.
thumbWidth?: number
The width of the thumb.