Giter Site home page Giter Site logo

bpote / react-compound-slider Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sghall/react-compound-slider

0.0 2.0 0.0 2.31 MB

React Compound Slider | Futuristic 5kb slider :curly_loop:

Home Page: https://sghall.github.io/react-compound-slider/#/slider-demos/horizontal

License: MIT License

JavaScript 99.76% Shell 0.24%

react-compound-slider's Introduction

react-compound-slider

Welcome to the future. React Compound Slider is a tiny (5kb) slider component with no opinion about markup or styles.

Build Status Dependency Status Coverage Status license npm version

React Compound Slider
React Compound Slider
React Compound Slider

Installation

React Compound Slider is available as an npm package.

To install and save in your package.json dependencies, run:

npm install react-compound-slider

Approach

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

If your 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 Features

  • Compound component design provides maximum customizability ✓

    • Makes no assumptions about your markup
    • Precise control over user interactions and styling
  • Horizontal/vertical display ✓

  • The display of values can be reversed ✓

  • Supports mouse and touch events ✓

    • Supports IE9+, Chrome, Firefox & Safari
  • Create any type of slider ✓

    • One API for all sliders types
    • Single value slider
    • Range slider (2 handles)
    • Multiple Sliders (N handles)
  • Automatically generates uniformly spaced, human-readable tick values to label your slider ✓

    • Supports passing custom set of ticks
  • Integrates seemlessly with any app styling approach ✓

    • CSS
    • CSS-in-JS
    • Inline-styles
  • Interaction modes ✓

    • Allow handles to cross
    • Prevent crossing
  • Works as a controlled component ✓

Example Usage

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

const sliderStyle = {
  position: 'relative',
  width: '100%',
  height: 80,
}

  <Slider
    rootStyle={sliderStyle}
    domain={[0, 100]}  // [min, max]
    step={1}
    mode={2} // 1 = allow-crossing of handles, 2 = no crossing
    values={[10, 20, 30]} // one value would be a value slider, two a range slider, etc
  >
    <Rail>
      {({ getRailProps }) => (
        <div style={railStyle} {...getRailProps()} /> // the rail props will make the rail clickeable (optional)
      )}
    </Rail>
    <Handles>
      {({ handles, getHandleProps }) => (
        <div className="slider-handles">
          {handles.map(handle => (
            ...render your handle here
          ))}
        </div>
      )}
    </Handles>
    <Tracks left={false} right={false}>  // you can toggle the left and right tracks
      {({ tracks, getTrackProps }) => (
        <div className="slider-tracks">
          {tracks.map(({ id, source, target }) => (
            ...render your track here
          ))}
        </div>
      )}
    </Tracks>
    <Ticks count={15}> // generates nice tick mark values or provide your own
      {({ ticks }) => (
        <div className="slider-ticks">
          {ticks.map(tick => (
            ...render your tick here
          ))}
        </div>
      )}
    </Ticks>
  </Slider>

react-compound-slider's People

Contributors

sghall avatar josepot avatar bvandenbos avatar

Watchers

James Cloos avatar Brisha Pote avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.