1 |
|
2 | import React from "react";
|
3 |
|
4 | import { addMonths } from "date-fns";
|
5 | import { DayPicker, WeekNumberProps } from "react-day-picker";
|
6 |
|
7 | const today = new Date(2021, 0, 1);
|
8 |
|
9 | export function WeeknumberCustom() {
|
10 | return (
|
11 | <DayPicker
|
12 | showWeekNumber
|
13 | defaultMonth={addMonths(today, -1)}
|
14 | components={{
|
15 | WeekNumber: ({ week, ...props }: WeekNumberProps) => (
|
16 | <td {...props}>
|
17 | <button onClick={() => console.log(week)}>{props.children}</button>
|
18 | </td>
|
19 | )
|
20 | }}
|
21 | labels={{
|
22 | labelWeekNumber: (weekNumber: number) => `W${weekNumber}`
|
23 | }}
|
24 | formatters={{
|
25 | formatWeekNumber: (weekNumber: number) => `W${weekNumber}`
|
26 | }}
|
27 | />
|
28 | );
|
29 | }
|