Giter Site home page Giter Site logo

rheostat's Introduction

Rheostat

A mobile, tablet, desktop, and accessible slider for the web.

Rheostat demo

Install

npm install rheostat

Props

The algorithm, by default linear, the slider will use. Feel free to write your own as long as it conforms to the shape.

  algorithm: PropTypes.shape({
    getValue: PropTypes.func,
    getPosition: PropTypes.func,
  })

Custom class name that will be applied to the root of Rheostat.

  className: PropTypes.string

Custom React component overrides for both the handles, and the "progress" bar.

  handle: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
  progressBar: PropTypes.oneOfType([PropTypes.func, PropTypes.string])

The maximum and minimum possible values, by default 0 - 100.

  max: PropTypes.number
  min: PropTypes.number

pitComponent is a custom React component for rendering "pits" across the bar. pitPoints is the set of points at which it will render a pit. Points are an array of values on the slider.

  pitComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
  pitPoints: PropTypes.arrayOf(PropTypes.number)

NOTE: onChange is called whenever the value is changed and committed. This happens at the end of a drag, keypress, or click event. onChange is recommended when you wish to persist the values.

onValuesUpdated is a convenience event that is triggered while the value is being actively changed. This includes dragging, click, or keypress. onValuesUpdated is recommended if you need to work with the values before they're committed.

  onChange: PropTypes.func
  onClick: PropTypes.func
  onKeyPress: PropTypes.func
  onSliderDragEnd: PropTypes.func
  onSliderDragMove: PropTypes.func
  onSliderDragStart: PropTypes.func
  onValuesUpdated: PropTypes.func

snap is a boolean which controls the slider's snapping behavior. snapPoints is an array of values on the slider where the slider should snap to.

If snap is set to true and no snapPoints are set then the slider is snapped into an absolute position. For example, on a scale of 1-10 if the slider is let go at the 54% mark it'll pick the value 5 and snap to 50%.

  snap: PropTypes.bool
  snapPoints: PropTypes.arrayOf(PropTypes.number)

The values, by default 0 and 100.

  values: PropTypes.arrayOf(PropTypes.number)

You can disable the slider to prevent the user from moving it.

  disabled: PropTypes.bool

Usage

Important: Make sure to include the css file or feel free to create your own.

  • Simple.
import Rheostat from 'rheostat';

ReactDOM.render(<Rheostat />, document.getElementById('slider-root'));
  • A slider with a multiple handles.
import Rheostat from 'rheostat';

ReactDOM.render((
  <Rheostat
    min={1}
    max={100}
    values={[1, 100]}
  />
), document.getElementById('slider-root'));

Live Playground

For more examples you can check out the storybook.

  • Clone this repo on your machine.
  • npm install
  • npm run storybook
  • Visit http://localhost:9001/.

rheostat's People

Contributors

goatslacker avatar greenkeeper[bot] avatar iam4x avatar joeduncan avatar lambdahands avatar lencioni avatar ljharb avatar malindamiller avatar manuhabitela avatar raghavio avatar reklawnos avatar

Watchers

 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.