1 | import React from "react";
|
2 |
|
3 | import { format } from "date-fns";
|
4 | import { DayPicker, FormatOptions } from "react-day-picker";
|
5 |
|
6 | const seasonEmoji: Record<string, string> = {
|
7 | winter: "⛄️",
|
8 | spring: "🌸",
|
9 | summer: "🌻",
|
10 | autumn: "🍂"
|
11 | };
|
12 |
|
13 | const getSeason = (month: Date): string => {
|
14 | const monthNumber = month.getMonth();
|
15 | if (monthNumber >= 0 && monthNumber < 3) return "winter";
|
16 | if (monthNumber >= 3 && monthNumber < 6) return "spring";
|
17 | if (monthNumber >= 6 && monthNumber < 9) return "summer";
|
18 | else return "autumn";
|
19 | };
|
20 |
|
21 | const formatCaption = (month: Date, options: FormatOptions | undefined) => {
|
22 | const season = getSeason(month);
|
23 | return `${seasonEmoji[season]} ${format(month, "LLLL", { locale: options?.locale })}`;
|
24 | };
|
25 |
|
26 | export function Formatters() {
|
27 | return (
|
28 | <DayPicker
|
29 | fromYear={2020}
|
30 | toYear={2025}
|
31 | formatters={{ formatMonthCaption: formatCaption }}
|
32 | />
|
33 | );
|
34 | }
|