Duration Picker React component for Tailwind CSS v4
v1.0.1Updated in 1.2.1
A React duration picker for hours and minutes whose pill springs apart into editable fields.
Click the pen to spring the segments apart and start editing; the hours field is focused for you and the pen morphs into a tick. Type your values. Anything past the ceiling (24 hr and 60 min by default) clamps to the max and shakes so you know it was corrected. Click the tick to confirm and watch the pill merge back into one piece.
Duration Picker is a free React component in the React input components category, written in TypeScript for React 19 and Tailwind CSS v4. It installs as source with npx wingo-ui@latest add duration-picker, together with Motion presets and UIProvider and the npm packages motion, figma-squircle, flubber, react-use-measure and @radix-ui/react-slot.
Add to a project
Requirements: React 19 and Tailwind CSS v4, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup
npx wingo-ui@latest add duration-pickerUsage
Import DurationPicker from @/components/ui/duration-picker.
"use client"
import { useState } from "react"
import DurationPicker, { type DurationValue } from "@/components/ui/duration-picker"
export function Demo() {
const [duration, setDuration] = useState<DurationValue>({ hours: 1, minutes: 30 })
return (
<DurationPicker
size="md"
value={duration}
onChange={setDuration}
onConfirm={(d) => console.log("saved", d)}
/>
)
}
// zero config, fully uncontrolled
// <DurationPicker onConfirm={(d) => console.log("saved", d)} />Props
sizedefault"md""sm" | "md" | "lg"Overall scale. The pill is 40px (sm, 44px on touch screens), 48px (md) or 56px (lg) tall, and the corner radius, the open field width, the icon and the text size scale with it.
radiusdefault"md""none" | "sm" | "md" | "lg" | "full"Outer corner radius of the squircle: square, tighter, the original 10 / 12 / 14px per size, rounder, or a pill. The inner corners open up from it while editing.
surfaceColordefault"auto"stringFill of the three segments, any CSS color. Auto is a soft gray that follows the light and dark theme. A translucent tint keeps the digits readable in both themes.
labelColordefault"auto"stringColor of the Hr. and Min. labels, any CSS color. Auto is a muted gray tuned per theme.
valueColordefault"auto"stringColor of the typed digits, any CSS color. Auto is black on light pages and white on dark ones.
accentColordefault"#868593"stringColor of the pen icon and the tick it morphs into, any CSS color.
gapdefault8numberSpace in pixels the three segments spread apart to while editing.
maxHoursdefault24numberCeiling for the hours field. Typing past it clamps to this value and shakes the input.
maxMinutesdefault60numberCeiling for the minutes field. Same clamp and shake behavior as maxHours.
defaultEditingdefaultfalsebooleanRenders the picker already open in edit mode, with the tick showing.
hoursLabeldefault"Hr."stringText rendered after the hours field. Swap it for a translation or a terser h.
minutesLabeldefault"Min."stringText rendered after the minutes field.
editLabeldefault"Edit duration"stringAccessible name of the pen button while the picker is closed.
saveLabeldefault"Save duration"stringAccessible name of the tick button while editing.
disableddefaultfalsebooleanDims the control to half opacity and blocks entering edit mode.
value{ hours: number; minutes: number }Controlled value. Pair it with onChange and the picker mirrors whatever you pass in. Leave it out to let the component manage its own state.
defaultValue{ hours: number; minutes: number }Starting value for uncontrolled usage. Ignored when value is provided. Left out, both fields start empty and show a 0 placeholder.
onChange(value: DurationValue) => voidFires on every keystroke with the current clamped value. Listen here to react while the user types.
onConfirm(value: DurationValue) => voidFires once with the final clamped value when the tick is clicked. This is usually the one you want for saving.
onEditingChange(editing: boolean) => voidFires when the picker enters or leaves edit mode, handy for blocking navigation or dimming surrounding UI while it is open.
classNamestringExtra classes merged onto the root; other div props are spread onto it too. Every inner part carries a data-slot (duration-picker, duration-picker-segment, duration-picker-input, duration-picker-toggle) plus data-editing, data-disabled and data-size states, and the colors live in the --duration-picker-surface, --duration-picker-label and --duration-picker-value variables, so you can restyle from CSS alone.
Parts
DurationValue
typeThe value shape for value, defaultValue, onChange and onConfirm: { hours: number; minutes: number }.
Examples
Logging time on a task
onConfirm fires once with the final value when the tick is pressed, which is the moment to save the entry.
Custom limits and labels
maxHours and maxMinutes set the ceilings, so anything above them clamps and shakes; short labels keep the pill compact.
Sizes
sm, md and lg are 40, 48 and 56px tall, with the corners, field and icon scaled to match.
Tinted
A translucent surface with a matching label and icon color reads well in both themes.
Files
- components/ui/duration-picker.tsx
FAQ
Is the React Duration Picker component free?
Yes. The source is free and needs no account: copy it from the Code tab or install it with the CLI.
How do I install Duration Picker?
Run npx wingo-ui@latest add duration-picker. It also adds the Wingo UI items it builds on (Motion presets and UIProvider) and the npm packages motion, figma-squircle, flubber, react-use-measure and @radix-ui/react-slot. With shadcn, run npx shadcn@latest add https://wingo-ui.com/r/duration-picker.json.