A Calendar picker component that combines an input field with a calendar popup for easy date selection. The component supports various date formats, time selection, dialog mode for mobile devices, and extensive customization options.
Calendar component (automatically included)
DateTime utilities
Farbe color utilities
See the Example by Serhii Pimenov on CodePen .
<!-- Simple date picker -->
< input data-role = "calendar-picker" >
<!-- With initial value -->
< input data-role = "calendar-picker" value = "2024/01/15" >
< input data-role = "calendar-picker" data-label = "Select date:" >
<!-- Custom date format -->
< input data-role = "calendar-picker"
data-format = "DD, MMM YYYY"
data-input-format = "DD/MM/YYYY" >
<!-- With time selection -->
< input data-role = "calendar-picker"
data-initial-time = "14:30" >
<!-- Dialog mode for mobile -->
< input data-role = "calendar-picker"
<!-- With date restrictions -->
< input data-role = "calendar-picker"
data-min-date = "2024/01/01"
data-max-date = "2024/12/31" >
<!-- With clear button -->
< input data-role = "calendar-picker"
data-clear-button = "true" >
// Initialize programmatically
const picker = Metro . makePlugin ( '#myInput' , 'calendar-picker' , {
// Get component instance
const picker = Metro . getPlugin ( '#myInput' , 'calendar-picker' );
Parameter Type Default Description labelstring "" Label text displayed above the input valuestring "" Initial date value calendarPickerDeferrednumber 0 Deferred initialization delay nullValueboolean true Allow null/empty values useNowboolean false Use current date as default prependstring "" HTML content to prepend to input dialogModeboolean false Force dialog mode dialogPointnumber 640 Screen width breakpoint for dialog mode dialogOverlayboolean true Show overlay in dialog mode overlayColorstring ”#000000” Overlay background color overlayAlphanumber 0.5 Overlay transparency sizestring ”100%“ Input width formatstring METRO_DATE_FORMAT Display date format inputFormatstring null Input parsing format clearButtonboolean false Show clear button calendarButtonIconstring ”📅“ Calendar button icon clearButtonIconstring ”❌“ Clear button icon prevMonthIconstring ”⯇“ Previous month icon nextMonthIconstring ”⯈“ Next month icon prevYearIconstring ”⯇“ Previous year icon nextYearIconstring ”⯈“ Next year icon copyInlineStylesboolean false Copy inline styles to container openModestring ”auto” Calendar open direction (“auto”, “up”, “down”) wideboolean false Use wide calendar layout widePointnumber 640 Screen width for wide layout showTimeboolean false Enable time selection outsideboolean true Show dates outside current month weekStartnumber 0 First day of week (0=Sunday, 1=Monday) eventsarray [] Calendar events initialTimestring null Initial time value (HH:MM) initialHoursnumber null Initial hours initialMinutesnumber null Initial minutes headerFormatstring ”dddd, MMM DD” Calendar header format showWeekNumberboolean false Show week numbers rippleboolean false Enable ripple effect rippleColorstring ”#000000” Ripple effect color specialarray [] Special dates array excludearray [] Excluded dates array minDatestring null Minimum selectable date maxDatestring null Maximum selectable date yearsBeforenumber 100 Years before current year yearsAfternumber 100 Years after current year
Parameter Description clsCalendarCalendar container classes clsCalendarHeaderCalendar header classes clsCalendarContentCalendar content classes clsCalendarMonthsMonth view classes clsCalendarYearsYear view classes clsCalendarTimeTime picker classes clsTimeTime container classes clsTimeHoursHours input classes clsTimeMinutesMinutes input classes clsTimeButtonTime button classes clsTimeButtonPlusPlus button classes clsTimeButtonMinusMinus button classes clsTodayToday date classes clsSelectedSelected date classes clsExcludedExcluded date classes clsOverlayOverlay classes clsPickerPicker container classes clsInputInput field classes clsPrependPrepend content classes clsLabelLabel classes
clear() - Clear the selected date and reset to empty value.
val(value, format) - Get or set the picker value. Returns object with date and time if no arguments provided.
disable() - Disable the calendar picker.
enable() - Enable the calendar picker.
toggleState() - Toggle between enabled and disabled states.
getTime(asString) - Get the selected time. Returns array [hours, minutes] or string “HH:MM” if asString is true.
changeAttribute(attributeName, newValue) - Change component attribute dynamically.
destroy() - Destroy the component and clean up event listeners.
const picker = Metro . getPlugin ( '#myPicker' , 'calendar-picker' );
picker . val ( '2024/12/25' );
const currentValue = picker . val (); // Returns {date: Date, time: [hours, minutes]}
const timeString = picker . getTime ( true ); // Returns "14:30"
Event Description onDayClickFired when a day is clicked in the calendar onCalendarPickerCreateFired when the calendar picker is created onCalendarShowFired when the calendar popup is shown onCalendarHideFired when the calendar popup is hidden onChangeFired when the selected date changes onPickerChangeFired when the picker value changes onMonthChangeFired when the calendar month changes onYearChangeFired when the calendar year changes
< input data-role = "calendar-picker"
data-on-change = "handleDateChange"
data-on-calendar-show = "handleCalendarShow" >
function handleDateChange ( date ) {
console . log ( 'Date changed to:' , date );
function handleCalendarShow ( calendar ) {
console . log ( 'Calendar shown' );
.calendar-picker - Main container class
.calendar-for-picker - Calendar popup container
.input-calendar-button - Calendar button
.input-clear-button - Clear button
.open - Calendar is open
.open-up - Calendar opens upward
.dialog-mode - Dialog mode active
.disabled - Component is disabled
.focused - Input is focused
.calendar-wide - Wide calendar layout
.compact - Compact calendar layout
The component automatically switches to dialog mode on mobile devices based on the dialogPoint setting
Date formats follow the Metro UI date formatting conventions
The component integrates with the Metro UI theming system
Time selection is optional and can be enabled with the showTime parameter
The calendar popup automatically positions itself to stay within the viewport
Use appropriate date formats for your locale and user expectations
Enable dialog mode for better mobile experience
Set reasonable min/max date ranges to guide user selection
Use clear button for optional date fields
Consider time selection only when necessary to avoid interface complexity
Test the component across different screen sizes to ensure proper responsive behavior