Skip to content

Latest commit

 

History

History
361 lines (232 loc) · 9.91 KB

slider.md

File metadata and controls

361 lines (232 loc) · 9.91 KB

Slider

Source

A horizontal track with a thumb that can be moved between a minimum and a maximum value.

Usage

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 {...} />

Props

The Slider-component takes the following props:

Name Type Default Required
min number 0
max number 100
step number
showDots boolean false
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

min

min?: number

The minimum value of the slider.


max

max?: number

The maximum value of the slider.


step

step?: number

The amount of steps that the slider should be divided into.


showDots

showDots?: boolean

Whether to show dots at the possible breakpoints


defaultValue

defaultValue?: number

A default value for the slider.


value

value?: number

The current value of the slider.


style

style?: { [key: string]: number | string }

A React style object that will be applied to root element.


className

className?: string

A classname string that will be applied to the root element.


showLabel

showLabel?: boolean

Wether the label should be shown. Only applies to horizontal sliders.


valueFormatter

valueFormatter?: function

A function to format the current value for display in the label.


labelStyle

labelStyle?: { [key: string]: number | string }

A React style object that will be applied to the label.


onChangeStart

onChangeStart?: function

A callback that is invoked when the user starts changing the value.


onChange

onChange?: function

A callback that is invoked when the user changes the value of the slider.


onChangeEnd

onChangeEnd?: function

A callback that is invoked when the user stops changing the slider value.


thumbStyle

thumbStyle?: { [key: string]: number | string }

A React style object that will be applied to the thumb.


disabled

disabled?: boolean

Wether to ignore any user interaction and render the slider with a disabled style.


vertical

vertical?: boolean

Wether the slider should be vertical instead of horizontal.


interval

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

minInterval?: number

The minimum range that can be selected by the two thumbs.


maxInterval

maxInterval?: number

The maximum range that can be selected by the two thumbs.


defaultStartValue

defaultStartValue?: number

The default value for the left thumb.


defaultEndValue

defaultEndValue?: number

The default value for the right thumb.


startValue

startValue?: number

The current value of the left thumb.


endValue

endValue?: number

The current value of the right thumb.


trackStyle

trackStyle?: { [key: string]: number | string }

A React style object that will be applied to the track.


innerTrackStyle

innerTrackStyle?: { [key: string]: number | string }

A React style object that will be applied ot the inner track.


showValueInThumb

showValueInThumb?: boolean

Wether the current value should be shown inside the thumb.


scaleOnDown

scaleOnDown?: boolean

Wether the slider should be scaled when the user grabs it on mobile devices.


thumbWidth

thumbWidth?: number

The width of the thumb.