import React, { Fragment } from 'react'; import useTimer from '../hooks/UseTimer'; import './PDPTSTimer.scss'; import ClockIcon from '@moda/icons/clock-16'; interface Props { countdownTime: number; countdownEndMessage: string; endingText?: string; hasZeroes?: boolean; hasIcon?: boolean; } export const PDPTSTimer: React.FC = ({ hasZeroes, countdownTime, countdownEndMessage, hasIcon, }) => { const [timeLeft] = useTimer(countdownTime, hasZeroes); const showTimer = parseInt(timeLeft.daysLeft, 10) < 40; const timerStyle = parseInt(timeLeft.daysLeft, 10) <= 3 ? 'PDPTSTimer PDPTSTimer--ending-soon' : 'PDPTSTimer'; return (
{timeLeft.isOver && ( {countdownEndMessage} )} {!timeLeft.isOver && showTimer && ( {hasIcon && } Ends in {timeLeft.daysLeft + 'd'} {timeLeft.hoursLeft + 'h'} {timeLeft.minutesLeft + 'm'} )}
); };