React Rangeslider Extended
A lightweight responsive react range slider component forked from whoisandie/react-rangeslider.
Check out examples.
Install
Install via npm
(use --save
to include it in your package.json)
$ npm install react-rangeslider-extended --save
Usage
React Rangeslider is bundled with a single slider component. You can require them in plain old ES5 syntax or import them in ES6 syntax.
...plain old ES5
var React = ;var Slider = ; var Volume = React; moduleexports = Volume;
... or use ES6 syntax
;; extends Component { superprops context; thisstate = value: 10 /** Start value **/ ; } { this; } { return <Slider value=value orientation="vertical" onChange=thishandleChange /> ; }
There's also a umd version available at lib/umd
. The component is available on window.ReactRangeslider
. To style the slider, please refer the rangeslider styles in demo/demo.less
file.
API
Rangeslider is bundled with a single component, that accepts data and callbacks only as props
.
Component
// inside render<Slider min=String or Number max=String or Number step=String or Number orientation=String value=Number onChange=Function onChangeComplete=Function valueMapping=Function />
Props
Prop | Default | Description |
---|---|---|
min |
0 | minimum value the slider can hold |
max |
100 | maximum value the slider can hold |
step |
1 | step in which increments/decrements have to be made |
orientation |
horizontal | orientation of the slider |
value |
- | current value of the slider |
onChange |
- | function the slider takes, current value of the slider as the first parameter |
onChangeComplete |
- | function the slider takes and fires after interaction has ended, current value of the slider as the first parameter |
valueMapping |
default func | function returning an object that defines segments and toValue and toPos methods to controll position to value (and vice versa) mapping |
Value Mapping
The valueMapping
prop takes a function taking the arguments min
and max
that returns an object with definitions of segments on the slider’s range and how positions within these segments are mapped to values.
This allows for example to let you set lower values more precisely and higher ones in larger steps. For each segment there is toValue
(position to value) and a toPos
(value to position) function defined.
The keys of the definition object define the segements start position. See example below.
... Component ... '0': Math value / 2 / 100 '.25': Math value / 100 '.5': Math value / span * range ; { return <Slider min=0 max=1000 value=thisstatevalue onChange=thishandleChange valueMapping=thisvalueMapping /> <div className="value">Value: thisstatevalue</div> ; }
Issues
Feel free to contribute. Submit a Pull Request or open an issue for further discussion.
Todo
- Ship styles along with component
- Tests using Enzyme
License
MIT © whoisandie & Oliver Wehn