Kosorikōsori alpha

Date Picker

A date picker component with range and presets.

Installation

The date picker is built using a composition of the <Popover /> and <Calendar /> components. See installation instructions for the Popover and the Calendar components.

Usage

import { format } from 'date-fns';
import { Calendar as CalendarIcon } from 'lucide-react';
 
import { cn } from '@kosori/ui';
import { Button } from '@kosori/ui/button';
import { Calendar } from '@kosori/ui/calendar';
import { Popover, PopoverContent, PopoverTrigger } from '@kosori/ui/popover';
const [date, setDate] = React.useState<Date>()
 
  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          className={cn(
            "w-[280px] justify-start text-left font-normal",
            !date && "text-grey-text"
          )}
        >
          <CalendarIcon className="mr-2 h-4 w-4" />
          {date ? format(date, "PPP") : <span>Pick a date</span>}
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-auto p-0">
        <Calendar
          mode="single"
          selected={date}
          onSelect={setDate}
          initialFocus
        />
      </PopoverContent>
    </Popover>
  )

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.

On this page