• Stars
    star
    626
  • Rank 71,755 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โ—พ React Compound Slider | A small React slider with no opinion on markup or styles

React Compound Slider

Welcome to the future. React Compound Slider is a small slider component with no opinion about markup or styles.

Documentation and Examples

Coverage Status license npm downloads npm version Language grade: JavaScript

2020 Roadmap

Basic Overview:

  • Convert slider source to Typescript (done)
  • Convert tests to Typescript (done)
  • Convert demos and docs to Typescript (done)
  • Use hooks internally and export them
  • Drive state changes with a reducer that can be changed by the user

The upcoming versions of this slider will allow for more customization. I don't expect any significant changes for existing users.

Motivation

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.

Slider Features

  • Small size
  • 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

Documentation and Examples

More Examples on CodeSandbox

Installation

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 [email protected]

Documentation

The documentation is divided into several sections:

Example Usage

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:

Starter Components - Horizontal

Starter Components - Vertical

Starter Components - Material UI

Starter Components - With Tooltips

Basic Tooltip CSS (CSS from this demo)

import { Slider, Handles, Tracks } from 'react-compound-slider'
import { Handle, Track, Tick } from './your-local-slider-components'

  <Slider
    rootStyle={sliderStyle}
    domain={[0, 100]} // [min, max]
    values={[20, 60, 80]} // slider values
  >
    <Rail>
      {({ getRailProps }) => (
        <div style={railStyle} {...getRailProps()} /> // render your clickable rail!
      )}
    </Rail>
    <Handles>
      {({ handles, getHandleProps }) => (
        // render your handles!
      )}
    </Handles>
    <Tracks left={false} right={false}>
      {({ tracks, getTrackProps }) => (
        // render your (optional) tracks!
      )}
    </Tracks>
    <Ticks count={10}>
      {({ ticks }) => (
        // render your (optional) ticks!
        // count prop = auto generate approximately 10 uniformly spaced, human-readable ticks
      )}
    </Ticks>
  </Slider>

Approach

This library takes a compound component approach to creating sliders that separates the data/logic from presentation.

If you're familiar with Kent Dodd's work on Paypal's downshift or react-toggled then the pattern should seem familiar. The components use the function as child components pattern.

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. The 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 Handles, Tracks, and 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

More Repositories

1

react-move

React Move | Beautiful, data-driven animations for React
JavaScript
6,585
star
2

react-vertex

โ—พ React Vertex | Hooks-based WebGL library for React
TypeScript
1,240
star
3

resonance

โ—พResonance | 5kb React animation library
JavaScript
1,005
star
4

d3-threejs

CSS 3D Transforms with D3 and THREE.js
JavaScript
304
star
5

threejs-maps

Interactive Maps with D3.js, Three.js and Mapbox
JavaScript
97
star
6

react-d3-transitions

Enter, update and exit pattern using React 15.0, D3 4.0 and Redux
JavaScript
85
star
7

subunit

A small library that gives you D3 style selections in THREE.js.
JavaScript
73
star
8

webgl-globes

JavaScript
64
star
9

d3-chord-diagrams

Example Chord Diagrams in D3
HTML
49
star
10

d3-graphs

An Interactive Force Directed Graph in D3.js
JavaScript
45
star
11

famous-chart-demos

Examples integrating D3.js with Famo.us
JavaScript
43
star
12

chord-transitions

Transitioning Chord Diagram Demo with Angular/D3
JavaScript
39
star
13

d3-multi-series-charts

Some Example Multi-Series Charts in D3.js
JavaScript
26
star
14

last-fm

A demo app using D3 and AngularJS Directives
JavaScript
19
star
15

bundle-inspector-webpack-plugin

Bundle Inspector | Analysis Tool for Webpack
JavaScript
18
star
16

angular-d3

Demo app using Angular, D3, and Neo4j.
JavaScript
13
star
17

physijs-dom-renderer

Demo of JavaScript physics engine simulation with DOM elements. D3.js used to generate HTML.
JavaScript
7
star
18

dragon-curves

JavaScript
5
star
19

chaos-game

JavaScript
5
star
20

javascript-object-instantiation

JavaScript
5
star
21

react-quickie-controls

Quick development controls for React projects. Change values and colors quickly in your development environment or storybooks.
TypeScript
5
star
22

web-scraper

Some node scripts for scraping movie data from the web.
JavaScript
4
star
23

chart-physics

Experiments with Three.js, D3.js and Physics Engines
JavaScript
4
star
24

kapellmeister

Orchestration for Animated Transitions
JavaScript
4
star
25

neo4j-loader

A simple Node module to bulk load data into Neo4j
JavaScript
2
star
26

webgl-flux-chat

JavaScript
2
star
27

bungalow

JavaScript
1
star
28

antigen

JavaScript
1
star