Form
Calendar
A calendar component built on react-day-picker, supporting single, multiple, and range selection with customizable locale, formatting, and appearance.
Installation
bash
pnpm dlx shadcn@latest add calendar -c packages/reactBasic
6/19/2026
tsx
import { useState } from "react"
import { Calendar } from "@polyui/react/calendar"
export function CalendarBasic() {
const [date, setDate] = useState<Date | undefined>(new Date())
return (
<div className="space-y-2 text-center">
<Calendar mode="single" selected={date} onSelect={setDate} className="rounded-xl border border-border" />
{date && <p className="text-sm text-muted-foreground">{date.toLocaleDateString("en-US")}</p>}
</div>
)
}Range
tsx
import { Calendar } from "@polyui/react/calendar"
export function CalendarRange() {
return (
<div className="space-y-2 text-center">
<Calendar mode="range" numberOfMonths={2} className="rounded-xl border border-border" />
</div>
)
}Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
mode | "single" | "multiple" | "range" | — | Selection mode. |
selected | Date | Date[] | DateRange | undefined | — | Currently selected date(s) (controlled). |
onSelect | (date: ...) => void | — | Date selection callback. |
showOutsideDays | boolean | true | Whether to show days outside the current month. |
captionLayout | "label" | "dropdown" | "dropdown-months" | "dropdown-years" | "label" | How the month/year caption is displayed. |
locale | Locale | — | date-fns locale for localized display. |
numberOfMonths | number | 1 | Number of months to display at once. |