1 import PropTypes from 'prop-types';
2 import React from 'react';
4 const Slider = ({ children, duration, vertical }) => {
5 const [index, setIndex] = React.useState(0);
7 React.useEffect(() => {
8 const interval = setInterval(() => {
9 setIndex(i => (i + 1) % React.Children.count(children));
12 clearInterval(interval);
14 }, [React.Children.count(children), duration]);
16 return <div className={`slider-container ${vertical ? 'vertical' : 'horizontal'}`}>
17 <div className="slider-slides" style={{
18 transform: vertical ? `translateY(${-index * 100}%)` : `translateX(${-index * 100}%)`
26 children: PropTypes.node,
27 duration: PropTypes.number,
28 vertical: PropTypes.bool,
31 Slider.defaultProps = {
35 const Slide = ({ children }) => {
36 return <div className="slider-slide">
42 children: PropTypes.node,
47 export default Slider;