# Date Picker · JGuang UI

> 浏览 Base UI 与 Radix UI 的全部组件实现。

- 页面: https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker
- 改编自: shadcn/ui 文档 (MIT) @ bc0705384b51252af26dcc65425b216bf5eb063c
- 说明：正文保留英文原文。

> 示例 `date-picker-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## Installation

The Date Picker is built using a composition of the `` and the `` components.

See installation instructions for the [Popover](/systems/jguang-ui/docs/components/radix/popover#installation) and the [Calendar](/systems/jguang-ui/docs/components/radix/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"
          data-empty={!date}
          className="w-[280px] justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
        >
          <CalendarIcon />
          {date ? format(date, "PPP") : <span>Pick a date</span>}
        </Button>
      </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.

## Composition

A date picker is built from `Popover` and `Calendar` (there is no `DatePicker` root component):

```text
Popover
├── PopoverTrigger
└── PopoverContent
    └── Calendar
```

## Basic

A basic date picker component.


> 示例 `date-picker-basic`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## Range Picker

A date picker component for selecting a range of dates.


> 示例 `date-picker-range`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## 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.


> 示例 `date-picker-dob`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## Input

A date picker component with an input field for selecting a date.


> 示例 `date-picker-input`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## Time Picker

A date picker component with a time input field for selecting a time.


> 示例 `date-picker-time`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## Natural Language Picker

This component uses the `chrono-node` library to parse natural language dates.


> 示例 `date-picker-natural-language`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker


## RTL

To enable RTL support in JGuang UI, see the [RTL configuration guide](/systems/jguang-ui/docs/rtl).


> 示例 `date-picker-rtl`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/date-picker

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
