- 手风琴
- 警报
- 警报对话框
- 纵横比
- 头像
- 徽章
- 面包屑
- 按钮
- 按钮组
- 日历
- 卡片
- 轮播
- 图表
- 复选框
- 可折叠
- 组合框
- 命令
- 上下文菜单
- 数据表格
- 日期选择器
- 对话框
- 方向
- 抽屉
- 下拉菜单
- 空
- 字段
- 悬停卡
- 输入
- 输入组
- 输入 OTP
- 条目
- 键盘
- 标签
- 菜单栏
- 原生选择
- 导航菜单
- 分页
- 弹出窗口
- 进度
- 单选按钮组
- 可调整大小
- 滚动区域
- 选择
- 分隔符
- 工作表
- 侧边栏
- 骨架
- 滑块
- Sonner
- 旋转器
- 切换
- 表格
- 标签
- 文本区域
- Toast
- 切换
- 切换组
- 工具提示
- 排版
- 手风琴
- 警报
- 警报对话框
- 纵横比
- 头像
- 徽章
- 面包屑
- 按钮
- 按钮组
- 日历
- 卡片
- 轮播
- 图表
- 复选框
- 可折叠
- 组合框
- 命令
- 上下文菜单
- 数据表格
- 日期选择器
- 对话框
- 方向
- 抽屉
- 下拉菜单
- 空
- 字段
- 悬停卡
- 输入
- 输入组
- 输入 OTP
- 条目
- 键盘
- 标签
- 菜单栏
- 原生选择
- 导航菜单
- 分页
- 弹出窗口
- 进度
- 单选按钮组
- 可调整大小
- 滚动区域
- 选择
- 分隔符
- 工作表
- 侧边栏
- 骨架
- 滑块
- Sonner
- 旋转器
- 切换
- 表格
- 标签
- 文本区域
- Toast
- 切换
- 切换组
- 工具提示
- 排版
"use client"
import * as React from "react"安装
🌐 Installation
日期选择器是由 <Popover /> 和 <Calendar /> 组件组合构建的。
🌐 The Date Picker is built using a composition of the <Popover /> and the <Calendar /> components.
请参阅 Popover 和 Calendar 组件的安装说明。
🌐 See installation instructions for the Popover and the Calendar components.
用法
🌐 Usage
"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>
)
}有关更多信息,请参阅 React DayPicker 文档。
🌐 See the React DayPicker documentation for more information.
示例
🌐 Examples
基础
🌐 Basic
一个基本的日期选择器组件。
🌐 A basic date picker component.
"use client"
import * as React from "react"范围选择器
🌐 Range Picker
用于选择日期范围的日期选择器组件。
🌐 A date picker component for selecting a range of dates.
"use client"
import * as React from "react"出生日期
🌐 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.
"use client"
import * as React from "react"输入
🌐 Input
一个带有输入字段的日期选择组件,用于选择日期。
🌐 A date picker component with an input field for selecting a date.
"use client"
import * as React from "react"时间选择器
🌐 Time Picker
一个带有时间输入字段的日期选择器组件,用于选择时间。
🌐 A date picker component with a time input field for selecting a time.
"use client"
import * as React from "react"自然语言选择器
🌐 Natural Language Picker
该组件使用 chrono-node 库来解析自然语言日期。
🌐 This component uses the chrono-node library to parse natural language dates.
"use client"
import * as React from "react"从右到左
🌐 RTL
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
🌐 To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"