JGuang / JGuang UI
Components组件Base UIBase UI 组件

Date Picker

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

中文模式已适配导航、标题、简介、目录与常用章节名称。翻译状态:部分完成;技术正文目前仍为英文。
Loading JGuang UI example…

安装

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

See installation instructions for the Popover and the Calendar components.

用法

"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="justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
          />
        }
      >
        <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 documentation for more information.

Composition

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

Popover
├── PopoverTrigger
└── PopoverContent
    └── Calendar

Basic

A basic date picker component.

Loading JGuang UI example…

Range Picker

A date picker component for selecting a range of dates.

Loading JGuang UI example…

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.

Loading JGuang UI example…

Input

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

Loading JGuang UI example…

Time Picker

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

Loading JGuang UI example…

Natural Language Picker

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

Loading JGuang UI example…

从右到左布局

To enable RTL support in JGuang UI, see the RTL configuration guide.

Loading JGuang UI example…

来源: components/base/date-picker.mdx

JGuang UI 技术文档。

On this page