Socket
Socket
Sign inDemoInstall

rc-slider

Package Overview
Dependencies
17
Maintainers
9
Versions
176
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-slider

Slider UI component for React


Version published
Weekly downloads
1.8M
increased by6.85%
Maintainers
9
Install size
2.58 MB
Created
Weekly downloads
 

Package description

What is rc-slider?

The rc-slider npm package is a React component that allows users to implement slider functionality in their web applications. It provides a range of sliders, including basic sliders, range sliders, and sliders with custom handles and tracks. It is customizable and supports various configurations such as vertical orientation, marks, step adjustments, and more.

What are rc-slider's main functionalities?

Basic Slider

This code sample demonstrates how to create a basic horizontal slider with a default value set to 30.

import React from 'react';
import Slider from 'rc-slider';
import 'rc-slider/assets/index.css';

const BasicSlider = () => (
  <Slider defaultValue={30} />
);

export default BasicSlider;

Range Slider

This code sample shows how to create a range slider that allows users to select a value range. The default selected range is from 20 to 50.

import React from 'react';
import { Range } from 'rc-slider';
import 'rc-slider/assets/index.css';

const RangeSlider = () => (
  <Range defaultValue={[20, 50]} />
);

export default RangeSlider;

Slider with Marks

This code sample illustrates a slider with marks at specified values. It also shows how to style individual marks and use React components as labels.

import React from 'react';
import Slider from 'rc-slider';
import 'rc-slider/assets/index.css';

const marks = {
  0: '0°C',
  26: '26°C',
  37: '37°C',
  100: {
    style: {
      color: 'red',
    },
    label: <strong>100°C</strong>,
  },
};

const MarkedSlider = () => (
  <Slider marks={marks} defaultValue={37} step={null} />
);

export default MarkedSlider;

Vertical Slider

This code sample demonstrates how to create a vertical slider by setting the 'vertical' prop. The slider is contained within a div that specifies its height.

import React from 'react';
import Slider from 'rc-slider';
import 'rc-slider/assets/index.css';

const VerticalSlider = () => (
  <div style={{ height: 200, marginLeft: 50 }}>
    <Slider vertical defaultValue={30} />
  </div>
);

export default VerticalSlider;

Other packages similar to rc-slider

Readme

Source

rc-slider

Slider UI component for React

NPM version dumi build status Test coverage Dependencies DevDependencies npm download bundle size

Install

rc-slider

Example

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

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

Usage

import Slider, { Range } from 'rc-slider';
import 'rc-slider/assets/index.css';

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

Compatibility

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Electron
Electron
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('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.
onBeforeChangeFunctionNOOPonBeforeChange will be triggered when ontouchstart or onmousedown is triggered.
onChangeFunctionNOOPonChange will be triggered while the value of Slider changing.
onAfterChangeFunctionNOOPonAfterChange will be triggered when ontouchend or onmouseup is triggered.
minimumTrackStyleObjectplease use trackStyle instead. (only used for slider, just for compatibility , will be deprecate at rc-slider@9.x )
maximumTrackStyleObjectplease use railStyle instead (only used for slider, just for compatibility , will be deprecate at rc-slider@9.x)
handleStyleArray[Object] | Object[{}]The style used for handle. (both for slider(Object) and range(Array of Object), the array will be used for multi handle following element order)
trackStyleArray[Object] | Object[{}]The style used for track. (both for slider(Object) and range(Array of Object), the array will be used for multi track following element order)
railStyleObject{}The style used for the track base color.
dotStyleObject{}The style used for the dots.
activeDotStyleObject{}The style used for the active dots.

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.
ariaLabelGroupForHandlesArray[string]-Set the aria-label attribute on each handle.
ariaLabelledByGroupForHandlesArray[string]-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:
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

rc-slider is released under the MIT license.

Keywords

FAQs

Last updated on 12 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc