react-metro-range-slider

1.0.1 • Public • Published

Metro layout range slider for React

Tiny react UI component for modern metro layout based range slider prototype.

Demo

https://imshaikot.github.io/react-metro-range-slider/

Installation

$ npm install react-metro-range-slider --save

Getting Started

There's a lot of other range-slider available for different design purposes - this one will lets you bring the metro layout and the slider by itself very thin :) It's very easy to start with this range slider if you're using any bundler (whether CommonJS or ES6 import).

// Using ES6
import RangeSlider from 'react-metro-range-slider';
import 'react-metro-range-slider/lib/index.css';
 
// Not using ES6
var RangeSlider = require('react-rangeslider');

Example and API

import React from 'react';
 
import RangeSlider from 'react-metro-range-slider';
import 'react-metro-range-slider/lib/index.css';
 
class MyComponent extends React.Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      my_value: 0
    }
  }
 
  onChange(event, value) {
    this.setState({
      my_value: value
    })
  }
 
  render() {
    return (
      <RangeSlider
        onChange={(e, v) => this.onChange(e, v)} // [Optionalin order to track the chages
        onChangeStart={(e, v) => console.log(e, v)} // [Optionalfires when change/drag starts
        onChangeEnd={(e, v) => console.log(e, v)} // [Optionalfires when change/drag ends
 
        colorPalette={{fill: '#F97D4E', toFill: '#939292', thumb: '#FD5412'}} // [Optionalto set color palette to the slider
 
        max={50} // [Optional] [Default: 100]
        min={-20} // [Optional] [Default: 0]
        preValue={10} // [Optional] [Default: 0to set prefilled value
 
        disabled={true} // [Optional] [Default: falseto set the slider in dsiabled state
 
        value={0} // [Optionalthis one is very important - it won't update on change and you shouldn't assign the updated value on itThe purpose of using this prop is to set any data to set during the runtime (exany async value)
 
        onPreModal={(value) => Math.round(value) } // [Optionalto show a predictional tooltipyou should pass a function and return the filtered value to itIf the function returns undefinedit'll show the current value on the tooltip
      />
    )
  }
}

Package Sidebar

Install

npm i react-metro-range-slider

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • imshaikot