1.4.0 • Published 5 years ago

react-multi-bar-slider v1.4.0

Weekly downloads
677
License
MIT
Repository
github
Last release
5 years ago

react-multi-bar-slider

Slider component with multiple bars for React.

Demo repo

Multi slider screenshot

Install

yarn add react-multi-bar-slider or npm install --save react-multi-bar-slider

Usage

See the demo repo.

Basic example

import MultiSlider, { Progress } from 'react-multi-bar-slider';

export default class App extends Component {
  state = {
    progress: 10
  };

  handleSlide = newProgress => this.setState({ progress: newProgress });

  render() {
    return (
      <MultiSlider onSlide={this.handleSlide}>
        <Progress color="green" progress={this.state.progress} />
        <Progress color="purple" progress={45} />
      </MultiSlider>
    );
  }
}

Advanced example

import MultiSlider, { Progress, Dot } from 'react-multi-bar-slider';

export default class App extends Component {
  state = {
    progress: 10
  };

  handleSlide = newProgress => this.setState({ progress: newProgress });

  render() {
    return (
      <MultiSlider
        width={600}
        height={20}
        slidableZoneSize={40}
        backgroundColor="bisque"
        equalColor="blue"
        style={{ marginBottom: 40 }}
        onSlide={this.handleSlide}
        onDragStart={progress => console.log(`Started dragging: ${progress}%`)}
        onDragStop={progress => console.log(`Stopped dragging: ${progress}%`)}
        roundedCorners
        reversed
      />
        <Progress color="green" progress={this.state.progress}>
          <Dot color="grey" />
        </Progress>
        <Progress color="purple" progress={45}>
          <Dot color="grey" />
        </Progress>
      </MultiSlider>
    );
  }
}

Props

* = Required

MultiSlider

PropDescriptionTypeDefault
widthWidth of the slidernumber or string100%
heightHeight of the slidernumber or string14px
slidableZoneSizeSize of the zone in which sliders can be draggednumber or string7px,
backgroundColorBackground color of the sliderstring#EEEEEE
equalColorColor of all bars when their values are equalstring
styleCustom style for the slider Signature: function(props: object) => objectobject or function{}
onSlideCallback that is fired when the progress was set Signature: function(progress: number) => voidfunction
onDragStartCallback function that is fired when the slider has begun to move Signature: function(progress: number) => voidfunction
onDragStopCallback function that is fired when the slide has stopped moving Signature: function(progress: number) => voidfunction
roundedCornersWhen set to true, the slider has rounded cornersboolfalse
reversedWhen set to true, the slider is reversedboolfalse
readOnlyWhen set to true, the slider can't be updatedboolfalse
children*The progress bars that are shown in the slider (or any other children)node

All other props (not documented here) will be passed on to the root element.

Progress

PropDescriptionTypeDefault
color*Color of the progress barstring
progress*Progress of the progress barnumber
styleCustom style for the progress bar Signature: function(props: object) => objectobject or function
childrenThe slider dot (or any other children)node

All other props (not documented here) will be passed on to the root element.

Dot

PropDescriptionTypeDefault
widthWidth of the dotnumber or string50 when the dot has an icon, 28 if not
heightHeight of the dotnumber or string50 when the dot has an icon, 28 if not
colorColor of the dotstring
iconURL of the image to use as dot iconstring
styleCustom style for the dot Signature: function(props: object) => objectobject or function
iconStyleCustom style for the dot icon Signature: function(props: object) => objectobject or function
childrenChildren of the dotnode

All other props (not documented here) will be passed on to the root element.

How custom styles work

When a function is passed to a style prop rather than an object, it is expected to return an object. The style function will be called with all props that that component has (except for the style and children props and any internal callbacks). The return value of the function will be used as style (see the demo repo for an example).

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago