Skip to main content

Calendar

Displays the calendar grid with date selection.

Live Demoโ€‹

โ†’ Try the interactive demo in Storybook

See live examples with different configurations and styling options.

Importโ€‹

import * as DatePicker from '@legeannd/react-modular-datepicker'
;<DatePicker.Calendar />

Basic Usageโ€‹

<DatePicker.Provider type='single'>
<DatePicker.Calendar />
</DatePicker.Provider>

Propsโ€‹

PropTypeDefaultDescription
idstringundefinedCalendar identifier for Header grouping
showWeekdaysbooleantrueShow weekday headers (Sun, Mon, Tue...)
weekdayLabelsstring[]undefinedCustom weekday labels (7 items, starting with Sunday)
weekdaysContainerClassNamestringundefinedCSS classes for weekday labels container
weekdayClassNamestringundefinedCSS classes for individual weekday labels
daysContainerClassNamestringundefinedCSS classes for days grid container
dayButtonClassNamesDayButtonClassNames{}Granular day button styling
footerSlotfunctionundefinedRender prop for custom footer
classNamestringundefinedCalendar container CSS classes

Weekday Customizationโ€‹

Hide Weekdaysโ€‹

<DatePicker.Calendar showWeekdays={false} />

Custom Weekday Labelsโ€‹

<DatePicker.Calendar weekdayLabels={['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sรกb']} />

Only the first 7 items are used (Sunday through Saturday). Extra items are ignored.

Style Weekdaysโ€‹

<DatePicker.Calendar
weekdaysContainerClassName='flex justify-around mb-2 border-b pb-2'
weekdayClassName='text-xs font-semibold text-gray-600 uppercase'
/>

Day Button Stylingโ€‹

Granular control over day button states:

<DatePicker.Calendar
dayButtonClassNames={{
base: 'rounded-full aspect-square transition-colors',
selected: 'bg-blue-600 text-white',
today: 'font-bold text-blue-600 ring-2 ring-blue-500',
weekend: 'text-red-600',
disabled: 'opacity-50 cursor-not-allowed line-through',
hovered: 'bg-gray-100',
differentMonth: 'text-gray-400',
monthBoundary: 'font-semibold',
rangeStart: 'bg-blue-700 text-white rounded-l-full',
rangeEnd: 'bg-blue-700 text-white rounded-r-full',
betweenRange: 'bg-blue-100 rounded-none',
disabledInRange: 'bg-gray-100 opacity-50 line-through',
}}
/>

Available Statesโ€‹

StateDescriptionWhen Applied
baseFoundation styles for all day buttonsAlways
selectedSelected datesWhen date is selected
todayCurrent date (today)Current date, suppressed when in range
weekendWeekend days (Sat/Sun)Weekends, suppressed when hovered/selected/in range
disabledDisabled datesAlways visible, overrides all states
hoveredHovered stateOnly when not selected or in range
differentMonthPrev/next month datesDates from adjacent months
monthBoundaryFirst/last day of monthRegardless of other states
rangeStartRange start dateRange mode only
rangeEndRange end dateRange mode only
betweenRangeDates between start/endRange mode only, suppresses weekend/today
disabledInRangeDisabled dates in a rangeRange mode only

State Priorityโ€‹

States are applied with the following priority (highest to lowest):

  1. disabled - Always visible
  2. disabledInRange - Disabled dates within a range
  3. selected - Overrides hover, weekend, today
  4. rangeStart / rangeEnd - Range mode
  5. betweenRange - Range mode, suppresses weekend/today
  6. hovered - When not selected/in range
  7. today - Suppressed when in betweenRange
  8. weekend - Suppressed when hovered/selected/in range
  9. differentMonth - Always visible unless selected
  10. monthBoundary - Always visible

Add custom content below the calendar grid:

<DatePicker.Calendar
footerSlot={({ currentDate }) => (
<div className='mt-4 rounded-lg border border-blue-200 bg-gradient-to-r from-blue-50 to-purple-50 p-3'>
<p className='text-center text-sm font-medium text-gray-700'>
๐Ÿ“… {currentDate.format('MMMM YYYY')}
</p>
<p className='mt-1 text-center text-xs text-gray-500'>
{currentDate.format('dddd')}s are highlighted
</p>
</div>
)}
/>

The footerSlot receives:

  • currentDate - Day.js instance of the current calendar month

Calendar Grouping with IDโ€‹

When using multiple calendars with a Header, use id for selective grouping:

<DatePicker.Provider type='range'>
<DatePicker.Header groupingMode={['cal1', 'cal2']}>
<DatePicker.Button type='previous'>โ†</DatePicker.Button>
<DatePicker.Label />
<DatePicker.Button type='next'>โ†’</DatePicker.Button>
</DatePicker.Header>
<DatePicker.Calendar id='cal1' /> {/* Renders inside Header */}
<DatePicker.Calendar id='cal2' /> {/* Renders inside Header */}
<DatePicker.Calendar id='cal3' /> {/* Renders separately */}
</DatePicker.Provider>

See Header Component for more on grouping.

Complete Exampleโ€‹

import * as DatePicker from '@legeannd/react-modular-datepicker'
;<DatePicker.Provider type='single'>
<DatePicker.Calendar
className='rounded-lg bg-white p-4 shadow-md'
showWeekdays={true}
weekdayLabels={['S', 'M', 'T', 'W', 'T', 'F', 'S']}
weekdaysContainerClassName='border-b'
weekdayClassName='text-gray-500 font-medium'
daysContainerClassName='grid grid-cols-7 gap-1'
dayButtonClassNames={{
base: 'h-10 w-10 rounded-full',
selected: 'bg-blue-600 text-white',
today: 'border border-blue-600',
}}
/>
</DatePicker.Provider>

TypeScript Typesโ€‹

import type { CalendarProps, DayButtonClassNames } from '@legeannd/react-modular-datepicker'