1 | import React, { useState } from "react";
|
2 |
|
3 | import { format } from "date-fns";
|
4 | import { DateRange, DayPicker } from "react-day-picker";
|
5 |
|
6 | export function RangeMinMax() {
|
7 | const [range, setRange] = useState<DateRange | undefined>();
|
8 |
|
9 | let footer = `Please pick the first day.`;
|
10 | if (range?.from) {
|
11 | if (!range.to) {
|
12 | footer = `${format(range.from, "PPP")}—`;
|
13 | } else if (range.to) {
|
14 | footer = `${format(range.from, "PPP")}—${format(range.to, "PPP")}`;
|
15 | }
|
16 | }
|
17 |
|
18 | return (
|
19 | <div>
|
20 | <p>Select up to 6 nights.</p>
|
21 | <DayPicker
|
22 | mode="range"
|
23 | min={1}
|
24 | max={6}
|
25 | selected={range}
|
26 | onSelect={setRange}
|
27 | footer={footer}
|
28 | />
|
29 | </div>
|
30 | );
|
31 | }
|