1.1.8 • Published 1 year ago

react-before-after-slider-component v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React before after slider component

Simple slider component for comparing images. Before and after.

screencast demo

Demo

https://smeleshkin.github.io/react-before-after-slider-component/

Build

npm run build:npm

Basic usage

npm install react-before-after-slider-component --save

Then use it in your app:

import React from 'react';
import ReactBeforeSliderComponent from 'react-before-after-slider-component';
import 'react-before-after-slider-component/dist/build.css';

const FIRST_IMAGE = {
  imageUrl: 'https://example.com/.../some-image.jpg'
};
const SECOND_IMAGE = {
  imageUrl: 'https://example.com/.../some-image-2.jpg'
};
/* ... */
<ReactBeforeSliderComponent
    firstImage={FIRST_IMAGE}
    secondImage={SECOND_IMAGE}
/>
/* ... */

Props

AttributeRequiredTypeDefaultDescription
firstImagetrueImageImage object with source url.
secondImagetrueImageImage object with source url.
delimiterColorfalsestring#fffCustom delimiter background color.
currentPercentPositionfalsenumber50Start delimiter position. Or also the current position, if it will change in parent.
classNamefalsestringCustom classname.
withResizeFeelfalsebooleantrueFeeling to window resizing.
onReadyfalsefunctionOn slider ready callback.
onVisiblefalsefunctionOn slider visible in viewport callback.
onChangePercentPositionfalse(newPosition: number) => voidOn delimiter position update callback. Has new position parameter.
feelsOnlyTheDelimiterfalsebooleanfalseOnly the separator feels clicks. Not any zone of the component.
delimiterIconStylesfalseReact.CSSPropertiesCustom styles of delimiter icon. E.g. for a logo. See "Custom logo example".
onChangeModefalse(newMode: MODE) => voidCallback when the slider mode changes. Can be used to disable page scrolling on touch devices while sliding.

Specific Types

interface Image {
    imageUrl: string,
    alt?: string,
}

export enum MODE {
    MOVE = 'move', // Moving the slider
    DEFAULT = 'default', // Resting state
}

Custom logo example

// Pass this as a delimiterIconStyles property
const delimiterIconStyles = {
   width: '50px',
   height: '50px',
   backgroundSize: 'cover',
   borderRadius: 'none',
   backgroundImage: 'url(<some-path-here>)'
}
1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.3

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago