Ir al contenido

DateRangePicker

Un período: de un día a otro, en un solo control. Los dos días se escriben parte por parte, o se eligen en un calendario presionando el primer día y luego el último.

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

En esta página
  1. De un día a otro
  2. Estados
  3. Cuándo usarlo
  4. Para todos
  5. Props

De un día a otro

Abre el calendario y presiona dos días. La pista cuenta los días.

17 days of logs, both ends included.

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

const days = (r: DateRange) => Math.round((Date.parse(r.end) - Date.parse(r.start)) / 86_400_000) + 1;

export default function Basic() {
  const [period, setPeriod] = useState<DateRange | null>({ start: '2026-11-01', end: '2026-11-17' });
  return (
    <FormGrid>
      <Field label="Logs from" hint={period ? `${days(period)} days of logs, both ends included.` : 'Choose the first and the last day.'}>
        <DateRangePicker value={period} onChange={setPeriod} max="2026-11-17" />
      </Field>
    </FormGrid>
  );
}

Estados

Con un error que dice cómo arreglarlo, y desactivado.

An export covers up to 31 days. Bring the two days closer.

Set by the plan.

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

export default function States() {
  return (
    <FormGrid>
      <Field label="Export rows created" error="An export covers up to 31 days. Bring the two days closer.">
        <DateRangePicker defaultValue={{ start: '2026-08-01', end: '2026-11-17' }} />
      </Field>
      <Field label="Billing period" hint="Set by the plan.">
        <DateRangePicker disabled defaultValue={{ start: '2026-11-01', end: '2026-11-30' }} />
      </Field>
    </FormGrid>
  );
}

Cuándo usarlo

Úsalo cuando

  • Un tramo de tiempo filtra o limita algo: los registros de un período, los días de una exportación, una ventana de mantenimiento en días.
  • El inicio y el fin solo tienen sentido juntos.

No lo uses cuando

  • Es un solo día: DatePicker.
  • Las dos fechas son hechos separados (ingresó, se fue): dos DatePicker, cada uno con su etiqueta.
  • Solo tienen sentido períodos fijos («últimos 7 días»): un Select.

Para todos

  • Tab entra al primer día; las flechas izquierda y derecha recorren las partes de los dos días; arriba y abajo cambian la parte.
  • En el calendario, Enter sobre un día empieza el período y Enter sobre otro lo termina; Escape antes del segundo día cancela.
  • El control es un group con el nombre de su etiqueta, con «fecha de inicio» y «fecha de fin» adentro. Se anuncia el período elegido.
  • El valor es { start, end } con los dos días como texto ISO, ambos incluidos.
  • Dentro de un Field toma la etiqueta, la pista y el error por sí solo; suelto, dale un aria-label.

Props

DateRangePickerTipoPor 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 DateRange
disabled boolean
endName string
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 last day that can be chosen.

string
min

The first day that can be chosen, as `2026-11-01`.

string
name

The name of the value when it travels in a form.

string
onChange ((range: DateRange | null) => void)
startName

Names of the two values when they travel in a form.

string
unavailable

Days that cannot be chosen: return true for them.

((date: string) => boolean)
value

From one day to another, both included: `{ start: '2026-11-01', end: '2026-11-17' }`.

DateRange | null
  1. De un día a otro
  2. Estados
  3. Cuándo usarlo
  4. Para todos
  5. Props

    Busca páginas, secciones y términos