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
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
groupcon 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
| DateRangePicker | Tipo | Por defecto |
|---|---|---|
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | DateRange | |
disabled | boolean | |
endName | string | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
maxThe last day that can be chosen. | string | |
minThe first day that can be chosen, as `2026-11-01`. | string | |
nameThe name of the value when it travels in a form. | string | |
onChange | ((range: DateRange | null) => void) | |
startNameNames of the two values when they travel in a form. | string | |
unavailableDays that cannot be chosen: return true for them. | ((date: string) => boolean) | |
valueFrom one day to another, both included: `{ start: '2026-11-01', end: '2026-11-17' }`. | DateRange | null |