UNPKG

750 BTypeScriptView Raw
1/* eslint-disable no-console */
2import React from "react";
3
4import { addMonths } from "date-fns";
5import { DayPicker, WeekNumberProps } from "react-day-picker";
6
7const today = new Date(2021, 0, 1);
8
9export 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}