timepicker-ui
4.6.0GitHub
timepicker-ui
Features / Per-day Content

Per-day Content

Show a price or any text under the day number. This page documents @pglejzer/datepicker-ui, the companion of timepicker-ui.

Prices on weekdays

#

calendar.renderDate returns a string, a DOM node, or null for no content. A string is always text, never HTML. The text is added to the accessible name of the day. Here every weekday shows a price.

renderDate only draws the cell, so call the same function in onConfirm to read the price of the picked date.

Single
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
const price = (date) =>
date.getDay() === 0 || date.getDay() === 6
? null
: `$${80 + ((date.getDate() * 7) % 90)}`;
const result = document.querySelector("#price");
new DatepickerUI("#date", {
calendar: { renderDate: price },
callbacks: {
onConfirm: ({ value }) => {
if (value && "date" in value) {
result.textContent = `${value.formatted} · ${price(value.date) ?? "no price"}`;
}
},
},
}).create();

In a range picker

#

The same function works in range mode.

Range
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
const price = (date) =>
date.getDay() === 0 || date.getDay() === 6
? null
: `$${80 + ((date.getDate() * 7) % 90)}`;
new DatepickerUI("#date", {
calendar: { mode: "range", renderDate: price },
}).create();

Note

Cells with content are taller, so the calendar grows. Keep the text short, such as a price or a count.
Esc