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.

Usage

'use client';
 
import { Button } from '@/components/ui/button';
import { Calendar } from '@/components/ui/calendar';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import clsx from 'clsx';
import { format } from 'date-fns';
import { Calendar as CalendarIcon } from 'lucide-react';
import { useState } from 'react';
import styles from './styles.module.scss';
 
const DatePickerDemo = () => {
    const [date, setDate] = useState<Date>();
 
    return (
        <Popover>
            <PopoverTrigger asChild>
                <Button variant={'outline'} className={clsx(styles.trigger__btn, !date && styles.trigger__btn__muted)}>
                    <CalendarIcon className={styles.trigger__btn__icon} />
                    {date ? format(date, 'PPP') : <span>Pick a date</span>}
                </Button>
            </PopoverTrigger>
            <PopoverContent className={styles.popover__container}>
                <Calendar mode='single' selected={date} onSelect={setDate} initialFocus />
            </PopoverContent>
        </Popover>
    );
};
 
export default DatePickerDemo;

See the React DayPicker documentation for more information.

Examples

Date Picker

Date Range Picker

With Presets

Form

Your date of birth is used to calculate your age.