Skip to content
Open
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
3 changes: 3 additions & 0 deletions apps/v4/content/docs/components/calendar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ You can use the `<Calendar>` component to build a date picker. See the [Date Pic

To use the Persian calendar, edit `components/ui/calendar.tsx` and replace `react-day-picker` with `react-day-picker/persian`.

Then, to ensure the months dropdown displays correctly when `captionLayout='dropdown'`, pass a custom `formatMonthDropdown`
function to your Calendar instance.

```diff
- import { DayPicker } from "react-day-picker"
+ import { DayPicker } from "react-day-picker/persian"
Expand Down
19 changes: 17 additions & 2 deletions apps/v4/registry/new-york-v4/examples/calendar-hijri.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ export default function CalendarHijri() {
defaultMonth={date}
selected={date}
onSelect={setDate}
className="rounded-lg border shadow-sm"
className="rounded-lg border shadow-sm",
captionLayout='dropdown'
/**
* You can handle months in two ways:
* 1. Apply this solution for a specific Calendar instance.
* 2. Override the default `formatMonthDropdown` function
* directly in the Calendar component code, as explained below.
*/
formatters={{
formatMonthDropdown: date => date.toLocaleString('fa-IR', { month: 'short' }),
}}
/>
)
}
Expand Down Expand Up @@ -56,9 +66,14 @@ function Calendar({
className
)}
captionLayout={captionLayout}
/**
* To override the month display when `captionLayout='dropdown'`
* provide a custom `formatMonthDropdown` here
* You can set your preferred locale or pass a prop as needed
*/
formatters={{
formatMonthDropdown: (date) =>
date.toLocaleString("default", { month: "short" }),
date.toLocaleString("fa-IR", { month: "short" }), // customize the locale as needed
...formatters,
}}
classNames={{
Expand Down