Skip to content

Date Picker

A date picker component built with Calendar and Popover.

About

The Date Picker is built using a composition of the <Calendar> and <Popover> components.

Installation

The Date Picker is a composition pattern, not a standalone component. Install the required components:

pnpm dlx shadcn@latest add @frontal-labs/calendar @frontal-labs/popover @frontal-labs/button

Usage

import { format } from "date-fns";
import { CalendarIcon } from "lucide-react";
import { useState } from "react";
 
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
const [date, setDate] = useState<Date>();
 
return (
  <Popover>
    <PopoverTrigger
      render={
        <Button className="w-[280px] justify-start text-left font-normal" variant="outline" />
      }
    >
      <CalendarIcon />
      {date ? format(date, "PPP") : <span>Pick a date</span>}
    </PopoverTrigger>
    <PopoverContent align="start" className="w-auto p-0">
      <Calendar mode="single" selected={date} onSelect={setDate} />
    </PopoverContent>
  </Popover>
);

Examples

Date Range Picker

With Dropdown Navigation

Use captionLayout="dropdown" for date of birth or historical date selection:

With Presets

With Input

Close on Select

Control the popover state to close it when a date is selected: