UNPKG

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