react-rangeslider

A lightweight responsive react range slider component.A fast & lightweight react component as a drop in replacement for HTML5 input range slider element.

  • 所有者: whoisandy/react-rangeslider
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Installation

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

$ npm install react-rangeslider --save

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

$ yarn add react-rangeslider

Getting Started

React-Rangeslider is bundled with a slider component & default styles which can be overridden depending on your design requirements.

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 Slider from 'react-rangeslider'

// To include the default styles
import 'react-rangeslider/lib/index.css'

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

The UMD build is also available on unpkg:

<script src="https://unpkg.com/react-rangeslider/umd/rangeslider.min.js"></script>

You can find the library on window.ReactRangeslider. Optionally you can drop in the default styles by adding the stylesheet.

<link rel="stylesheet" href="https://unpkg.com/react-rangeslider/umd/rangeslider.min.css" />

Check out docs & examples.

Basic Example

import React, { Component } from 'react'
import Slider from 'react-rangeslider'

class VolumeSlider extends Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      volume: 0
    }
  }

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

  render() {
    let { volume } = this.state
    return (
      <Slider
        value={volume}
        orientation="vertical"
        onChange={this.handleOnChange}
      />
    )
  }
}

API

Rangeslider is bundled as a single component, that accepts data and callbacks only as props.

Component

import Slider from 'react-rangeslider'

// inside render
<Slider
  min={Number}
  max={Number}
  step={Number}
  value={Number}
  orientation={String}
  reverse={Boolean}
  tooltip={Boolean}
  labels={Object}
  handleLabel={String}
  format={Function}
  onChangeStart={Function}
  onChange={Function}
  onChangeComplete={Function}
/>

Props

Prop, Type, Default, Description
---------, -------, -------, -----------
min, number, 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
value, number, current value of the slider
orientation, string, horizontal, orientation of the slider
tooltip, boolean, true, show or hide tooltip
reverse, boolean, false, reverse direction of vertical slider (top-bottom)
labels, object, {}, object containing key-value pairs. { 0: 'Low', 50: 'Medium', 100: 'High'}
handleLabel, string, '', string label to appear inside slider handles
format, function, function to format and display the value in label or tooltip
onChangeStart, function, function gets called whenever the user starts dragging the slider handle
onChange, function, function gets called whenever the slider handle is being dragged or clicked
onChangeComplete, function, function gets called whenever the user stops dragging the slider handle.

Development

To work on the project locally, you need to pull its dependencies and run npm start.

$ npm install
$ npm start

Issues

Feel free to contribute. Submit a Pull Request or open an issue for further discussion.

License

MIT

主要指標

概覽
名稱與所有者whoisandy/react-rangeslider
主編程語言JavaScript
編程語言CSS (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2015-09-16 04:31:47
推送於2024-07-11 16:45:58
最后一次提交2017-09-18 20:32:59
發布數15
最新版本名稱v2.2.0 (發布於 2017-09-18 20:32:59)
第一版名稱1.0.0 (發布於 )
用户参与
星數644
關注者數12
派生數235
提交數215
已啟用問題?
問題數98
打開的問題數50
拉請求數18
打開的拉請求數45
關閉的拉請求數21
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?