1
0
mirror of https://github.com/Fayorg/calendrier-avant.git synced 2026-05-27 17:18:38 +02:00

added a timer with custom end alarm sounf

This commit is contained in:
timhaller
2023-12-15 14:52:46 +01:00
parent 47e1204be7
commit f0665d8e42
7 changed files with 64 additions and 4 deletions

View File

@@ -0,0 +1,43 @@
"use client";
import React from 'react';
import { useTimer } from 'react-timer-hook';
import { Button } from "@components/ui/button";
import { PauseIcon, Play} from "lucide-react";
interface MyTimerProps {
expiryTimestamp: Date;
onEnd?: () => void;
}
export default function MyTimer({ expiryTimestamp, onEnd } : MyTimerProps) {
const {
seconds,
minutes,
isRunning,
pause,
resume,
} = useTimer({
expiryTimestamp,
onExpire: () => onEnd && onEnd()
})
return (
<div className={"text-white text-center flex flex-col"}>
<div className={"font-bold text-8xl"}>
<span>{String(minutes).padStart(2, "0")}</span>:
<span>{String(seconds).padStart(2, "0")}</span>
</div>
<p>{isRunning ? 'Running' : 'Not running'}</p>
<div className={"self-center flex gap-4"}>
<Button onClick={pause} disabled={!isRunning}>
<PauseIcon/>
</Button>
<Button onClick={resume} disabled={isRunning}>
<Play/>
</Button>
</div>
</div>
);
}