Skip to content

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'

On this page
  1. How long to keep logs
  2. When to use it
  3. For everyone
  4. Props

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

DurationInputTypeDefault
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
defaultValue number
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks 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']
value

Seconds, or null while empty.

number | null
  1. How long to keep logs
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms