forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderCustomHeaderTwoMonths.js
More file actions
65 lines (64 loc) · 1.79 KB
/
renderCustomHeaderTwoMonths.js
File metadata and controls
65 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { useState, useMemo } from "react";
() => {
const [startDate, setStartDate] = useState(new Date());
const monthsShown = useMemo(() => 2, []);
return (
<DatePicker
renderCustomHeader={({
monthDate,
customHeaderCount,
decreaseMonth,
increaseMonth,
}) => (
<div>
<button
aria-label="Previous Month"
className={
"react-datepicker__navigation react-datepicker__navigation--previous"
}
onClick={decreaseMonth}
style={{
visibility: customHeaderCount === 0 ? "visible" : "hidden",
}}
>
<span
className={
"react-datepicker__navigation-icon react-datepicker__navigation-icon--previous"
}
>
{"<"}
</span>
</button>
<span className="react-datepicker__current-month">
{monthDate.toLocaleString("en-US", {
month: "long",
year: "numeric",
})}
</span>
<button
aria-label="Next Month"
className={
"react-datepicker__navigation react-datepicker__navigation--next"
}
onClick={increaseMonth}
style={{
visibility:
customHeaderCount === monthsShown - 1 ? "visible" : "hidden",
}}
>
<span
className={
"react-datepicker__navigation-icon react-datepicker__navigation-icon--next"
}
>
{">"}
</span>
</button>
</div>
)}
selected={startDate}
onChange={(date) => setStartDate(date)}
monthsShown={monthsShown}
/>
);
};