DatePicker
A Panel which can display a month of date cells, which navigates between the cells, fires events upon user selection actions, optionally navigates to other months in response to UI gestures, and optionally displays information about each date cell. Appearance in the built-in themes:
const picker = new DatePicker({ appendTo : targetElement, width : '24em', date : DateHelper.add(new Date(), '1d'), onSelectionChange : ({ selection }) => { Toast.show(`You picked ${DateHelper.format(selection[0], 'MMM DD')}`); } }); A date is selected (meaning a single value is selected if multiSelect is not set, or added to the selection if if set) by clicking a cell or by pressing Enter when focused on a cell.
The Shift and Ctrl keys modify selection behaviour depending on the value of multiSelect.
This class is used as a picker by the DateField class.
Styling cell content via CSS
Several different CSS classes are applied to date cells depending on their state. These can be used to style contents of cells via CSS.
b-disabled-date- Applied to disabled daysb-weekend- Applied to weekend daysb-past-date- Applied to dates before todayb-today- Applied to today's dateb-non-working-day- Applied to dates which are nonWorkingDays
By default, disabled dates in a lighter color. You can override this in your own CSS, using the CSS variable API of this class.
Custom cell rendering
You can easily control the content of each date cell using the cellRenderer. The example below shows a view typically seen when booking hotel rooms or apartments.
//<code-header> CSSHelper.insertRule('#datePickerCellRenderer .b-calendar-panel-cell .b-date-picker-cell-inner { padding:0.5em 1.2em 1.2em 1.2em;}', targetElement.getRootNode()); CSSHelper.insertRule('#datePickerCellRenderer .b-date-picker-cell-payload { bottom:0.75em;}', targetElement.getRootNode()); CSSHelper.insertRule('.price { font-size: 0.65em;}', targetElement.getRootNode()); CSSHelper.insertRule('.b-calendar-panel-cell:not(.b-active-date) .price { opacity:0.65; }', targetElement.getRootNode()); //</code-header> const prices = [ 110, 80, 0, 70, 120, 80, 90, 90, 110, 80, 0, 0, 120, 80, 90, 90, 130, 60, 0, 70, 80, 90 ], picker = new DatePicker({ id : 'datePickerCellRenderer', appendTo : targetElement, width : '27em', date : new Date(), cellRenderer({ cell, cellPayload, date }) { const sameMonth = date.getMonth() === this.date.getMonth(), price = prices[date.getDate()]; cellPayload.classList.add('price'); cellPayload.innerHTML = `${sameMonth && price ? ('