Installation
Section titled “Installation”pnpm dlx shadcn@latest add pxl-ui/registry/calendar
Install the following dependencies:
pnpm add react-day-picker
Copy and paste the following code into your project.
Update the import paths to match your project setup.
import { Calendar } from "@/components/ui/calendar"const [date, setDate] = React.useState<Date | undefined>(new Date())
return ( <Calendar mode="single" selected={date} onSelect={setDate} className="rounded-lg border" />)See the React DayPicker documentation for more information.
The Calendar component is built on top of React DayPicker.
Date Picker
Section titled “Date Picker”You can use the <Calendar> component to build a date picker. See the Date Picker page for more information.
Persian / Hijri / Jalali Calendar
Section titled “Persian / Hijri / Jalali Calendar”To use the Persian calendar, edit components/ui/calendar.tsx and replace react-day-picker with react-day-picker/persian.
import { DayPicker } from "react-day-picker"import { DayPicker } from "react-day-picker/persian"Selected Date (With TimeZone)
Section titled “Selected Date (With TimeZone)”The Calendar component accepts a timeZone prop to ensure dates are displayed and selected in the user’s local timezone.
export function CalendarWithTimezone() { const [date, setDate] = React.useState<Date | undefined>(undefined) const [timeZone, setTimeZone] = React.useState<string | undefined>(undefined)
React.useEffect(() => { setTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone) }, [])
return ( <Calendar mode="single" selected={date} onSelect={setDate} timeZone={timeZone} /> )}Note: If you notice a selected date offset (for example, selecting the 20th highlights the 19th), make sure the timeZone prop is set to the user’s local timezone.
Why client-side? The timezone is detected using Intl.DateTimeFormat().resolvedOptions().timeZone inside a useEffect to ensure compatibility with server-side rendering. Detecting the timezone during render would cause hydration mismatches, as the server and client may be in different timezones.
Range Calendar
Section titled “Range Calendar”Use the mode="range" prop to enable range selection.
Month and Year Selector
Section titled “Month and Year Selector”Use captionLayout="dropdown" to show month and year dropdowns.
Custom Cell Size
Section titled “Custom Cell Size”You can customize the size of calendar cells using the --cell-size CSS variable. You can also make it responsive by using breakpoint-specific values:
<Calendar mode="single" selected={date} onSelect={setDate} className="rounded-lg border [--cell-size:--spacing(11)] md:[--cell-size:--spacing(12)]"/>Or use fixed values:
<Calendar mode="single" selected={date} onSelect={setDate} className="rounded-lg border [--cell-size:2.75rem] md:[--cell-size:3rem]"/>Week Numbers
Section titled “Week Numbers”Use showWeekNumber to show week numbers.
API Reference
Section titled “API Reference”See the React DayPicker documentation for more information on the Calendar component.