import classNames from 'classnames'
import React from 'react'
export const TimeDisplay = (props: {
seconds: number
minutes: number
hours: number
days: number
className?: string
colonYOffset?: number
getTimeColorClassName?: (time: {
seconds: number
minutes: number
hours: number
days: number
}) => string
backgroundColorClassName?: string
unitsColorClassName?: string
timeClassName?: string
unitsClassName?: string
noColors?: boolean
hideSeconds?: boolean
hideMinutes?: boolean
hideHours?: boolean
hideDays?: boolean
}) => {
const {
seconds,
minutes,
hours,
days,
noColors,
className,
colonYOffset,
getTimeColorClassName,
hideDays,
hideHours,
hideMinutes,
hideSeconds,
backgroundColorClassName,
timeClassName,
unitsClassName,
unitsColorClassName
} = props
const textClassName = noColors
? undefined
: getTimeColorClassName({ seconds, minutes, hours, days })
if (
(seconds === null || seconds === undefined) &&
(minutes === null || minutes === undefined) &&
(hours === null || hours === undefined) &&
(days === null || days === undefined)
) {
return null
}
return (
{!hideDays && (
)}
{!hideHours && (
)}
{!hideMinutes && (
)}
{!hideSeconds && (
)}
)
}
const getTimeColorClassName = (time: { seconds; minutes; hours; days }) => {
const { days, hours, minutes } = time
if (days <= 0 && hours <= 0 && minutes <= 60) {
return 'text-pt-red'
} else if (days <= 0 && hours <= 8) {
return 'text-orange'
} else {
return 'text-gradient-magenta'
}
}
TimeDisplay.defaultProps = {
hideColors: false,
timeClassName: 'text-sm xs:text-xs sm:text-base',
unitsClassName: 'text-xxxs',
getTimeColorClassName
}
const Colon = (props: { className?: string; yOffset: number }) => (
:
)
const TimeUnit = (props: {
amount: number
unit: string
className?: string
exactDigits?: boolean
textClassName?: string
backgroundColorClassName?: string
timeClassName?: string
unitsClassName?: string
unitsColorClassName?: string
}) => {
const {
amount,
unit,
exactDigits,
textClassName,
className,
backgroundColorClassName,
timeClassName,
unitsClassName,
unitsColorClassName
} = props
const amounts = String(amount).split('')
if (!exactDigits && amounts.length === 1) {
amounts.unshift('0')
}
return (
{amounts.map((amount, index) => (
))}
{unit}
)
}
TimeUnit.defaultProps = {
exactDigits: false,
backgroundColorClassName: 'bg-pt-purple-darkest bg-opacity-10 dark:bg-white dark:bg-opacity-10',
unitsColorClassName:
'text-pt-purple-darkest text-opacity-50 dark:text-white dark:text-opacity-50',
unitsClassName: 'text-xxxs'
}
const TimeDigit = (props: {
amount: string
className?: string
backgroundColorClassName?: string
}) => (
{props.amount}
)
TimeDigit.defaultProps = {
backgroundColorClassName: 'bg-tertiary'
}