Files
shadcn-ui/apps/www/content/docs/components/calendar.mdx

70 lines
1.5 KiB
Plaintext

---
title: Calendar
description: A date field component that allows users to enter and edit date.
component: true
---
<ComponentExample src="/components/examples/calendar/demo.tsx">
<CalendarDemo />
</ComponentExample>
## About
The `Calendar` component is built on top of [React DayPicker](https://react-day-picker.js.org).
## Installation
```bash
npx shadcn-ui add calendar
```
<Accordion type="single" collapsible>
<AccordionItem value="manual-installation">
<AccordionTrigger>Manual Installation</AccordionTrigger>
<AccordionContent>
1. Install the `react-day-picker` and `date-fns` packages:
```bash
npm install react-day-picker date-fns
```
2. Copy and paste the following code into your project.
<ComponentSource src="/components/ui/calendar.tsx" />
<Callout>
This is the `<Calendar />` primitive. You can place it in a file at
`components/ui/calendar.tsx`.
</Callout>
</AccordionContent>
</AccordionItem>
</Accordion>
## Usage
```tsx
import { Calendar } from "@/components/ui/calendar"
```
```tsx
const [date, setDate] = React.useState<Date | undefined>(new Date())
return (
<Calendar
mode="single"
selected={date}
onSelect={setDate}
className="rounded-md border"
/>
)
```
See the [React DayPicker](https://react-day-picker.js.org) documentation for more information.
## Date Picker
You can use the `<Calendar>` component to build a date picker. See the [Date Picker](/docs/components/date-picker) page for more information.