1 | import React from "react";
|
2 |
|
3 | import { format } from "date-fns";
|
4 | import {
|
5 | type MonthCaptionProps,
|
6 | DayPicker,
|
7 | useDayPicker
|
8 | } from "react-day-picker";
|
9 |
|
10 | function CustomMonthCaption(props: MonthCaptionProps) {
|
11 | const { goToMonth, nextMonth, previousMonth } = useDayPicker();
|
12 | return (
|
13 | <>
|
14 | <h2>{format(props.calendarMonth.date, "MMM yyy")}</h2>
|
15 | <div style={{ display: "flex", justifyContent: "space-between" }}>
|
16 | <button
|
17 | style={{ all: "revert", cursor: "pointer" }}
|
18 | disabled={!previousMonth}
|
19 | onClick={() => previousMonth && goToMonth(previousMonth)}
|
20 | >
|
21 | Previous
|
22 | </button>
|
23 | <button
|
24 | style={{ all: "revert", cursor: "pointer" }}
|
25 | disabled={!nextMonth}
|
26 | onClick={() => nextMonth && goToMonth(nextMonth)}
|
27 | >
|
28 | Next
|
29 | </button>
|
30 | </div>
|
31 | </>
|
32 | );
|
33 | }
|
34 |
|
35 | export function CustomCaption() {
|
36 | return (
|
37 | <DayPicker
|
38 | hideNavigation
|
39 | components={{
|
40 | MonthCaption: CustomMonthCaption
|
41 | }}
|
42 | />
|
43 | );
|
44 | }
|