Date Picker

A date picker that supports ranges and quick presets.

date-fns lucide-react

Installation


1

Install the following dependencies:

npm i date-fns lucide-react
Ensure the <Popover/> and <Calendar/> component is added to your project.The Date Picker component depends on it, so make sure it’s available in your setup.See the installation instructions for Popover and Calendar components before using.
2

Create a date-picker.tsx file and paste the following code into it.

1'use client'
2
3import * as React from 'react'
4import { format } from 'date-fns'
5import { Calendar as CalendarIcon } from 'lucide-react'
6
7import { Button } from '@/components/ui/button'
8import { Calendar } from '@/components/ui/calendar'
9import {
10    Popover,
11    PopoverContent,
12    PopoverTrigger,
13} from '@/components/ui/popover'
14
15export function DatePickerDemo() {
16    const [date, setDate] = React.useState<Date>()
17
18    return (
19        <Popover>
20            <PopoverTrigger asChild>
21                <Button
22                    variant="outline"
23                    data-empty={!date}
24                    className="text-primary border-border h-10 w-32 justify-between font-medium hover:bg-gray-100 text-left"
25                >
26                    <CalendarIcon />
27                    {date ? format(date, 'PPP') : <span>Pick a date</span>}
28                </Button>
29            </PopoverTrigger>
30            <PopoverContent className="w-auto p-0">
31                <Calendar mode="single" selected={date} onSelect={setDate} />
32            </PopoverContent>
33        </Popover>
34    )
35}
36
3

Update the import paths to match your project setup.

Examples


Date of Birth Picker

Picker with Input

Date and Time Picker

Natural Language Picker

This component leverages the chrono-node library to interpret natural language dates.

Form