DurationInput
A length of time as a number and a unit: «30 minutes», «7 days». The value is in seconds, whatever unit is chosen.
import { DurationInput } from '@sypnia/ui/react'
How long to keep logs
Saved as 604800 seconds
Code
import { useState } from 'react';
import { DurationInput, Field } from '@sypnia/ui/react';
// The value is in seconds, whatever unit is chosen to type it.
export default function Retention() {
const [s, setS] = useState<number | null>(7 * 86400);
return <Field label="Keep logs for" hint={`Saved as ${s ?? '—'} seconds`}><DurationInput value={s} onChange={setS} units={['hours', 'days']} /></Field>;
} When to use it
Use it when
- Retention, timeouts, expiry.
Do not use it when
- A moment in time: use a date or time picker.
For everyone
- The number and the unit are two named controls.
Props
| DurationInput | Type | Default |
|---|---|---|
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | number | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
name | string | |
onChange | ((seconds: number | null) => void) | |
size | "sm" | "md" | "lg" | |
units | DurationUnit[] | ['minutes', 'hours', 'days'] |
valueSeconds, or null while empty. | number | null |