Date Picker Component

A customizable calendar component for date picking with multiple views, built with React Day Picker and Tailwind CSS.

  • Support for day, month, quarter, and year views
  • Range selection capability
  • Customizable styling
  • Fully accessible with ARIA attributes
  • Responsive design

Installation

The Date Picker component is part of our UI library. You can import it directly from the components directory.


Usage

Here is how to use the date picker in your project.

React TSX
1import DatePicker, { 
2  DateRangePicker, 
3  MonthPicker, 
4  QuarterPicker, 
5  YearPicker 
6} from "@/components/modern-ui/date-picker"

Date Picker

The DatePicker component allows users to select a single date.

Date Range Picker

The DateRangePicker allows users to select a range of dates, which is ideal for booking applications, event planning, or any scenario that requires a date range selection.

Month Picker

The MonthPicker component is useful when you need users to select an entire month instead of a specific date.

Quarter Picker

The QuarterPicker component allows users to select a quarter of a year, which is useful for financial or business applications.

Year Picker

The YearPicker component is perfect for when you need users to select an entire year.


API Reference

Calendar Props

PropTypeDefaultDescription
mode"single" | "range" | "multiple""single"The selection mode of the calendar
selectedDate | DateRange | Date[]undefinedThe selected date or dates
onSelect(date: Date | DateRange | Date[] | undefined) => voidundefinedFunction called when a date is selected
classNamestring""Additional CSS classes
showOutsideDaysbooleantrueShow days from the previous and next months
showYearSwitcherbooleantrueShow the year switcher in the caption
yearRangenumber12Number of years to display in year view
numberOfMonthsnumber1Number of months to display side by side
disabledDate[] | ((date: Date) => boolean)undefinedDates to disable or function to determine if a date should be disabled
fromDateDateundefinedThe earliest date that can be selected
toDateDateundefinedThe latest date that can be selected
defaultMonthDateundefinedThe month to display initially
initialView"days" | "months" | "quarters" | "years""days"The initial view of the calendar

DatePicker Props

PropTypeDefaultDescription
dateDateundefinedThe selected date
setDate(date: Date | undefined) => voidundefinedFunction called when a date is selected
classNamestringundefinedAdditional CSS classes
placeholderstring"Pick a date"Placeholder text to display when no date is selected

DateRangePicker Props

PropTypeDefaultDescription
dateRangeDateRangeundefinedThe selected date range
setDateRange(dateRange: DateRange | undefined) => voidundefinedFunction called when a date range is selected
classNamestringundefinedAdditional CSS classes
placeholderstring"Pick a date range"Placeholder text to display when no date range is selected
numberOfMonthsnumber2Number of months to display side by side

MonthPicker Props

PropTypeDefaultDescription
monthDateundefinedThe selected month
setMonth(month: Date | undefined) => voidundefinedFunction called when a month is selected
classNamestringundefinedAdditional CSS classes
placeholderstring"Pick a month"Placeholder text to display when no month is selected

QuarterPicker Props

PropTypeDefaultDescription
quarterDateundefinedThe selected quarter
setQuarter(quarter: Date | undefined) => voidundefinedFunction called when a quarter is selected
classNamestringundefinedAdditional CSS classes
placeholderstring"Pick a quarter"Placeholder text to display when no quarter is selected

YearPicker Props

PropTypeDefaultDescription
yearDateundefinedThe selected year
setYear(year: Date | undefined) => voidundefinedFunction called when a year is selected
classNamestringundefinedAdditional CSS classes
placeholderstring"Pick a year"Placeholder text to display when no year is selected

Custom Styling

The Calendar component supports extensive customization through className props:

  • monthsClassName
  • monthCaptionClassName
  • weekdaysClassName
  • weekdayClassName
  • monthClassName
  • captionClassName
  • captionLabelClassName
  • buttonNextClassName
  • buttonPreviousClassName
  • navClassName
  • monthGridClassName
  • weekClassName
  • dayClassName
  • dayButtonClassName
  • rangeStartClassName
  • rangeEndClassName
  • rangeMiddleClassName
  • selectedClassName
  • todayClassName
  • outsideClassName
  • disabledClassName
  • hiddenClassName