UNPKG

809 BTypeScriptView Raw
1import React from "react";
2
3import { format } from "date-fns";
4import { arSA } from "date-fns/locale";
5import { DayPicker, FormatOptions } from "react-day-picker";
6
7const NU_LOCALE = "ar-u-nu-arab";
8
9const formatDay = (day: Date) => day.getDate().toLocaleString(NU_LOCALE);
10
11const formatWeekNumber = (weekNumber: number) => {
12 return weekNumber.toLocaleString(NU_LOCALE);
13};
14
15const formatMonthCaption = (date: Date, options: FormatOptions | undefined) => {
16 const y = date.getFullYear().toLocaleString(NU_LOCALE);
17 const m = format(date, "LLLL", { locale: options?.locale });
18 return `${m} ${y}`;
19};
20
21export function NumberingSystem() {
22 return (
23 <DayPicker
24 locale={arSA}
25 dir="rtl"
26 showWeekNumber
27 formatters={{ formatDay, formatMonthCaption, formatWeekNumber }}
28 />
29 );
30}