DurationEditor
A compact hours / minutes pill. Tap the pencil and it splits into three bigger pills with editable numbers and a check; save and it merges back into one.
Preview
Preview coming soon
Try it live: run the CLI command below in an Expo app, or open the Code tab.
Installation
npx @codewithrabby/ui@latest add duration-editorUsage
import { DurationEditor } from "@/components/uir/duration-editor";
// uncontrolled
<DurationEditor
defaultValue={{ hours: 1, minutes: 30 }}
onChange={({ hours, minutes }) => saveDuration(hours * 60 + minutes)}
/>
// controlled
const [duration, setDuration] = useState({ hours: 0, minutes: 45 });
<DurationEditor value={duration} onChange={setDuration} hoursLabel="h" minutesLabel="m" />Props
| Prop | Type | Default |
|---|---|---|
valueControlled value. | { hours, minutes } | — |
defaultValueStarting value when uncontrolled. | { hours, minutes } | { hours: 1, minutes: 30 } |
onChangeCalled with the cleaned-up value when the check is pressed. Minutes cap at 59. | (value) => void | — |
onOpenChangeCalled when editing starts and ends. | (open: boolean) => void | — |
maxHoursLargest hours value. Also sets how many digits can be typed. | number | 99 |
hoursLabelUnit after the hours. | string | "Hr." |
minutesLabelUnit after the minutes. | string | "Min." |
backgroundColorPill colour. | string | "#efeff2" |
textColorNumber and check colour. | string | "#111" |
mutedColorUnit label and pencil colour. | string | "#8e8e93" |