CountdownTimerSpan.tsx 1004 B

1234567891011121314151617181920212223242526272829
  1. import MotionNumber from '@number-flow/react'
  2. interface CountdownTimerSpanProps {
  3. seconds: number
  4. }
  5. const CountdownTimerSpan = ({ seconds }: CountdownTimerSpanProps) => {
  6. const hours = Math.floor(seconds / 3600)
  7. const minutes = Math.floor((seconds % 3600) / 60)
  8. const remainingSeconds = seconds % 60
  9. const formatConfig = { minimumIntegerDigits: 2 }
  10. const formatValue = (value: number) => value.toString().padStart(2, '0')
  11. return (
  12. <span className="inline-flex gap-2">
  13. <span className="text-foreground-lighter text-sm p-0">Time remaining: </span>
  14. <span className="text-foreground text-sm font-mono flex items-center gap-0">
  15. <MotionNumber format={formatConfig} value={Number(formatValue(hours))} />
  16. hr
  17. <MotionNumber format={formatConfig} value={Number(formatValue(minutes))} />
  18. m
  19. <MotionNumber format={formatConfig} value={Number(formatValue(remainingSeconds))} />
  20. </span>
  21. </span>
  22. )
  23. }
  24. export default CountdownTimerSpan