mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-28 07:04:20 +00:00
102 lines
2.0 KiB
Plaintext
102 lines
2.0 KiB
Plaintext
---
|
|
title: Calendar
|
|
description: A date field component that allows users to enter and edit date.
|
|
component: true
|
|
links:
|
|
doc: https://react-day-picker.js.org
|
|
---
|
|
|
|
<ComponentPreview
|
|
name="calendar-demo"
|
|
title="Calendar"
|
|
description="A calendar showing the current date."
|
|
/>
|
|
|
|
## About
|
|
|
|
The `Calendar` component is built on top of [React DayPicker](https://react-day-picker.js.org).
|
|
|
|
## Installation
|
|
|
|
<CodeTabs>
|
|
|
|
<TabsList>
|
|
<TabsTrigger value="cli">CLI</TabsTrigger>
|
|
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="cli">
|
|
|
|
```bash
|
|
npx shadcn@latest add calendar
|
|
```
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="manual">
|
|
|
|
<Steps>
|
|
|
|
<Step>Install the following dependencies:</Step>
|
|
|
|
```bash
|
|
npm install react-day-picker date-fns
|
|
```
|
|
|
|
<Step>Add the `Button` component to your project.</Step>
|
|
|
|
The `Calendar` component uses the `Button` component. Make sure you have it installed in your project.
|
|
|
|
<Step>Copy and paste the following code into your project.</Step>
|
|
|
|
<ComponentSource name="calendar" />
|
|
|
|
<Step>Update the import paths to match your project setup.</Step>
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
</CodeTabs>
|
|
|
|
## 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.
|
|
|
|
## Examples
|
|
|
|
### Form
|
|
|
|
<ComponentPreview name="calendar-form" />
|
|
|
|
## Changelog
|
|
|
|
### 11-03-2024 day_outside color
|
|
|
|
- Changed the color of the `day_outside` class to the following to improve contrast:
|
|
|
|
```tsx showLineNumbers title="calendar.tsx"
|
|
"day_outside:
|
|
"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",
|
|
```
|