react-spring-slider
- General
- Installation
- Usage
- Configuration
- Contribution
General
This is a slider which uses react-spring under
the hood.
This project aims to be flexible through configuration as well as be easy to use
by sane and reasonable defaults.
You can have a real life look how this can be used within storybook at:
farbenmeer.github.io/react-spring-slider.
Installation
yarn add @farbenmeer/react-spring-slider
npm install --save @farbenmeer/react-spring-slider
Usage
The module provides a default export which you can import and use in your own
component.
import Slider from '@farbenmeer/react-spring-slider';
const App = () => {
return (
<Slider>
<div>child 1</div>
<div>child 2</div>
<div>child 3</div>
</Slider>
)
}
The slider can gain any children as long as there are a react node, so you can
show images, text or some more complex components.
Configuration
The slider currently provides the following interface:
activeIndex: PropTypes.number,
ArrowComponent: PropTypes.func,
arrowStyle: PropTypes.objectOf(PropTypes.string),
auto: PropTypes.number,
BulletComponent: PropTypes.func,
bulletStyle: PropTypes.objectOf(PropTypes.string),
children: PropTypes.node,
hasBullets: PropTypes.bool,
onSlideChange: PropTypes.func
Some option examples:
import Slider from '@farbenmeer/react-spring-slider';
const App = () => {
const onSlideChange = index => console.log(`changed to slide ${index}`);
const BulletComponent = ({onClick, isActive}) => (
<li
style={{
width: '25px',
height: '25px',
backgroundColor: 'red',
margin: '0 2px',
opacity: isActive && '0.5'
}}
onClick={onClick}
/>
);
BulletComponent.propTypes = {
onClick: PropTypes.func.isRequired,
isActive: PropTypes.bool.isRequired
};
const ArrowComponent = ({onClick, direction}) => {
return (
<div
style={{
border: '1px solid black',
padding: '1em',
backgroundColor: 'white'
}}
onClick={onClick}
>
{direction}
</div>
);
};
ArrowComponent.propTypes = {
onClick: PropTypes.func.isRequired,
direction: PropTypes.string.isRequired
};
return (
<Slider
activeIndex={2}
auto
hasBullets
BulletComponent={BulletComponent}
ArrowComponent={ArrowComponent}
onSlideChange={onSlideChange}
>
<div>child 1</div>
<div>child 2</div>
<div>child 3</div>
</Slider>
)
}
Only a different bulletStyle:
<Slider hasBullets bulletStyle={{backgroundColor: '#fff'}}>
<MySlide />
<MySlide />
<MySlide />
</Slider>
Contribution
See CONTRIBUTING.md