1.1.8 • Published 1 year ago

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

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

React node before after slider component

Simple slider component for comparing images. Before and after. This is a fork of https://github.com/smeleshkin/react-before-after-slider-component

screencast demo

Demo

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

Build

npm run build:npm

Basic usage

npm install react-node-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}
/>
/* ... */
/* or you can use a component*/

const FIRST_COMPONENT = <GatsbyImage image={firstImage.gatsbyImage} alt={firstImage.alt} />;
const SECOND_COMPONENT = <GatsbyImage image={secondImage.gatsbyImage} alt={secondImage.alt} />;

<ReactBeforeSliderComponent
    firstComponent={FIRST_COMPONENT}
    secondComponent={SECOND_COMPONENT}
/>
/* ... */

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.
onChangePercentPositionfalsefunctionOn delimiter position update callback. Has new position parameter.
feelsOnlyTheDelimiterfalsefunctionfalseOnly 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"
firstComponentfalseReactNodeA component like GatsbyImage to use a component instead of imageUrl
secondComponentfalseReactNodeA component like GatsbyImage to use a component instead of imageUrl

Specific Types

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

Custom logo example

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