mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-08 14:35:09 +00:00
* feat(v4): update home page * fix * fix: cards * feat(v4): charts page * feat: update pages * feat: colors * fix * feat: add docs * feat: mdx work * fix * fix * fix: sidebar * fix: lint * feat: updates * feat: update components * feat: fix docs * fix: responsive * feat: implement cmdk * fix: update navigation menu demo * fix: code style * fix: themes * feat: implement blocks page * fix: docs config * refactor * fix: outputFileTracingIncludes * fix * fix: output * fix * fix: registry * refactor: move docs * debug: docs * debug * revert * fix: mjs * deps: pin fumadocs * debug * fix: downgrade next * fix: index page * refactor: move mdx components * fix: remove copy button * fix * was it zod * yes it was * remove copy page * fix: color page * fix: colors page * fix: meta colors * fix: copy button * feat: sync registry * fix: registry build script * feat: update port * feat: clean up examples * fix * fix: mobile nav * fix: blur for mobile * fix: sidebar nav * feat: update examples * fix: build scripts * feat: update components * feat: restyle * fix: types * fix: styles * fix: margins * fix: screenshots * fix * feat: update theme * fix: charts nav * fix: image * feat: optimize images * fix: menu * fix: card * fix: border * check * feat: implement charts page * fix: charts * fix: og images * feat: extend touch * fix: static * fix: sizing * fix: mobile screenshots * fix: page nav * fix * feat: update favicon * fix: theme selector * fix: feedback * fix: sink * docs: update * fix: styles * chore: update registry * fix: command * fix * fix: minor updates * fix: typography on smaller devices * fix: format * fix: remove unused icon * feat: update favicon * fix: typography * docs: typography page * fix: steps
94 lines
2.1 KiB
Plaintext
94 lines
2.1 KiB
Plaintext
---
|
|
title: Date Picker
|
|
description: A date picker component with range and presets.
|
|
component: true
|
|
---
|
|
|
|
<ComponentPreview
|
|
name="date-picker-demo"
|
|
description="A date picker in a popover"
|
|
/>
|
|
|
|
## Installation
|
|
|
|
The Date Picker is built using a composition of the `<Popover />` and the `<Calendar />` components.
|
|
|
|
See installation instructions for the [Popover](/docs/components/popover#installation) and the [Calendar](/docs/components/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 asChild>
|
|
<Button
|
|
variant={"outline"}
|
|
className={cn(
|
|
"w-[280px] justify-start text-left font-normal",
|
|
!date && "text-muted-foreground"
|
|
)}
|
|
>
|
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
|
{date ? format(date, "PPP") : <span>Pick a date</span>}
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-auto p-0">
|
|
<Calendar
|
|
mode="single"
|
|
selected={date}
|
|
onSelect={setDate}
|
|
initialFocus
|
|
/>
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|
|
```
|
|
|
|
See the [React DayPicker](https://react-day-picker.js.org) documentation for more information.
|
|
|
|
## Examples
|
|
|
|
### Date Picker
|
|
|
|
<ComponentPreview
|
|
name="date-picker-demo"
|
|
description="A date picker in a popover"
|
|
/>
|
|
|
|
### Date Range Picker
|
|
|
|
<ComponentPreview
|
|
name="date-picker-with-range"
|
|
description="A date range picker"
|
|
/>
|
|
|
|
### With Presets
|
|
|
|
<ComponentPreview
|
|
name="date-picker-with-presets"
|
|
description="A date picker with presets"
|
|
/>
|
|
|
|
### Form
|
|
|
|
<ComponentPreview name="date-picker-form" />
|