UIR

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-editor

Usage

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

PropTypeDefault
value

Controlled value.

{ hours, minutes }—
defaultValue

Starting value when uncontrolled.

{ hours, minutes }{ hours: 1, minutes: 30 }
onChange

Called with the cleaned-up value when the check is pressed. Minutes cap at 59.

(value) => void—
onOpenChange

Called when editing starts and ends.

(open: boolean) => void—
maxHours

Largest hours value. Also sets how many digits can be typed.

number99
hoursLabel

Unit after the hours.

string"Hr."
minutesLabel

Unit after the minutes.

string"Min."
backgroundColor

Pill colour.

string"#efeff2"
textColor

Number and check colour.

string"#111"
mutedColor

Unit label and pencil colour.

string"#8e8e93"