tvt-calendar

  • public/js/tvt-calendar.js
  • public/css/tvt-calendar.css
  • resources/views/components/assets/tvt-calendar.blade.php

Inline date picker for Travitude, no dependencies. Every colour and size is a CSS custom property. A calendar is framed by default; border: false drops the frame when its host is one already, like a modal.

It has its own width by default (--tvt-cal-month-width per month, narrower on a narrow screen), which also sizes a dropdown around it; fullWidth: true fills the container instead, with wider days. The switches below set both on every calendar of the page.

Brand
Border
Width 100%
Markers
Marker left

1. Booking: date range, two months

Hotels and packages. Days before today and past months cannot be picked. Two months from 768px, one below (resize the window). At least one night: the same day clicked twice keeps only the check-in. Up to 18 months ahead.

Pick the check-in and check-out dates.

new tvtCalendar('#demo-range', {
    preset: 'booking',          // nothing before today
    mode: 'range',
    months: 'auto',             // 2 from 768px, 1 below
    minNights: 1,
    maxDate: '+18m',
    inputs: { start: '#demo-range-start', end: '#demo-range-end' },  // hidden, Y-m-d
});

2. Booking: one date, one month

A one-way flight or a departure date. Today has the brand border; the picked date is filled.

Pick a date.

new tvtCalendar('#demo-single', { preset: 'booking' });

3. Birth date: typed or picked

Days after today and the next months cannot be picked; 120 years back. Type the date (the dots are added as you type, 5. becomes 05.) or pick it, with the month and year selects for the jump. A date that does not exist or is in the future marks the field invalid.

Type or pick a date.

new tvtCalendar('#demo-birth', {
    preset: 'birthdate',        // nothing after today, 120 years back, month / year selects
    textInput: '#demo-birth-input',
});

4. Child birth date: age limits

A child aged 2 to 11 on the return date (): only the birth dates that give that age can be picked. The limits move with ageOn (calendar.set({ ageOn })).

Type or pick a date.

new tvtCalendar('#demo-child', {
    preset: 'birthdate',
    minAge: 2,
    maxAge: 11,
    ageOn: returnDate,          // 'YYYY-MM-DD'
    textInput: '#demo-child-input',
});

5. Prices in the days

The price calendar of the transport tabs. renderDay adds the price (.tvt-cal__day-label) and .is-price, which gives the day the brand border. A day whose price has to be checked is a link (dayHref): sky, darker on hover, and a click follows the link instead of picking the day. disable leaves out the days without an offer. Taller days through --tvt-cal-day-height; at full width (the switch above) the days are square instead, up to 7.5rem, as in the transport tabs: --tvt-cal-day-height: auto; --tvt-cal-day-aspect: 1; --tvt-cal-day-max-width: 7.5rem.

A special offer is marked with a triangle in a corner (dayMarker; the Markers and Marker left switches above set markers and markerSide). Its colour is --tvt-cal-marker in the CSS, or markerColor for one calendar (the Marker colour picker).

Special offer

Pick a departure with an offer.

new tvtCalendar('#demo-prices', {
    preset: 'booking',
    months: 'auto',
    openOn: firstOfferDate,     // not today's month, which may have no offer
    disable: (iso) => !offers[iso],
    // offers[iso]: { price: '1861 €', special: true } or { check: true }
    dayHref: (iso) => (offers[iso].check ? `/check-price?date=${iso}` : null),
    // true, or the text read by screen readers and shown on hover (default: labels.marker)
    dayMarker: (iso) => (offers[iso].special ? 'Special offer' : null),
    markerColor: '#f59e0b',     // optional: --tvt-cal-marker for this calendar
    renderDay: (day, { iso }) => {
        const offer = offers[iso];
        if (!offer) return;
        if (offer.price) day.classList.add('is-price');
        const label = document.createElement('span');
        label.className = 'tvt-cal__day-label';
        label.textContent = offer.price || 'check price';
        day.append(label);
    },
});

Keyboard, events, methods

Keyboard

  • ← → ↑ ↓ day / week
  • Home End start / end of the week
  • PgUp PgDn month, with Shift year
  • Enter Space pick

Events (on the element)

  • tvt:calendar-change { start, end, nights, startDate, endDate }
  • tvt:calendar-month { year, month }

Methods

  • setDate(value, { silent }), clear(), getValue()
  • jumpTo('2027-05'), setMonths(1 | 2 | 'auto')
  • set(options), isDisabled(date), destroy()
  • tvtCalendar.formatDate(iso, 'l, d F Y')