-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: persian calendar * Update docs * Update playground * Playground updates * Update playground
- Loading branch information
Showing
15 changed files
with
338 additions
and
115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
import { DayPicker } from "react-day-picker/persian"; | ||
|
||
export function Persian() { | ||
return <DayPicker mode="single" />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
|
||
import { DayPicker, getDateLib, enUS } from "react-day-picker/persian"; | ||
|
||
export function PersianEn() { | ||
const [selected, setSelected] = React.useState(new Date()); | ||
const dateLib = getDateLib({ locale: enUS }); | ||
return ( | ||
<DayPicker | ||
locale={enUS} | ||
mode="single" | ||
selected={selected} | ||
required | ||
onSelect={setSelected} | ||
footer={`Selected: ${dateLib.format(selected, "d MMM yyyy")}`} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
|
||
import { grid } from "@/test/elements"; | ||
import { render } from "@/test/render"; | ||
|
||
import { PersianFormatted } from "./PersianFormatted"; | ||
|
||
const today = new Date(2024, 11, 22); | ||
|
||
beforeAll(() => jest.setSystemTime(today)); | ||
afterAll(() => jest.useRealTimers()); | ||
|
||
test("should render دی 1403", () => { | ||
render(<PersianFormatted />); | ||
expect(grid("دی 1403")).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react"; | ||
|
||
import { DayPicker, getDateLib } from "react-day-picker/persian"; | ||
|
||
export function PersianFormatted() { | ||
const [selected, setSelected] = React.useState(new Date()); | ||
const dateLib = getDateLib(); | ||
return ( | ||
<DayPicker | ||
mode="single" | ||
selected={selected} | ||
required | ||
onSelect={setSelected} | ||
footer={`Selected: ${dateLib.format(selected, "yyyy/MM/dd")}`} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist/cjs/persian.d.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 persian = require("./dist/cjs/persian.js"); | ||
module.exports = persian; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,2 @@ | ||
import React from "react"; | ||
|
||
import * as jalaliDateLib from "date-fns-jalali"; | ||
import { faIR } from "date-fns-jalali/locale"; | ||
|
||
import { DayPicker as DayPickerComponent } from "./index.js"; | ||
import type { DayPickerProps } from "./types/props.js"; | ||
|
||
export function DayPicker( | ||
props: DayPickerProps & { | ||
/** | ||
* The locale to use in the calendar. | ||
* | ||
* @default `faIR` from `date-fns-jalali` | ||
*/ | ||
locale?: DayPickerProps["locale"]; | ||
/** | ||
* The direction of the text in the calendar. | ||
* | ||
* @default `rtl` | ||
*/ | ||
dir?: DayPickerProps["dir"]; | ||
/** | ||
* The date library to use in the calendar. | ||
* | ||
* @default `jalaliDateLib` from `date-fns-jalali` | ||
*/ | ||
dateLib?: DayPickerProps["dateLib"]; | ||
} | ||
) { | ||
return ( | ||
<DayPickerComponent | ||
{...props} | ||
locale={props.locale ?? faIR} | ||
dir={props.dir ?? "rtl"} | ||
dateLib={props.dateLib ?? jalaliDateLib} | ||
/> | ||
); | ||
} | ||
/** @deprecated Import from `react-day-picker/persian` instead. */ | ||
export * from "./persian.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from "react"; | ||
|
||
import * as dateFnsJalali from "date-fns-jalali"; | ||
import { Locale } from "date-fns-jalali"; | ||
import * as locales from "date-fns-jalali/locale"; | ||
|
||
import { | ||
DateLib, | ||
DateLibOptions, | ||
DayPicker as DayPickerComponent | ||
} from "./index.js"; | ||
import type { DayPickerProps } from "./types/props.js"; | ||
|
||
export const faIR = locales.faIR; | ||
export const enUS = locales.enUS; | ||
|
||
/** Render the Persian Calendar */ | ||
export function DayPicker( | ||
props: DayPickerProps & { | ||
/** | ||
* The locale to use in the calendar. | ||
* | ||
* @default `faIR` | ||
*/ | ||
locale?: Locale; | ||
/** | ||
* The direction of the text in the calendar. | ||
* | ||
* @default `rtl` | ||
*/ | ||
dir?: DayPickerProps["dir"]; | ||
/** | ||
* The date library to use in the calendar. | ||
* | ||
* @default `jalaliDateLib` from `date-fns-jalali` | ||
*/ | ||
dateLib?: DayPickerProps["dateLib"]; | ||
} | ||
) { | ||
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 ?? faIR} | ||
dir={props.dir ?? "rtl"} | ||
dateLib={dateLib} | ||
/> | ||
); | ||
} | ||
|
||
/** Returns the date library used in the calendar. */ | ||
export const getDateLib = (options?: DateLibOptions) => { | ||
return new DateLib(options, dateFnsJalali); | ||
}; |
Oops, something went wrong.