import React, { MouseEventHandler } from "react"; import { isSameDay } from "date-fns"; import { DateRange, DayButtonProps, DayPicker, useDayPicker } from "react-day-picker"; function DayWithShiftKey(props: DayButtonProps) { const { selected } = useDayPicker({ mode: "range" }); const handleClick: MouseEventHandler = (e) => { const requireShiftKey = selected?.from && !isSameDay(props.day.date, selected.from); if (!e.shiftKey && requireShiftKey) { return; } props.onClick?.(e); }; return ( ); } export function RangeShiftKey() { const [range, setRange] = React.useState({ from: undefined }); let footer = "Please pick a day."; if (range?.from && !range?.to) { footer = "Press Shift to choose more days."; } else if (range?.to) { const formattedFrom = range.from?.toDateString(); const formattedTo = range.to.toDateString(); footer = `You selected the days between ${formattedFrom} and ${formattedTo}`; } return ( ); }