Ir al contenido

TimePicker

Una hora del día. Las horas y los minutos se escriben por separado; la pantalla muestra 12 o 24 horas según el idioma de la persona, y el valor siempre es de 24 horas (14:30).

import { TimePicker } from '@sypnia/ui/react'

En esta página
  1. Una hora
  2. Estados
  3. Cuándo usarlo
  4. Para todos
  5. Props

Una hora

En inglés muestra AM y PM; en español, 24 horas. El valor de abajo es el mismo en los dos.

300

Saved as 03:00, in the time zone of the project.

Código
import { useState } from 'react';
import { Field, FormGrid, TimePicker } from '@sypnia/ui/react';

export default function Basic() {
  const [at, setAt] = useState<string | null>('03:00');
  return (
    <FormGrid>
      <Field label="Back up every day at" hint={at ? <>Saved as <code>{at}</code>, in the time zone of the project.</> : 'Choose a quiet hour.'}>
        <TimePicker value={at} onChange={setAt} />
      </Field>
    </FormGrid>
  );
}

Estados

Siempre 24 horas, con un error que dice cómo arreglarlo, y desactivado.

1845
2330

Reports go out between 06:00 and 22:00. Choose an hour in that window.

400

Set by Sypnia for every project in this region.

Código
import { Field, FormGrid, TimePicker } from '@sypnia/ui/react';

export default function States() {
  return (
    <FormGrid>
      <Field label="Always in 24 hours">
        <TimePicker hourCycle={24} defaultValue="18:45" />
      </Field>
      <Field label="Send the report at" error="Reports go out between 06:00 and 22:00. Choose an hour in that window.">
        <TimePicker defaultValue="23:30" min="06:00" max="22:00" />
      </Field>
      <Field label="Maintenance starts at" hint="Set by Sypnia for every project in this region.">
        <TimePicker disabled defaultValue="04:00" />
      </Field>
    </FormGrid>
  );
}

Cuándo usarlo

Úsalo cuando

  • Algo pasa cada día a una hora: una copia de seguridad, un informe, un período de silencio.
  • La hora tiene límites: min y max.

No lo uses cuando

  • También necesita el día: DateTimePicker.
  • Es una duración (90 minutos), no una hora del día: NumberInput con unidad, o DurationInput.
  • Solo se pueden elegir unas pocas horas fijas: Select.

Para todos

  • Cada parte es un spinbutton: escribir la llena y salta a la siguiente; las flechas arriba y abajo la cambian; izquierda y derecha se mueven entre partes.
  • Con 12 horas, «a» y «p» ponen AM y PM.
  • Las partes se anuncian como hora, minuto y AM/PM, en el idioma de la página.
  • Dentro de un Field toma la etiqueta, la pista y el error por sí solo; suelto, dale un aria-label.

Props

TimePickerTipoPor defecto
aria-describedby string
aria-label

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

string
aria-labelledby string
className string
defaultValue string
disabled boolean
hourCycle

12 or 24 hours on screen. By default, what the language uses.

12 | 24
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
max

The latest hour.

string
min

The earliest hour, as `08:00`.

string
name string
onChange ((time: string | null) => void)
value

The hour, as `14:30` (always 24 hours in the value), or null while it is empty.

string | null
  1. Una hora
  2. Estados
  3. Cuándo usarlo
  4. Para todos
  5. Props

    Busca páginas, secciones y términos