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

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

  • 0.1.2
  • Source
  • npm
  • Socket score

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

License npm npm bundle size Build Status

React Compare Slider

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

Features

  • Supports responsive images, videos, any React components
  • Supports landscape and portrait orientations
  • Simple API
  • Responsive, fluid
  • Fully customisable
  • Works in IE11+
  • Teeny-tiny, only one ponyfill dependency
  • Type safe

Demo

Usage

Install

yarn add react-compare-slider
# OR
npm install react-compare-slider

Use it!

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

<ReactCompareSlider
    itemOne={<img src="..." alt="Image one" />}
    itemTwo={<img src="..." alt="Image two" />}
/>

Props & docs

Props

PropTypeRequiredDefault valueDescription
handleReactNodeundefinedCustom handle component
itemOneReactNodeundefinedFirst component to show in slider
itemTwoReactNodeundefinedSecond component to show in slider
onChangefunctionundefinedCallback on position change, returns current position as argument (position) => { ... }
positionnumber50Initial percentage position of divide (0-100)
portraitbooleanundefinedWhether to use portrait orientation

ReactCompareSliderImage

ReactCompareSliderImage is a standalone image component that detects whether the browser supports the object-fit CSS property, if not it will apply a background image to achieve the same effect. It calls styleFitContainer internally and will set background-size, background-position and background-image if they have not already been defined in a passed style prop.

Props

ReactCompareSliderImage supports all attributes assignable to an img component, in addition to the following:

PropTypeRequiredDefault valueDescription
fallbackEnablebooleantrueWhether to enable fallback background
Example

Standalone:

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

// `src` will be used as background image on unsupported browsers
<ReactCompareSliderImage src="..." />

// `backgroundImage` will be used as background image on unsupported browsers
<ReactCompareSliderImage src="..." style={{ backgroundImage: 'url(...)' }} />

Within slider:

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

<ReactCompareSlider
    itemOne={<ReactCompareSliderImage src="..." alt="Image one" />}
    itemTwo={<ReactCompareSliderImage src="..." alt="Image two" />}
/>

styleFitContainer

The styleFitContainer utility makes any child media component (img, picture, video, etc.) fill its parent and maintain the correct aspect ratio. It returns a React style object and accepts a CSS object as an argument and defaults to object-fit to cover.

Example

Fill a full width/height container:

import { styleFitContainer } from 'react-compare-slider';

// ...

<div style={{ width: '100vw', height: '100vh' }}>
    <video 
        style={{ 
            ...styleFitContainer({
                objectFit: 'contain', 
                objectPosition: 'center',
            }) 
        }} 
        // ...
    />
</div>

Notes

Bootstrapped with TSDX.

FAQs

Package last updated on 06 Oct 2019

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