mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-01 16:44:24 +00:00
* feat: add base and radix docs * feat: transform code for display * fix * fix * fix * fix * fix * chore: remove claude files * fix * fix * fix * chore: run format:write * fix * feat: add more examples * fix * feat: add aspect-ratio * feat: add avatar * feat: add badge * feat: add breadcrumb * fix * feat: add button * fix * fix * fix * feat: add calendar and card * feat: add carousel * fix: chart * feat: add checkbox * feat: add collapsible * feat: add combobox * feat: add command * feat: add context menu * feat: add data-table dialog and drawer * feat: dropdown-menu * feat: add date-picker * feat: add empty * feat: add field and hover-card * fix: input * feat: add input * feat: add input-group * feat: add input-otp * feat: add item * feat: add kbd and label * feat: add menubar * feat: add native-select * feat: add more components * feat: more components * feat: more components * feat: add skeleton, slider and sonner * feat: add spinner and switch * feat: add more components * fix: tabs * fix: tabs * feat: add docs for sidebar * fix * fix * fi * docs: update * fix: create page * fix * fix * chore: add changelog * fix
98 lines
2.6 KiB
Plaintext
98 lines
2.6 KiB
Plaintext
---
|
|
title: Date Picker
|
|
description: A date picker component with range and presets.
|
|
base: base
|
|
component: true
|
|
---
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-demo" />
|
|
|
|
## Installation
|
|
|
|
The Date Picker is built using a composition of the `<Popover />` and the `<Calendar />` components.
|
|
|
|
See installation instructions for the [Popover](/docs/components/base/popover#installation) and the [Calendar](/docs/components/base/calendar#installation) components.
|
|
|
|
## Usage
|
|
|
|
```tsx showLineNumbers title="components/example-date-picker.tsx"
|
|
"use client"
|
|
|
|
import * as React from "react"
|
|
import { format } from "date-fns"
|
|
import { Calendar as CalendarIcon } from "lucide-react"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
import { Button } from "@/components/ui/button"
|
|
import { Calendar } from "@/components/ui/calendar"
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from "@/components/ui/popover"
|
|
|
|
export function DatePickerDemo() {
|
|
const [date, setDate] = React.useState<Date>()
|
|
|
|
return (
|
|
<Popover>
|
|
<PopoverTrigger
|
|
render={
|
|
<Button
|
|
variant="outline"
|
|
data-empty={!date}
|
|
className="data-[empty=true]:text-muted-foreground justify-start text-left font-normal"
|
|
/>
|
|
}
|
|
>
|
|
<CalendarIcon />
|
|
{date ? format(date, "PPP") : <span>Pick a date</span>}
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-auto p-0">
|
|
<Calendar mode="single" selected={date} onSelect={setDate} />
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|
|
```
|
|
|
|
See the [React DayPicker](https://react-day-picker.js.org) documentation for more information.
|
|
|
|
## Examples
|
|
|
|
### Basic
|
|
|
|
A basic date picker component.
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-basic" />
|
|
|
|
### Range Picker
|
|
|
|
A date picker component for selecting a range of dates.
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-range" />
|
|
|
|
### Date of Birth
|
|
|
|
A date picker component for selecting a date of birth. This component includes a dropdown caption layout for date and month selection.
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-dob" />
|
|
|
|
### Input
|
|
|
|
A date picker component with an input field for selecting a date.
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-input" />
|
|
|
|
### Time Picker
|
|
|
|
A date picker component with a time input field for selecting a time.
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-time" />
|
|
|
|
### Natural Language Picker
|
|
|
|
This component uses the `chrono-node` library to parse natural language dates.
|
|
|
|
<ComponentPreview styleName="base-nova" name="date-picker-natural-language" />
|