View fulldotdev/ui on GitHub

Calendar

A calendar component that allows users to select a date or a range of dates.

Installation

npx shadcn@latest add @fulldev/calendar

Usage

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"
  />
)

Date Picker

You can use the <Calendar> component to build a date picker.

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"

Changed from the official source: react-day-picker 10 moved the Persian calendar to the @daypicker/persian add-on (same DayPicker API). The Vazirmatn font loads from @fontsource-variable/vazirmatn instead of next/font/google.

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.

Basic

A basic calendar component.

Range Calendar

Use the mode="range" prop to enable range selection.

Month and Year Selector

Use captionLayout="dropdown" to show month and year dropdowns.

Presets

Date and Time Picker

Booked dates

Custom Cell Size

<Calendar
  mode="single"
  selected={date}
  onSelect={setDate}
  className="rounded-lg border [--cell-size:--spacing(11)] md:[--cell-size:--spacing(12)]"
/>
<Calendar
  mode="single"
  selected={date}
  onSelect={setDate}
  className="rounded-lg border [--cell-size:2.75rem] md:[--cell-size:3rem]"
/>

Week Numbers

Use showWeekNumber to show week numbers.

RTL

To enable RTL support in shadcn/ui, see the RTL configuration guide.

import { arSA } from "react-day-picker/locale"

;<Calendar
  mode="single"
  selected={date}
  onSelect={setDate}
  locale={arSA}
  dir="rtl"
/>

API Reference

Source: react/src/components/ui/calendar.tsx

See the React DayPicker documentation for more information on the Calendar component.