React Compound Slider
Welcome to the future. React Compound Slider is a tiny (4.3kb) slider component with no opinion about markup or styles.
This library aims to be a stable platform for creating slider components with a very small impact on bundle size. It is primarily aimed at application developers and npm package maintainers. You can create your own set of controls matched exactly to your application style, but it takes a little more effort than other components out there. You need to be comfortable handling what gets rendered and styling your components to really get maximum value from this library. There are quite a few demos on the website but they should be used as a starting point. You can also create your own custom themed slider component for your favorite framework and release it on npm for others to use.
- Small size (4.3kb)
- Makes no assumptions about your markup
- Supports SVG sliders
- Supports typescript
- Precise control over user interactions and styling
- Horizontal/vertical display
- The display of values can be reversed
- Supports mouse and touch events (tested in IE9+, Chrome, Firefox & Safari)
- Supports keyboard events so handles can be moved using arrow keys
- Create any type of slider (value, range, n-handled sliders)
- Generates uniformly spaced, human-readable tick values to label your slider
- Integrates seemlessly with any app styling approach (CSS, CSS-in-JS, Inline-styles)
- Interaction modes (Allow crossing, Prevent crossing, Pushable mode, Create your own mode)
- Works as a controlled component
More Examples on CodeSandbox
- Basic Multi-Slider on CodeSandbox
- Date/Time Slider on CodeSandbox
- Video Slider on CodeSandbox
- Slider w/ Tooltips (Typescript)
- SVG Slider on CodeSandbox
- Value Slider on CodeSandbox (Typescript)
- Range Slider on CodeSandbox (Typescript)
- Custom Feet-Inches Ticks on CodeSandbox (Typescript)
- Custom Feet-Inches Ticks - Vertical on CodeSandbox (Typescript)
- Material Design Example on CodeSandbox by @RafeSacks
- Slider with Bar Chart on CodeSandbox by @magician11 See #85.
React Compound Slider is available as an npm package.
To install and save in your
package.json dependencies, run:
// React 16.3 or greater npm install react-compound-slider // React 15.0 -> 16.2 npm install firstname.lastname@example.org
The documentation is divided into several sections:
You have full control of everything that is rendered. Just render the
Slider children that you want. Don't need ticks? Don't use
Ticks. Don't want a rail? Don't use
Rail. Just create the local rail, handle, track and tick components that you want and render those using whatever styling method you prefer.
You can use these components from the demos to jumpstart your slider:
import Slider Handles Tracks from 'react-compound-slider'import Handle Track Tick from './your-local-slider-components'<Slider== // [, ]= //><Rail>getRailProps<div = /> // render your clickable rail!</Rail><Handles>handles getHandleProps// render your handles!</Handles><Tracks = =>tracks getTrackProps// render your (optional) tracks!</Tracks><Ticks =>ticks// render your (optional) ticks!// count prop = auto generate approximately 10 uniformly spaced, human-readable ticks</Ticks></Slider>
This library takes a compound component approach to creating sliders that separates the data/logic from presentation.
In practical terms this means you can create just about any kind of slider you can imagine and use whatever style approach you want.
By taking this approach it also frees you up to render whatever markup you want to customize your slider.
Slider streams you the data and really only cares about the dimensions of the outer div where it takes its measurements from.
In general slider components are composed of a relatively positioned outer div with elements absolutely positioned inside by a percentage.
In this library the
Ticks components are used as children to the
Slider component and they let you tap into a stream of values and percentages that you can then use to render your own components.
Slider Artwork by Guilhem from the Noun Project