Vincoli

Giorni Minimi e Massimi

Limita la lunghezza dell’intervallo con minDays e maxDays (inclusi). Gli utenti non possono confermare un intervallo più corto di minDays o più lungo di maxDays.

import { useState } from "react";
import "react-date-range-picker-styled/rdrp-styles.css";
import { DateRangePicker } from "react-date-range-picker-styled";
function MinMaxDays() {
const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({
start: null,
end: null,
});
return <DateRangePicker value={value} onChange={setValue} minDays={3} maxDays={14} />;
}

Date Disabilitate

Usa isDateUnavailable per disabilitare dinamicamente date specifiche. Le date disabilitate non possono essere selezionate come inizio o fine di un intervallo.

import { useState } from "react";
import "react-date-range-picker-styled/rdrp-styles.css";
import { DateRangePicker } from "react-date-range-picker-styled";
const isWeekend = (date: Date) => {
const day = date.getDay();
return day === 0 || day === 6;
};
function DisabledDates() {
const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({
start: null,
end: null,
});
return <DateRangePicker value={value} onChange={setValue} isDateUnavailable={isWeekend} />;
}

Permetti Data Singola

Per impostazione predefinita, un intervallo in cui l’inizio è uguale alla fine è consentito. Imposta allowSingleDateInRange={false} per richiedere almeno due date distinte.

import { useState } from "react";
import { DateRangePicker } from "react-date-range-picker-styled";
import "react-date-range-picker-styled/rdrp-styles.css";
function AllowSingleDate() {
const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({
start: null,
end: null,
});
return <DateRangePicker value={value} onChange={setValue} allowSingleDateInRange={false} />;
}