import React, { Fragment } from 'react'; import styled from 'styled-components'; import ReactCountdown from 'react-countdown-now'; import * as tokens from '@tokens'; import { dim } from '@dim'; import { H4, Numeral, Anchor } from '@Typography'; import Button from '@Components/Button'; import { CountdownProps, ButtonInterface } from './interface'; const StyledArticle = styled.article` width: 100%; position: relative; img { width: 100%; } `; const StyledContentWrapper = styled.div` width: 100%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: ${({ dark }: { dark: boolean }) => (dark ? tokens.colorBlack : tokens.colorWhite)}; text-align: center; a { color: ${({ dark }: { dark: boolean }) => (dark ? tokens.colorBlack : tokens.colorWhite)}; } `; const StyledTimer = styled.div``; const CountdownFigure = styled(Numeral)` ${({ dark }: { dark: boolean }) => { const color = dark ? tokens.colorBlack : tokens.colorWhite; const thickness = '2px'; return ` display: inline-block; margin: 0; @supports (-webkit-text-stroke: ${thickness} ${color}) { { color: transparent; -webkit-text-stroke: ${thickness} ${color}; text-shadow: none; } } @supports not (-webkit-text-stroke: ${thickness} ${color}) { color: ${color}; } `; }} `; const StyledButton = styled(Button)` margin-top: ${dim(6)}; `; const StyledH4 = styled(H4)` margin-top: 0; `; const StyledAnchor = styled(Anchor)` margin-top: ${dim(3)}; display: inline-block; `; const LinkButton = (button: ButtonInterface) => { if (button.onClick) { return ( // {button.text} ); } if (button.href) { return {button.text}; } return null; }; const setDigit = (n: number) => (n > 9 ? '' + n : '0' + n); const Countdown: React.FC = ({ title, endTime, button, assetSrc, dark = false, timeFinishedMessage }) => { return ( {title} {title} ( {setDigit(days) || '00'} :  {setDigit(hours) || '00'} :  {setDigit(minutes) || '00'} :  {setDigit(seconds)} )} >

{timeFinishedMessage}

{button && LinkButton(button)}
); }; export default Countdown;