import React from 'react'; import { TransitionGroup, CSSTransition } from 'react-transition-group'; import { HardwareWallets, Coinbase, Bity } from './PromoComponents'; import './Promos.scss'; const promos = [HardwareWallets, Coinbase, Bity]; const CarouselAnimation = ({ children, ...props }) => ( {children} ); interface State { activePromo: number; } export default class Promos extends React.PureComponent<{}, State> { public timer: any = null; public state = { activePromo: parseInt(String(Math.random() * promos.length), 10) }; public componentDidMount() { this.timer = setInterval(() => this.rotate(), 10000); } public componentWillUnmount() { clearInterval(this.timer); } public render() { const { activePromo } = this.state; return (
{promos .filter(i => { return i === promos[activePromo]; }) .map(promo => {promo})}
{promos.map((_, index) => { return (
); } private navigateToPromo = (idx: number) => () => { // stop rotating when user begins interacting with promos clearInterval(this.timer); this.setState({ activePromo: Math.max(0, Math.min(promos.length, idx)) }); }; private rotate = () => { const activePromo = (this.state.activePromo + 1) % promos.length; this.setState({ activePromo }); }; }