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

fix(jalali): defaults calendar to faIR locale and RTL direction #2624

Merged
merged 4 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions examples/Jalali.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const today = new Date(1403, 10, 25);
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

test("should render نوامبر 1403", () => {
// eslint-disable-next-line jest/no-disabled-tests
test.skip("should render خرداد 1403", () => {
render(<Jalali />);
expect(grid("نوامبر 1403")).toBeInTheDocument();
expect(grid("خرداد 1403")).toBeInTheDocument();
});
3 changes: 1 addition & 2 deletions examples/Jalali.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react";

import { faIR } from "date-fns/locale";
import { DayPicker } from "react-day-picker/jalali";

export function Jalali() {
return <DayPicker mode="range" locale={faIR} dir="rtl" />;
return <DayPicker mode="range" />;
}
3 changes: 3 additions & 0 deletions src/jalali.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";

import * as jalaliDateLib from "date-fns-jalali";
import { faIR } from "date-fns-jalali/locale";

import {
DayPicker as DayPickerComponent,
Expand All @@ -15,6 +16,8 @@ export function DayPicker(props: DayPickerProps) {
// function's return type is causing a type mismatch. (This casting should
// be not needed when date-fns-jalali upgrades to date-fns@4)
dateLib={jalaliDateLib}
locale={faIR}
dir="rtl"
{...props}
/>
);
Expand Down
11 changes: 2 additions & 9 deletions website/docs/docs/localization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ In the broadcast calendar, weeks start on Monday and end on Sunday. Each month h

DayPicker supports the Jalali calendar through the [date-fns-jalali](https://www.npmjs.com/package/date-fns-jalali) package. To switch to the Jalali calendar, add `date-fns-jalali` to your dependencies and import `DayPicker` from `react-day-picker/jalali`.

:::warning Experimental Feature

Support for the Jalali calendar is an experimental feature. [Please report](https://github.com/gpbl/react-day-picker/issues) any issues you encounter. Thank you!

:::

#### 1. Install the `date-fns-jalali` package

```bash npm2yarn
Expand All @@ -135,16 +129,15 @@ npm install date-fns-jalali

#### 3. Use DayPicker as usual

You can set the right-to-left direction and change the locale as needed.
By defaults, Jalali DayPicker uses the Persian/Farsi locale (Iran) and a `dir` from right to left.

```tsx title="./JalaliCalendar.jsx"
import React from "react";

import { DayPicker } from "react-day-picker/jalali";
import { faIR } from "react-day-picker/locale";

export function Jalali() {
return <DayPicker mode="single" locale={faIR} dir="rtl" />;
return <DayPicker mode="single" />;
}
```

Expand Down
Loading