import { Component, createSignal, onMount, onCleanup } from "solid-js"; interface CountdownCircleTimerProps { duration: number; initialRemainingTime: number; size: number; strokeWidth: number; colors: string; children: (time: number) => any; onComplete?: () => void; } const CountdownCircleTimer: Component = (props) => { const radius = (props.size - props.strokeWidth) / 2; const circumference = radius * 2 * Math.PI; const [remainingTime, setRemainingTime] = createSignal( props.initialRemainingTime ); // Calculate progress (0 to 1) const progress = () => remainingTime() / props.duration; const strokeDashoffset = () => circumference * (1 - progress()); onMount(() => { const interval = setInterval(() => { setRemainingTime((prev) => { const newTime = prev - 1; if (newTime <= 0) { clearInterval(interval); props.onComplete?.(); return 0; } return newTime; }); }, 1000); onCleanup(() => { clearInterval(interval); }); }); return (
{/* Background circle */} {/* Progress circle */} {/* Timer text in center */}
{props.children(remainingTime())}
); }; export default CountdownCircleTimer;