Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ethiopic calendar #2658

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ethiopic module
  • Loading branch information
gpbl committed Jan 6, 2025
commit 57662036f21ef4e054284b952e67ba4580ba5da2
1 change: 1 addition & 0 deletions ethiopic.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/cjs/ethiopic/index.d.ts";
4 changes: 4 additions & 0 deletions ethiopic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable no-undef */
const ethiopic = require("./dist/cjs/ethiopic/index.js");
gpbl marked this conversation as resolved.
Show resolved Hide resolved
module.exports = ethiopic;
1 change: 1 addition & 0 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from "./DisableNavigation";
export * from "./Dropdown";
export * from "./DropdownMonths";
export * from "./DropdownMultipleMonths";
export * from "./Ethiopic";
export * from "./Fixedweeks";
export * from "./FocusRecursive";
export * from "./Footer";
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
"default": "./dist/cjs/persian.js"
}
},
"./ethiopic": {
"import": {
"types": "./dist/esm/ethiopic/index.d.ts",
"default": "./dist/esm/ethiopic/index.js"
},
"require": {
"types": "./dist/cjs/ethiopic/index.d.ts",
"default": "./dist/cjs/ethiopic/index.js"
}
},
"./locale": {
"import": {
"types": "./dist/esm/locale.d.ts",
Expand Down
71 changes: 71 additions & 0 deletions src/ethiopic/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from "react";

import type { Locale } from "date-fns";

import {
DateLib,
DateLibOptions,
DayPicker as DayPickerComponent
} from "../index.js";
import type { DayPickerProps } from "../types/props.js";

import * as ethiopicDateLib from "./lib/index.js";

/**
* Render the Persian Calendar.
*
* @see https://daypicker.dev/docs/localization#persian-calendar
*/
export function DayPicker(
props: DayPickerProps & {
/**
* The locale to use in the calendar.
*
* @default `am-ET`
*/
locale?: Locale;
/**
* The numeral system to use when formatting dates.
*
* - `latn`: Latin (Western Arabic)
* - `arab`: Arabic-Indic
* - `arabext`: Eastern Arabic-Indic (Persian)
* - `deva`: Devanagari
* - `ethio`: Ethiopic
* - `beng`: Bengali
* - `guru`: Gurmukhi
* - `gujr`: Gujarati
* - `orya`: Oriya
* - `tamldec`: Tamil
* - `telu`: Telugu
* - `knda`: Kannada
* - `mlym`: Malayalam
*
* @defaultValue `ethio` Eastern Arabic-Indic (Persian)
* @see https://daypicker.dev/docs/translation#numeral-systems
*/
numerals?: DayPickerProps["numerals"];
}
) {
const dateLib = getDateLib({
locale: props.locale,
weekStartsOn: props.broadcastCalendar ? 1 : props.weekStartsOn,
firstWeekContainsDate: props.firstWeekContainsDate,
useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens,
timeZone: props.timeZone
});
return (
<DayPickerComponent
{...props}
locale={props.locale ?? ({} as Locale)}
numerals={props.numerals ?? "ethio"}
dateLib={dateLib}
/>
);
}

/** Returns the date library used in the calendar. */
export const getDateLib = (options?: DateLibOptions) => {
return new DateLib(options, ethiopicDateLib);
};
1 change: 1 addition & 0 deletions src/ethiopic/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { startOfYear } from "./startOfYear.js";
Empty file.
3 changes: 3 additions & 0 deletions src/ethiopic/lib/startOfYear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function startOfYear() {
return new Date();
}