mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-08 14:35:09 +00:00
* feat(form): add form component * feat(www): update site styles * feat: add form examples * docs(www): add docs for forms * docs(www): hide tabs for docs demo
83 lines
1.8 KiB
Plaintext
83 lines
1.8 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.
|
|
|
|
## React Hook Form
|
|
|
|
<Alert className="mt-4">
|
|
<AlertDescription>
|
|
**Note**: Learn more about using React Hook Form on the
|
|
[docs](/docs/forms/react-hook-form) page.
|
|
</AlertDescription>
|
|
</Alert>
|
|
|
|
<ComponentExample src="/components/examples/calendar/react-hook-form.tsx">
|
|
<CalendarReactHookForm />
|
|
</ComponentExample>
|