3.1.0 • Published 17 days ago

react-compare-slider v3.1.0

Weekly downloads
2,088
License
MIT
Repository
github
Last release
17 days ago

Example


Features

  • Supports responsive images and any other React components (picture, video, canvas, iframe etc.)
  • Supports landscape and portrait orientations
  • Accessible screen reader and keyboard support out of the box
  • Simple API
  • Unopinionated & fully customizable optionally use your own components and styles
  • Responsive & fluid with intrinsic sizing
  • Teeny-tiny, zero dependencies
  • Type safe

Demos

Usage

Install

npm install react-compare-slider
# or
yarn add react-compare-slider
# or
pnpm add react-compare-slider

Basic Image Usage

You may use ReactCompareSliderImage to render images or use your own custom components.

import { ReactCompareSlider, ReactCompareSliderImage } from 'react-compare-slider';

export const Example = () => {
  return (
    <ReactCompareSlider
      itemOne={<ReactCompareSliderImage src="..." srcSet="..." alt="Image one" />}
      itemTwo={<ReactCompareSliderImage src="..." srcSet="..." alt="Image two" />}
    />
  );
};

Props

PropTypeRequiredDefaultDescription
boundsPaddingnumber0Padding to limit the slideable bounds in pixels on the X-axis (landscape) or Y-axis (portrait).
browsingContextglobalThisglobalThisContext to bind events to (useful for iframes).
changePositionOnHoverbooleanfalseWhether the slider should follow the pointer on hover.
disabledbooleanfalseWhether to disable slider movement (items are still interactable).
handleReactNodeundefinedCustom handle component.
itemOneReactNodeundefinedFirst component to show in slider.
itemTwoReactNodeundefinedSecond component to show in slider.
keyboardIncrementnumber\|`${number}%`5%Percentage or pixel amount to move when the slider handle is focused and keyboard arrow is pressed.
onlyHandleDraggablebooleanfalseWhether to only change position when handle is interacted with (useful for touch devices).
onPositionChange(position: number) => voidundefinedCallback on position change, returns current position percentage as argument.
portraitbooleanfalseWhether to use portrait orientation.
positionnumber50Initial percentage position of divide (0-100).
transitionstringundefinedShorthand CSS transition property to apply to handle movement. E.g. .5s ease-in-out

API docs for more information.

Real World Examples

Checkout out the Real World Examples page.

Requirements

  • React 16.8+
  • The latest two versions of each major browser are officially supported
3.1.0

17 days ago

3.0.2-1

25 days ago

3.0.2-0

3 months ago

3.0.0-beta.1

6 months ago

3.0.0-beta.0

6 months ago

3.0.0-beta.3

6 months ago

3.0.0-beta.2

6 months ago

3.0.0-beta.4

6 months ago

3.0.1

6 months ago

3.0.0

6 months ago

2.2.0

2 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.2.1

3 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1-rc.1

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

2.0.0

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago