|
1 | | -const CustomHeader = ({ |
2 | | - monthDate, |
3 | | - customHeaderCount, |
4 | | - decreaseMonth, |
5 | | - increaseMonth, |
6 | | -}: ReactDatePickerCustomHeaderProps) => ( |
7 | | - <div> |
8 | | - <button |
9 | | - aria-label="Previous Month" |
10 | | - className={ |
11 | | - "react-datepicker__navigation react-datepicker__navigation--previous" |
12 | | - } |
13 | | - style={customHeaderCount === 1 ? { visibility: "hidden" } : undefined} |
14 | | - onClick={decreaseMonth} |
15 | | - > |
16 | | - <span |
17 | | - className={ |
18 | | - "react-datepicker__navigation-icon react-datepicker__navigation-icon--previous" |
19 | | - } |
20 | | - > |
21 | | - {"<"} |
22 | | - </span> |
23 | | - </button> |
24 | | - <span className="react-datepicker__current-month"> |
25 | | - {monthDate.toLocaleString("en-US", { |
26 | | - month: "long", |
27 | | - year: "numeric", |
28 | | - })} |
29 | | - </span> |
30 | | - <button |
31 | | - aria-label="Next Month" |
32 | | - className={ |
33 | | - "react-datepicker__navigation react-datepicker__navigation--next" |
34 | | - } |
35 | | - style={customHeaderCount === 0 ? { visibility: "hidden" } : undefined} |
36 | | - onClick={increaseMonth} |
37 | | - > |
38 | | - <span |
39 | | - className={ |
40 | | - "react-datepicker__navigation-icon react-datepicker__navigation-icon--next" |
41 | | - } |
42 | | - > |
43 | | - {">"} |
44 | | - </span> |
45 | | - </button> |
46 | | - </div> |
47 | | -); |
48 | | - |
49 | 1 | const RenderCustomHeaderTwoMonths = () => { |
50 | 2 | const [selectedDate, setSelectedDate] = useState<Date | null>(new Date()); |
| 3 | + const monthsShown = useMemo(() => 2, []); |
51 | 4 |
|
52 | 5 | return ( |
53 | 6 | <DatePicker |
54 | | - renderCustomHeader={CustomHeader} |
| 7 | + renderCustomHeader={({ |
| 8 | + monthDate, |
| 9 | + customHeaderCount, |
| 10 | + decreaseMonth, |
| 11 | + increaseMonth, |
| 12 | + }: ReactDatePickerCustomHeaderProps) => ( |
| 13 | + <div> |
| 14 | + <button |
| 15 | + aria-label="Previous Month" |
| 16 | + className={ |
| 17 | + "react-datepicker__navigation react-datepicker__navigation--previous" |
| 18 | + } |
| 19 | + style={ |
| 20 | + customHeaderCount === 1 ? { visibility: "hidden" } : undefined |
| 21 | + } |
| 22 | + onClick={decreaseMonth} |
| 23 | + > |
| 24 | + <span |
| 25 | + className={ |
| 26 | + "react-datepicker__navigation-icon react-datepicker__navigation-icon--previous" |
| 27 | + } |
| 28 | + > |
| 29 | + {"<"} |
| 30 | + </span> |
| 31 | + </button> |
| 32 | + <span className="react-datepicker__current-month"> |
| 33 | + {monthDate.toLocaleString("en-US", { |
| 34 | + month: "long", |
| 35 | + year: "numeric", |
| 36 | + })} |
| 37 | + </span> |
| 38 | + <button |
| 39 | + aria-label="Next Month" |
| 40 | + className={ |
| 41 | + "react-datepicker__navigation react-datepicker__navigation--next" |
| 42 | + } |
| 43 | + onClick={increaseMonth} |
| 44 | + style={{ |
| 45 | + visibility: |
| 46 | + customHeaderCount === monthsShown - 1 ? "visible" : "hidden", |
| 47 | + }} |
| 48 | + > |
| 49 | + <span |
| 50 | + className={ |
| 51 | + "react-datepicker__navigation-icon react-datepicker__navigation-icon--next" |
| 52 | + } |
| 53 | + > |
| 54 | + {">"} |
| 55 | + </span> |
| 56 | + </button> |
| 57 | + </div> |
| 58 | + )} |
55 | 59 | selected={selectedDate} |
56 | 60 | onChange={(date: Date | null) => setSelectedDate(date)} |
57 | | - monthsShown={2} |
| 61 | + monthsShown={monthsShown} |
58 | 62 | /> |
59 | 63 | ); |
60 | 64 | }; |
|
0 commit comments