Files
web/apps/scandic-web/components/Countdown/index.tsx
Bianca Widstam 68c1b3dc50 Merged in chore/BOOK-708-replace-title-component (pull request #3414)
Chore/BOOK-708 replace title component

* chore(BOOK-708): replace title with typography

* chore(BOOK-708): replace title with typography

* chore(BOOK-708): remove Title from package.json


Approved-by: Linus Flood
Approved-by: Anton Gunnarsson
2026-01-12 07:54:59 +00:00

38 lines
953 B
TypeScript

"use client"
import { useState } from "react"
import { useInterval } from "usehooks-ts"
import { dt } from "@scandic-hotels/common/dt"
import { Typography } from "@scandic-hotels/design-system/Typography"
import styles from "./countdown.module.css"
import type { CountdownProps } from "@/types/components/countdown"
export default function Countdown({
minutes = 30,
seconds = 0,
onChange = () => undefined,
}: CountdownProps) {
const [time, setTime] = useState(dt.duration({ minutes, seconds }))
const timeSeconds = time.asSeconds()
useInterval(
() => {
setTime((currentTime) => {
const newTime = currentTime.asMilliseconds() - 1000
onChange(newTime)
return dt.duration(newTime)
})
},
timeSeconds > 0 ? 1000 : null
)
return (
<Typography variant="Title/lg" className={styles.title}>
<time dateTime={time.toISOString()}>{time.format("m:ss")}</time>
</Typography>
)
}