An independent integration of @stephanluis/react-input-duration
and react-countdown-circle-timer.
The duration input sits inside an animated countdown circle. While running, the circle shows
the remaining time; after completion it shows “Too late ...”. Applications provide their own buttons.
npm install @stephanluis/react-countdown-circle-timer-editableReact 18.2 or 19 and React DOM are required.
import { useRef, useState } from 'react';
import EditableCircleCountdown from '@stephanluis/react-countdown-circle-timer-editable';
function TimerExample() {
const timer = useRef(null);
const [running, setRunning] = useState(false);
const [completed, setCompleted] = useState(false);
const [status, setStatus] = useState('Ready.');
function start() {
try {
timer.current.start();
} catch (error) {
setStatus(error.message);
}
}
return <>
<EditableCircleCountdown ref={timer} initialValue="0:00:00:10.000"
onStart={() => { setCompleted(false); setRunning(true); setStatus('Countdown running.'); }}
onStop={() => { setRunning(false); setStatus('Countdown stopped.'); }}
onComplete={() => { setRunning(false); setCompleted(true); setStatus('Countdown complete.'); }} />
<button type="button" onClick={running ? () => timer.current.stop() : completed
? () => { timer.current.edit(); setCompleted(false); setStatus('Ready.'); } : start}>
{running ? 'Stop' : completed ? 'Edit' : 'Start'}
</button>
<p role="status">{status}</p>
</>;
}initialValue accepts HH:mm:ss.SSS or D:HH:mm:ss.SSS and is used only on mount.
start() uses the last committed duration and throws if the input is not ready, invalid, zero,
or outside JavaScript's safe integer and date ranges. stop() preserves the remaining duration
for editing. Each method returns true when it acts and false if already in that state.
onStart, onStop, and onComplete are React callbacks; stopping after the deadline calls
onComplete instead of onStop. The input is disabled while running.
After completion, call edit() to show the editor again; it returns true when the completion
display is dismissed and false otherwise. Remaining time is displayed as total minutes and
seconds, rounded up to the next second.
Use idleColor to set the circle color when it is not running (default #004777).
Set showDays={false}, noHours, and noMicroseconds to display only minutes and seconds.
When noMicroseconds is enabled, stopping rounds the remaining time up to a whole second so
the editable value matches the countdown display. Hidden fields otherwise retain their values.
minutesDivider and secondsDivider customize the input's separators. Like input-duration,
the seconds divider is normally hidden when milliseconds are hidden; the demo uses CSS to show
it as an s suffix.
Pass options for the underlying components through inputProps and circleProps:
<EditableCircleCountdown
initialValue="00:00:10.000"
inputProps={{ name: 'duration', tabThrough: true, onChange: value => console.log(value) }}
circleProps={{
size: 220,
colors: '#004777',
children: ({ remainingTime, color }) => (
<span style={{ color }}>{remainingTime > 0 ? `${remainingTime}s` : 'Done'}</span>
),
}}
/>inputProps accepts the React input-duration props, including visibility, separators, HTML
attributes, and onChange. The integration manages value and defaultValue; use
initialValue to set the initial duration. Its own existing top-level input options take
precedence over the corresponding inputProps. The input is always disabled while running;
inputProps.disabled can also disable it while idle.
circleProps accepts the countdown timer's appearance options and onUpdate. Its children
render function receives the original timer's remainingTime, elapsedTime, and color while
running or completed; the editor remains visible when idle. Without it, the default running and
completion displays are used. The integration manages duration, initialRemainingTime,
isPlaying, and onComplete, so those cannot be overridden through circleProps. Use the
integration's onComplete callback instead; automatic repeats are not supported. Custom
colors apply while running and completed; idleColor controls the idle circle. For an array
of colors, supply colorsTime as required by the original timer.
This project is not affiliated with or endorsed by react-countdown-circle-timer.
Run npm install, then npm run demo, and open the URL printed by Vite. Run npm test to check
the integration and its TypeScript declarations. The demo initially shows the default time paused
and lets you click the circle to edit minutes and seconds. It starts on blur: Enter from either
field or forward Tab from seconds starts the countdown and leaves focus on the page. Keyboard handling is provided by input-duration; the demo
starts the countdown when editing ends.
The GitHub Pages workflow builds and deploys the demo when changes are pushed to main.
