GithubHelp home page GithubHelp logo

zoltan-mihalyi / react-compare-slider Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nerdyman/react-compare-slider

0.0 0.0 0.0 7.35 MB

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

Home Page: https://react-compare-slider.vercel.app

License: MIT License

Shell 0.51% JavaScript 1.76% TypeScript 97.73%

react-compare-slider's Introduction

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

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

Prop Type Required Default Description
boundsPadding number 0 Padding to limit the slideable bounds in pixels on the X-axis (landscape) or Y-axis (portrait).
changePositionOnHover boolean false Whether the slider should follow the pointer on hover.
disabled boolean false Whether to disable slider movement (items are still interactable).
handle ReactNode undefined Custom handle component.
itemOne ReactNode undefined First component to show in slider.
itemTwo ReactNode undefined Second component to show in slider.
keyboardIncrement number|`${number}%` 5% Percentage or pixel amount to move when the slider handle is focused and keyboard arrow is pressed.
onlyHandleDraggable boolean false Whether to only change position when handle is interacted with (useful for touch devices).
onPositionChange function undefined Callback on position change, returns current position percentage as argument (position) => { ... }.
portrait boolean false Whether to use portrait orientation.
position number 50 Initial percentage position of divide (0-100).
transition string undefined Shorthand 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

react-compare-slider's People

Contributors

nerdyman avatar raphaelts3 avatar dependabot[bot] avatar jsberlanga avatar tenpi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.