- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Typography
"use client";
import { format } from "date-fns";
import { ChevronDownIcon } from "lucide-react";
import * as React from "react";
Installation
The Date Picker is built using a composition of the <Popover /> and the <Calendar /> components.
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>
);
}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
└── CalendarBasic
A basic date picker component.
"use client";
import { format } from "date-fns";
import * as React from "react";
import { Button } from "@/components/ui/button";Range Picker
A date picker component for selecting a range of dates.
"use client";
import { addDays, format } from "date-fns";
import { CalendarIcon } from "lucide-react";
import * as React from "react";
import type { DateRange } from "react-day-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.
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";Input
A date picker component with an input field for selecting a date.
"use client";
import { CalendarIcon } from "lucide-react";
import * as React from "react";
import { Calendar } from "@/components/ui/calendar";Time Picker
A date picker component with a time input field for selecting a time.
"use client";
import { format } from "date-fns";
import { ChevronDownIcon } from "lucide-react";
import * as React from "react";
Natural Language Picker
This component uses the chrono-node library to parse natural language dates.
"use client";
import { parseDate } from "chrono-node";
import { CalendarIcon } from "lucide-react";
import * as React from "react";
RTL
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client";
import { format } from "date-fns";
import { arSA, he } from "date-fns/locale";
import { ChevronDownIcon } from "lucide-react";
import * as React from "react";