Date Picker
A date picker component with range and presets.
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.
pnpm dlx cubix@latest add calendar popoverUsage
"use client"
import * as React from "react"
import { format } from "date-fns"
import { ChevronDownIcon } from "lucide-react"
import { Button } from "@/components/cubix/button"
import { Calendar } from "@/components/cubix/calendar"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/cubix/popover"
export function DatePickerDemo() {
const [date, setDate] = React.useState<Date>()
return (
<Popover>
<PopoverTrigger
render={
<Button
variant="outline"
data-empty={!date}
className="w-[212px] justify-between text-left font-normal data-[empty=true]:text-muted-foreground"
/>
}
>
{date ? format(date, "PPP") : <span>Pick a date</span>}
<ChevronDownIcon data-icon="inline-end" />
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={date}
onSelect={setDate}
defaultMonth={date}
/>
</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
└── CalendarExamples
Basic
A basic date picker component.
Range Picker
A date picker component for selecting a range of dates.
Date of Birth
A date picker for selecting a date of birth, with a dropdown caption layout for month and year.
Input
A date picker with an input field for selecting a date.
Time Picker
A date picker with a time input field for selecting a time.
Natural Language Picker
This component uses the chrono-node library to parse natural language dates.
pnpm add chrono-nodeAPI Reference
See the Calendar and Popover docs, plus the React DayPicker documentation.