Coder Social home page Coder Social logo

phpsmarter / react-slider-kit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from m-izadmehr/react-slider-kit

1.0 1.0 0.0 488 KB

react-slider-kit is going to be a comprehensive solution to slider feature in react.

Home Page: https://m-izadmehr.github.io/react-slider-kit/

License: MIT License

JavaScript 99.83% CSS 0.17%

react-slider-kit's Introduction

react-slider-kit

N|Solid

react-slider-kit is going to be a comprehensive solution to slider feature in react. This component was originally inspired by dribble concept design The Range Slider Component.

This slider components is going to include:

  • 1D and 2D sliders
  • Single and range sliders (in progress)
  • Horizontal and vertical sliders

Demo

The working demo of this component can be find at https://m-izadmehr.github.io/react-slider-kit/. An image of the original dribble design is shown below:

N|Solid


Installation

Using npm (use --save to include it in your package.json)

$ npm install react-slider-kit --save

Using yarn (this command also adds react-rangeslider to your package.json dependencies)

$ yarn add react-slider-kit

Getting Started

react-slider-kit is going to be a package of different sliders. In order to use a slider with a module bundler like webpack that supports either CommonJS or ES2015 modules, use as you would anything else:

// Using an ES6 transpiler like Babel
import {} from 'react-rangeslider'

// Not using an ES6 transpiler
var Slider = require('react-rangeslider')

Basic Example

import React, { Component } from 'react'
import {SingleSlider} from 'react-slider-kit';

export default class SimpleExample extends Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      value: 0
    }
  }

  handleOnChange = (value) => {
    this.setState({
      value: value
    })
  }

  render() {
    return (
       <SingleSlider
            min={0}
             max={100}
            step={20}
            start={80}
            onChangeStart={() => console.log('start drag')}
            onChange={(value)=>console.log('drag value: ', value)}
            onChangeComplete={this.handleOnChange}
        />
    )
  }
}

API

React-Slider-Kit is bundled as a combination of multiple components, and by default the single slider is imported.

Component

import {SingleSlider} from 'react-slider-kit';

// inside render

<SingleSlider
    min={Number}
    max={Number}
    step={Number}
    start={Number}
    sliderTo={Number}
    prefix={String}
    postfix={String}
    labels={Array}
    sticky={Boolean}
    tooltip={String}
    orientation={String}

    // chart configs
    chartData={Array}
    chartTooltip={Boolean}
    chartLength={Number}

    // methods
    onChangeStart={function}
    onChange={function}
    onChangeComplete={function}
/>

Props

Prop Type Default Description
min number 0 minimum value the slider can hold
max number 100 maximum value the slider can hold
step number 1 step in which increments/decrements have to be made
start number 0 starting value of slider
sliderTo number undefined used to change the value of slider manually (componentWillReceiveProps is listening for changes in this value)
tooltip string 'always' controls when slider tooltip is shown (always/onClick/never)
prefix string '' prefix in tooltip label (eg. '$')
postfix string '' postfix in tooltip label (eg. 'kg')
labels array [] custom labels to show on slider (eg. [{x:0,val:'Start'}, {x:50,val:'Middle'},]
sticky boolean false controls whether slider handle can move smoothly or it can only sit on step values
orientation string 'horizontal' slider orientation (eg. horizontal, vertical)
chartData array - used for showing 2D frequency graph on the slider (eg. [{ y: 0 }, { y: 0.1 }, { y: 1 }, { y: 1.5 }, { y: 3 }])
chartTooltip boolean false controls whether chart tooltip is shown on hover on data points
chartLength number 200 chart height (width) of chart in horizontal (vertical) orientation
onChangeStart function - function called on starting to drag slider
onChange function - function called during moving slider(on every pixel)
onChangeComplete function - function called after finishing slider move (used to set slider value on state)

License

MIT

react-slider-kit's People

Contributors

m-izadmehr avatar

Stargazers

 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.