Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-compare-slider

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-compare-slider

A slider component to compare any two React components in landscape or portrait orientation. It supports custom images, videos... and everything else.

  • 3.0.0-beta.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40K
increased by3.41%
Maintainers
1
Weekly downloads
 
Created
Source

React Compare Slider

Compare two components side-by-side or top-to-toe.

Example

License MIT npm version Bundle size
GitHub CI status Coverage Demos


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

Demo

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" />}
    />
  );
};

See the Images docs for more information and demos.

Props

PropTypeRequiredDefaultDescription
boundsPaddingnumber0Padding to limit the slideable bounds in pixels on the X-axis (landscape) or Y-axis (portrait).
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).
onPositionChangefunctionundefinedCallback on position change, returns current position percentage as argument (position) => { ... }.
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

Requirements

Keywords

FAQs

Package last updated on 21 Oct 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc