UNPKG

react-day-picker

Version:

Customizable Date Picker for React

41 lines (40 loc) 1.55 kB
import React from "react"; import { DateLib, DayPicker as DayPickerComponent, } from "../index.js"; import { enUS as enUSLocale } from "../locale/en-US.js"; import { th as thLocale } from "../locale/th.js"; import { format as originalBuddhistFormat } from "./lib/format.js"; // Adapter to match DateLib's format signature without using `any`. const buddhistFormat = (date, formatStr, options) => { return originalBuddhistFormat(date, formatStr, options); }; export const th = thLocale; export const enUS = enUSLocale; /** * Render the Buddhist (Thai) calendar. * * Months/weeks are Gregorian; displayed year is Buddhist Era (BE = CE + 543). * Thai digits are used by default. * * Defaults: * * - `locale`: `th` * - `dir`: `ltr` * - `numerals`: `thai` */ export function DayPicker(props) { const dateLib = getDateLib({ locale: props.locale ?? th, weekStartsOn: props.broadcastCalendar ? 1 : props.weekStartsOn, firstWeekContainsDate: props.firstWeekContainsDate, useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens, useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens, timeZone: props.timeZone, }); return (React.createElement(DayPickerComponent, { ...props, locale: props.locale ?? th, numerals: props.numerals ?? "thai", dir: props.dir ?? "ltr", dateLib: dateLib })); } /** Returns the date library used in the Buddhist calendar. */ export const getDateLib = (options) => { return new DateLib(options, { format: buddhistFormat, }); };