Skip to content

Commit a5b953d

Browse files
committed
restore: Restore the changes made on 7a95428
1 parent c9a3504 commit a5b953d

File tree

3 files changed

+57
-51
lines changed

3 files changed

+57
-51
lines changed

docs-site/src/components/Example/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { forwardRef, useState } from "react";
1+
import React, { forwardRef, useMemo, useState } from "react";
22
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live";
33
import DatePicker, {
44
registerLocale,
@@ -163,6 +163,7 @@ export default class CodeExampleComponent extends React.Component<
163163
scope={{
164164
// NB any globals added here should also be referenced in ../../examples/.eslintrc
165165
useState,
166+
useMemo,
166167
DatePicker,
167168
CalendarContainer,
168169
DateFNS,

docs-site/src/examples/live-provider-globals.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as DateFNS from "date-fns";
33
import type { ReactDatePickerCustomHeaderProps as ReactDatePickerCustomHeaderPropsType } from "react-datepicker";
44
import type { MiddlewareState as MiddlewareStateType } from "@floating-ui/react";
55
declare global {
6+
const useMemo: typeof React.useMemo;
67
const useState: typeof React.useState;
78
const DatePicker: any;
89
const CalendarContainer: any;

docs-site/src/examples/ts/renderCustomHeaderTwoMonths.tsx

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,64 @@
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-
491
const RenderCustomHeaderTwoMonths = () => {
502
const [selectedDate, setSelectedDate] = useState<Date | null>(new Date());
3+
const monthsShown = useMemo(() => 2, []);
514

525
return (
536
<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+
)}
5559
selected={selectedDate}
5660
onChange={(date: Date | null) => setSelectedDate(date)}
57-
monthsShown={2}
61+
monthsShown={monthsShown}
5862
/>
5963
);
6064
};

0 commit comments

Comments
 (0)