Skip to content

Calendar

The Calendar component provides a versatile and customizable way to display dates, select dates, and manage date-related events. It supports various display modes, date selection options, and styling capabilities.

See the Example by Serhii Pimenov on CodePen.

<!-- Basic calendar -->
<div class="calendar" data-role="calendar"></div>
<!-- Calendar with specific date shown -->
<div class="calendar" data-role="calendar" data-show="2023-12-25"></div>
<!-- Calendar with date selection -->
<div class="calendar" data-role="calendar" data-preset="2023-12-25"></div>
<!-- Static calendar (non-interactive) -->
<div class="calendar" data-role="calendar" data-static="true"></div>
<!-- Read-only calendar -->
<div class="calendar" data-role="calendar" data-readonly="true"></div>
<!-- Picker mode (for date selection) -->
<div class="calendar" data-role="calendar" data-picker-mode="true"></div>
<!-- Compact calendar -->
<div class="calendar" data-role="calendar" data-compact="true"></div>
<!-- Wide calendar -->
<div class="calendar" data-role="calendar" data-wide="true"></div>
<!-- Calendar with time selection -->
<div class="calendar" data-role="calendar" data-show-time="true"></div>
<!-- Calendar with initial time -->
<div class="calendar" data-role="calendar" data-show-time="true" data-initial-time="14:30"></div>
<!-- Calendar with minimum date -->
<div class="calendar" data-role="calendar" data-min-date="2023-01-01"></div>
<!-- Calendar with maximum date -->
<div class="calendar" data-role="calendar" data-max-date="2023-12-31"></div>
<!-- Calendar with excluded dates -->
<div class="calendar" data-role="calendar" data-exclude="2023-12-25,2023-12-26"></div>
<!-- Calendar with excluded days of week (0=Sunday, 6=Saturday) -->
<div class="calendar" data-role="calendar" data-exclude-day="0,6"></div>
<!-- Calendar with events -->
<div class="calendar" data-role="calendar" data-events="2023-12-25,2023-12-31"></div>
<!-- Calendar with multiple date selection -->
<div class="calendar" data-role="calendar" data-multi-select="true"></div>
<!-- Calendar with preset selected dates -->
<div class="calendar" data-role="calendar" data-multi-select="true" data-preset="2023-12-25,2023-12-31"></div>
OptionDefaultDescription
weekStartnullFirst day of week (0 for Sunday, 1 for Monday, etc.)
staticfalseIf true, calendar becomes non-interactive
readonlyfalseIf true, calendar is read-only
showGhostfalseIf true, shows ghost days from previous/next months
eventsnullArray or comma-separated string of dates with events
startContent”days”Initial content to show (“days”, “months”, “years”)
showTimefalseIf true, shows time selection
initialTimenullInitial time in format “HH:MM”
initialHoursnullInitial hours value (0-23)
initialMinutesnullInitial minutes value (0-59)
labelTimeHoursnullCustom label for hours
labelTimeMinutesnullCustom label for minutes
animationContenttrueIf true, enables content animation
animationSpeed10Animation speed in milliseconds
dayBorderfalseIf true, shows borders around days
excludeDaynullArray or comma-separated string of days to exclude (0-6)
prevMonthIcon”⯇“Icon for previous month button
nextMonthIcon”⯈“Icon for next month button
prevYearIcon”⯇“Icon for previous year button
nextYearIcon”⯈“Icon for next year button
compactfalseIf true, shows calendar in compact mode
widefalseIf true, shows calendar in wide mode
widePointnullBreakpoint for wide mode
pickerModefalseIf true, enables date picker mode
shownullDate to show initially
outsidetrueIf true, allows selection of days outside current month
buttons""Buttons to show in footer (“cancel”, “today”, “clear”, “done”)
yearsBefore100Number of years to show before current year
yearsAfter100Number of years to show after current year
headerFormat”dddd, MMM DD”Format for header date
showHeadertrueIf true, shows calendar header
showFootertrueIf true, shows calendar footer
showWeekNumberfalseIf true, shows week numbers
isDialogfalseIf true, calendar is used in dialog mode
ripplefalseIf true, enables ripple effect
rippleColor”#cccccc”Color for ripple effect
excludenullArray or comma-separated string of dates to exclude
presetnullArray or comma-separated string of preset selected dates
minDatenullMinimum selectable date
maxDatenullMaximum selectable date
weekDayClickfalseIf true, enables clicking on week days
weekNumberClickfalseIf true, enables clicking on week numbers
multiSelectfalseIf true, enables multiple date selection
specialnullArray or comma-separated string of special dates
formatMETRO_DATE_FORMATFormat for date output
inputFormatnullFormat for date input
MethodParametersReturnDescription
getTimeasString (boolean)Array or StringGets current time as array [hours, minutes] or string “HH:MM”
setTimetime (Array or String)ObjectSets current time from array [hours, minutes] or string “HH:MM”
getPreset-ArrayGets preset dates
getSelected-ArrayGets selected dates
getExcluded-ArrayGets excluded dates
getToday-ObjectGets today’s date
getCurrent-ObjectGets current date shown in calendar
clearSelected-ObjectClears all selected dates
toDay-ObjectSets calendar to today’s date
setExcludeexclude (Array or String)ObjectSets excluded dates
setPresetpreset (Array or String)ObjectSets preset selected dates
setSpecialspecial (Array or String)ObjectSets special dates
showDatedate (String or Object)ObjectShows specified date
setShowshow (String or Object)ObjectSets date to show
setMinDatedate (String or Object)ObjectSets minimum selectable date
setMaxDatedate (String or Object)ObjectSets maximum selectable date
destroy--Destroys the calendar component
EventDescription
onCancelTriggered when cancel button is clicked
onTodayTriggered when today button is clicked
onClearTriggered when clear button is clicked
onDoneTriggered when done button is clicked
onDayClickTriggered when a day is clicked
onDrawDayTriggered when a day is drawn
onDrawMonthTriggered when a month is drawn
onDrawYearTriggered when a year is drawn
onWeekDayClickTriggered when a week day is clicked
onWeekNumberClickTriggered when a week number is clicked
onMonthChangeTriggered when month is changed
onYearChangeTriggered when year is changed
onTimeChangeTriggered when time is changed
onHoursChangeTriggered when hours are changed
onMinutesChangeTriggered when minutes are changed
onCalendarCreateTriggered when calendar is created

The Calendar component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
—calendar-background#ffffff#2b2d30Background color of the calendar
—calendar-header-background#fafafa#43454aBackground color of the calendar header
—calendar-header-color#191919#dfe1e5Text color of the calendar header
—calendar-weekday-background#f8f8f7#414245Background color of weekday row
—calendar-weekday-color#191919#dfe1e5Text color of weekday row
—calendar-border-color#dddddd#414245Border color of the calendar
—calendar-color#191919#dfe1e5Text color of the calendar
—calendar-day-border-color#e8e8e8#4a4d51Border color of days
—calendar-exclude-day-background#ffffff#2b2d30Background color of excluded days
—calendar-exclude-day-color#aaa#818181Text color of excluded days
—calendar-today-day-background#56c30f#56c30fBackground color of today
—calendar-today-day-color#fff#fffText color of today
—calendar-border-radius6px6pxBorder radius of the calendar
/* Custom styling for a specific calendar */
#myCustomCalendar {
--calendar-background: #f0f8ff;
--calendar-header-background: #1e88e5;
--calendar-header-color: #ffffff;
--calendar-today-day-background: #ff5722;
--calendar-border-radius: 12px;
}
  • .calendar - Main calendar container
  • .compact - Compact calendar
  • .day-border - Calendar with day borders
  • .calendar-header - Calendar header
  • .calendar-content - Calendar content area
  • .calendar-footer - Calendar footer
  • .calendar-time - Time selection area
  • .selected - Selected date
  • .excluded - Excluded date
  • .today - Today’s date
  • .special - Special date
  • .outside - Date outside current month
  • .weekend - Weekend date

The Calendar component includes proper semantics for improved accessibility:

  • Proper ARIA roles and attributes for interactive elements
  • Keyboard navigation support
  • Screen reader friendly structure
  • High contrast support through CSS variables
  1. Use appropriate date formats for your target audience
  2. Provide clear visual indication of selected dates
  3. Use the minDate and maxDate options to limit date selection when appropriate
  4. Consider using the exclude option for dates that should not be selectable
  5. Implement appropriate event handlers to respond to user interactions
  6. Use CSS variables for consistent styling across your application