13.0.0 • Published 1 year ago

@tordek/rc-slider v13.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

rc-slider

Slider UI component for React

Forked off rc-slider to add support for passing classNames to parts of the slider.

NPM version build status Test coverage npm download bundle size

Install

@tordek/rc-slider

Example

npm start and then go to http://localhost:8000

Online examples: https://slider.react-component.now.sh/

Usage

import Slider from '@tordek/rc-slider';
import 'rc-slider/assets/index.css';

export default () => (
  <>
    <Slider />
    <Slider range />
  </>
);

Compatibility

IE / EdgeFirefoxChromeSafariElectron
IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

API

createSliderWithTooltip(Slider | Range) => React.Component

An extension to make Slider or Range support Tooltip on handle.

const Slider = require('@tordek/rc-slider');
const createSliderWithTooltip = Slider.createSliderWithTooltip;
const Range = createSliderWithTooltip(Slider.Range);

Online demo

After Range or Slider was wrapped by createSliderWithTooltip, it will have the following props:

NameTypeDefaultDescription
tipFormatter(value: number): React.ReactNodevalue => valueA function to format tooltip's overlay
tipPropsObject{ placement: 'top', prefixCls: 'rc-slider-tooltip', overlay: tipFormatter(value) }A function to format tooltip's overlay

Common API

The following APIs are shared by Slider and Range.

NameTypeDefaultDescription
classNamestring''Additional CSS class for the root DOM node
minnumber0The minimum value of the slider
maxnumber100The maximum value of the slider
marks{number: ReactNode} or{number: { style, label }}{}Marks on the slider. The key determines the position, and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which contains style and label properties.
stepnumber or null1Value to be added or subtracted on each step the slider makes. Must be greater than zero, and max - min should be evenly divisible by the step value. When marks is not an empty object, step can be set to null, to make marks as steps.
verticalbooleanfalseIf vertical is true, the slider will be vertical.
handle(props) => React.ReactNodeA handle generator which could be used to customized handle.
includedbooleantrueIf the value is true, it means a continuous value interval, otherwise, it is a independent value.
reversebooleanfalseIf the value is true, it means the component is rendered reverse.
disabledbooleanfalseIf true, handles can't be moved.
dotsbooleanfalseWhen the step value is greater than 1, you can set the dots to true if you want to render the slider with dots.
onChangeFunctionNOOPonChange will be triggered while the value of Slider changing.
*ClassNamestring | string[]variesHTML class property for different elements in the slider

Slider

NameTypeDefaultDescription
defaultValuenumber0Set initial value of slider.
valuenumber-Set current value of slider.
startPointnumberundefinedTrack starts from this value. If undefined, min is used.
tabIndexnumber0Set the tabIndex of the slider handle.
ariaLabelForHandlestring-Set the aria-label attribute on the slider handle.
ariaLabelledByForHandlestring-Set the aria-labelledby attribute on the slider handle.
ariaValueTextFormatterForHandle(value) => string-A function to set the aria-valuetext attribute on the slider handle. It receives the current value of the slider and returns a formatted string describing the value. See WAI-ARIA Authoring Practices 1.1 for more information.

Range

NameTypeDefaultDescription
defaultValuenumber[][0, 0]Set initial positions of handles.
valuenumber[]Set current positions of handles.
tabIndexnumber[][0, 0]Set the tabIndex of each handle.
ariaLabelGroupForHandlesArraystring-Set the aria-label attribute on each handle.
ariaLabelledByGroupForHandlesArraystring-Set the aria-labelledby attribute on each handle.
ariaValueTextFormatterGroupForHandlesArray(value) => string-A function to set the aria-valuetext attribute on each handle. It receives the current value of the slider and returns a formatted string describing the value. See WAI-ARIA Authoring Practices 1.1 for more information.
countnumber1Determine how many ranges to render, and multiple handles will be rendered (number + 1).
allowCrossbooleantrueallowCross could be set as true to allow those handles to cross.
pushableboolean or numberfalsepushable could be set as true to allow pushing of surrounding handles when moving a handle. When set to a number, the number will be the minimum ensured distance between handles. Example: npm.io
draggableTrackbooleanfalseOpen the track drag. open after click on the track will be invalid.

SliderTooltip

The Tooltip Component that keep following with content.

Development

npm install
npm start

Test Case

npm run test

Coverage

npm run coverage

License

@tordek/rc-slider is released under the MIT license.

13.0.0

1 year ago

12.2.0

1 year ago

12.1.4

1 year ago

12.1.3

2 years ago

12.1.2

2 years ago

12.1.1

2 years ago

12.1.0

2 years ago

12.0.1

2 years ago

12.0.0

2 years ago

11.0.6

2 years ago

11.0.5

2 years ago

11.0.4

2 years ago