3.0.6 • Published 8 years ago

reactrangeslider v3.0.6

Weekly downloads
612
License
MIT
Repository
github
Last release
8 years ago

React Sliders

An collection of elegant slider components for React. Demo Page.

Installing

The library is available as npm package.

npm install reactrangeslider

Using The component

The component is easy to use. Import the library and add the component to your JSX:

import React from 'react';
import Slider from 'range-sliders';

const MyPage = () =>
  <div>
    <Slider />
  </div>;

Small cart in header

An example of uncontrolled slider with single handle, defaultValue and step passed in props:

import React from 'react';
import RangeSlider from 'reactrangeslider';

const MyPage = () =>
  <div>
    <Slider defaultValue={20} step={ 5 } />
  </div>;

An example of controlled range slider with two handles, value and step passed in props:

import React from 'react';
import RangeSlider from 'reactrangeslider';

// value={ start: 20, end: 80 }
const MyPage = (value, onChange) =>
  <div>
    <RangeSlider
      value={ value }
      onChange={ onChange }
      min={ 20 }
      max={ 100 }
      step={ 5 }
    />
  </div>;

Check docs for more examples.

List of properties supported

OptionDescription
idid of the root div element
namename of the root div element
minminimum value in the range
maxmaximum value in the range
stepamount by which the position of slider will change in one movement
defaultValueit is used to initialize uncontrolled components
valueit is used to set value in a controlled component
onChangethe function is executed whenever the value changes
afterChangethe function is executed after the user has stopped moving the slider
disabledproperty used to disable component, disable component can not even receive focus
readOnlyproperty used to make component readOnly, it can still be focused
tabIndexthis is used to set the tabIndex of handles which are moved to change value of slider

Custom styling

Styling of Range Slider is highly customizable. It supports styling using both inline styles and classes. Internally the libary used inline styles, I have preferred that for ease of installation for users.

If inline styles are used for styling, the inline styles passed to it will override the defaults. If classes are used for styling, you will be required to use !important to override corresponding default inline style.

Style PropertyDescription
wrapperStylestyle applied to wrapper div element
trackStylestyle applied to track
disabledTrackStylestyle applied to track of disabled component
highlightedTrackStylestyle applied to highlighted track
disabledHighlightedTrackStylestyle applied to highlighted track of disabled component
handleStylestyle applied to handle
focusedHandleStylestyle applied to focused handle
hoveredHandleStylestyle applied to hovered handle
activeHandleStylestyle applied to active handle
disabledHandleStylestyle applied to disabled handle
Class NameDescription
wrapperClassNameclass applied to wrapper div element
handleClassName / disabledHandleClassNameeither of these classes is applied to the handle depending on whether its enabled or disabled
trackClassName / highlightedTrackClassNameeither of these classes is applied to the track depending on whether its enabled or disabled
highlightedTrackClassName / disabledHighlightedTrackClassNameeither of these classes is applied to the highlighted handle depending on whether its enabled or disabled

Styles applied to highlighted track are applicable only to Reage Slider with two handles and highlighted area between them.

Device support

Range Slider is responsive to different sizes and resolutions. Its responsive to mouse, keyboard and touch events.

Future plans

Making it a complete range of slider components with addition of components like vertical slider, vertical range slider, etc motivation.

License

MIT.