Primitives
Date Picker
A date picker built by combining a Popover with the Calendar component. Supports single dates, date ranges, and quick presets.
Date Picker Examples
Single Date
Date Range
With Presets
Installation
# The date picker is composed from existing primitives, already installed at:
# src/components/ui/shadcn/popover.tsx
# src/components/ui/shadcn/calendar.tsx
# src/components/ui/shadcn/button.tsx
Usage
'use client'
import * as React from 'react'
import { format } from 'date-fns'
import { CalendarIcon } from 'lucide-react'
import { Button } from '@/components/ui/shadcn/button'
import { Calendar } from '@/components/ui/shadcn/calendar'
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/shadcn/popover'
import { cn } from '@/lib/utils'
export function DatePickerDemo() {
const [date, setDate] = React.useState<Date | undefined>()
return (
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn('justify-start text-left font-normal', !date && '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>
)
}
Components
| Component | Description |
|---|---|
| Popover | Positions the calendar relative to the trigger button |
| PopoverTrigger | The button that displays the selected date |
| PopoverContent | Wraps the calendar |
| Calendar | The date grid, supports single, range, and multiple modes |
| Select | Used to build a presets dropdown (Today, Tomorrow, In a week) |