tvt-alert

  • public/js/tvt-alert.js
  • public/css/tvt-alert.css
  • resources/views/components/assets/tvt-alert.blade.php
  • resources/views/components/tools/tvt-alert.blade.php
  • resources/views/components/tools/tvt-alert-countdown.blade.php
  • config/alerts.php

Alerts are inline messages: they stay in the page, above what they are about, such as the notices of the booking pages (test site, booking started, time left, search expired). A tvt-toast is the message that comes and goes after an action.

<x-tools.tvt-alert> takes a type (colours and icon from config/alerts.php), a title, the text in the slot and buttons in an actions slot, in two sizes. A static alert needs no JS: the module's files load only for an alert that can be closed and for <x-tools.tvt-alert-countdown>, which switches between alerts as the time runs out.

1. Types

default (when type is left out), success, info, warning and danger. title is the first line, in bold; the slot is the text under it. icon replaces the type's icon (Font Awesome classes), :icon="false" leaves it out.

This is a test site!

The prices are not real and reservations made here are not valid.

Booking initiated successfully!

Please complete your payment process to secure your reservation.

19 minutes and 38 seconds

Time remaining for booking, including completing the payment, if you opt for online payment with the card.

Your search is about to expire!

You have 2 minutes left to complete your reservation, after which you must redo your search!

Your search has expired!

The search expires after 20 minutes. Please go to the booking engine to make a new search.
Blade
<x-tools.tvt-alert type="warning" title="Your search is about to expire!">
    You have 2 minutes left to complete your reservation, after which you must redo your search!
</x-tools.tvt-alert>

<x-tools.tvt-alert type="info" icon="fa-regular fa-plane" :title="$title">{{ $text }}</x-tools.tvt-alert>

2. Compact

size="sm": one line, small text and icon, the title in bold before the text and the actions at the end of the line. For short messages in a card, a form or an aside. It wraps on a narrow screen.

Prices include taxes and airport fees.
Your details have been saved.
Children under 2 travel free.
Only 2 rooms left at this price.
The card was declined.
Price changed: the flight now costs 642 EUR.
Blade
<x-tools.tvt-alert type="info" size="sm">Children under 2 travel free.</x-tools.tvt-alert>

<x-tools.tvt-alert type="warning" size="sm" title="Price changed:" :dismissible="true">
    the flight now costs 642 EUR.
    <x-slot:actions>
        <a href="...">See why</a>
    </x-slot:actions>
</x-tools.tvt-alert>

3. Actions

The actions slot holds the buttons or links that answer the message: under the text, or at the end of the line with size="sm". Their look is the page's: the alert only lays them out.

Booking initiated successfully!

Please complete your payment process to secure your reservation.

Your search has expired!

The search expires after 20 minutes. Please go to the booking engine to make a new search.
Blade
<x-tools.tvt-alert type="danger" title="Your search has expired!">
    The search expires after 20 minutes. Please go to the booking engine to make a new search.
    <x-slot:actions>
        <a href="..." class="...">New search</a>
        <a href="..." class="...">Back to results</a>
    </x-slot:actions>
</x-tools.tvt-alert>

4. Close, and keep closed

:dismissible="true" adds a close button (close-label is its aria-label). The alert fades and folds up, so what is under it moves up smoothly, then is removed; the keyboard focus goes to what follows it. Any [data-tvt-dismiss="alert"] inside an alert closes it, e.g. an "OK" among its actions.

remember="<id>" (dismissible by itself) keeps it closed for the rest of the session, on every page with an alert of that id: the test-site notice is closed once, not on each page. It is removed on load, before the page shows. tvtForgetAlert(id) brings it back from the next load.

This is a test site!

The prices are not real and reservations made here are not valid.

New: pay in 3 instalments

For bookings over 500 EUR, with any card.

Close an alert.

Blade
<x-tools.tvt-alert title="This is a test site!" remember="test-site">
    The prices are not real and reservations made here are not valid.
</x-tools.tvt-alert>
JS
tvtDismissAlert(alert);           // as its close button
tvtForgetAlert('test-site');      // shows again from the next load

document.addEventListener('tvt:alert-dismiss', (e) => console.log(e.target, e.detail.remember));

5. Countdown

<x-tools.tvt-alert-countdown> holds one alert per state and shows the one that matches the time left: state="running", "warning" from warning-at seconds (120 by default, in config/alerts.php; without a warning alert the running one stays) and "expired" at zero. The time is seconds from the page load or until, the end sent by the backend (the expiry of the search).

:time in a title or a text is the time left, every second. time-style: long (19 minutes, 38 seconds) and short (19 min, 38 sec), in the page's language by the browser, or digital (19:38), which is also what shows before the JS and in a browser without Intl.DurationFormat. The alert of the current state is rendered visible, so nothing moves on load.

A screen reader is told when the state changes (politely for the warning, at once for the expiry), not every second. The countdown fires tvt:alert-state and, at zero, tvt:alert-expire: below, the booking button is disabled when the search expires. This one starts at 2:15 with the warning from 2:00; the buttons restart it.

2:15

Time remaining for booking, including completing the payment, if you opt for online payment with the card.

 

Blade
<x-tools.tvt-alert-countdown :until="$searchExpiresAt" :warning-at="120">
    <x-tools.tvt-alert state="running" type="info" title=":time">
        Time remaining for booking, including completing the payment.
    </x-tools.tvt-alert>
    <x-tools.tvt-alert state="warning" type="warning" title="Your search is about to expire!">
        You have :time left to complete your reservation.
    </x-tools.tvt-alert>
    <x-tools.tvt-alert state="expired" type="danger" title="Your search has expired!">
        Please go to the booking engine to make a new search.
        <x-slot:actions><a href="...">New search</a></x-slot:actions>
    </x-tools.tvt-alert>
</x-tools.tvt-alert-countdown>
JS
countdown.addEventListener('tvt:alert-expire', () => bookButton.disabled = true);
countdown.addEventListener('tvt:alert-state', (e) => console.log(e.detail)); // { state, remaining, initial }

// starts it again: 20 minutes from now, or until a date
tvtStartAlertCountdown(countdown, 1200);
tvtStartAlertCountdown(countdown, '2026-11-06T18:20:00+02:00');

6. Classes and attributes

Every other attribute goes on the box, and class is added to its own (mb-4, or mb-2 when compact; padding, border, shadow): a width, an id for a script.

A static alert, in the page from the start, needs no role. One that a script adds after load does: role="status" (read when the reader is free) or role="alert" (read at once, for an error). The countdown needs none: it announces its changes itself.

Blade
<x-tools.tvt-alert type="danger" role="alert" class="max-w-xl" id="payment-error" title="The payment failed.">
    Your card was not charged. Please try again or use another card.
</x-tools.tvt-alert>

Props, attributes, events, functions

<x-tools.tvt-alert>

  • type: default, success, info, warning, danger (config/alerts.php)
  • title; the slot: the text; slot actions
  • size: md (default) or sm
  • icon: Font Awesome classes, false for none
  • dismissible, remember="<id>", close-label
  • state: running, warning, expired, in a countdown
  • no dark mode yet: it waits for the colour schemes

<x-tools.tvt-alert-countdown>

  • seconds from the load, or until (any date PHP parses)
  • warning-at: seconds, default countdown.warning_at (120)
  • time-style: long, short, digital; default countdown.time_style
  • :time in an alert's title or text

Events, functions

  • tvt:alert-dismiss { remember }, on the alert
  • tvt:alert-state { state, remaining, initial }, tvt:alert-expire { initial }, on the countdown
  • tvtDismissAlert(alert), tvtForgetAlert(id)
  • tvtStartAlertCountdown(countdown, secondsOrDate)
  • tvtInitAlerts(root): markup added after load