Components · Notifications

Toast

A toast is short-lived feedback on something the user just did: saved, copied, failed. It slides in, says its piece and leaves without blocking the page.

How to show a toast from script and the CSS behind it. The files are eco-design-system/notifications.css and notifications.js.

Basic Usage

Link the shared files once per page. Never copy the rules into a page.

StepWhat to do
1. Link<link rel="stylesheet" href="/eco-design-system/notifications.css"> and <script src="/eco-design-system/notifications.js"></script>. Link button.css first.
2. Show a toastCall ECO_N.showToast({ status, text }). The script adds the fixed host, the slide and the dismissal.
3. ChooseStatus info | success | warning | error. Emphasis weak (default) or strong (sparingly).
4. ActionsOptional: actions.primary and actions.secondary as buttons, or actions.links as inline links.
5. Auto-hideautoHide: 4000 for a confirmation. Leave it out for a Warning or an Error.

Toast

The markup has no motion. The slide is set in Motion on Examples & Guidelines.


API

Settings of showToast

SettingUse
statusinfo (default), success, warning, error.
emphasisweak (default) or strong.
title, textOptional title and the text.
iconInformational only: a Material Symbols name, shown as Outlined.
actions{ primary, secondary } (each { label, onClick }) or { links: [{ label, onClick }] }.
autoHideMilliseconds; 0 or empty = stays until dismissed.

Custom properties

NameUse
--toast-in-ease, --toast-in-durationEnter. Defaults: ease-decelerate-emphasized, duration-medium-2.
--toast-out-ease, --toast-out-durationExit. Defaults: ease-accelerate-generic, duration-medium-2.

Things to know

  • Only one toast is on screen: showToast replaces the current one.
  • Set the custom properties on <html> or on .toast-host.
  • ECO_N.dismissToast() closes the current toast.
  • Buttons inside a toast are always 32px high, also when button.css is on the page.

CSS / Tailwind

The component is one CSS file and one script, shared by every notification. Link them, never copy them. The code below is read from the files the page links, so it is always what you see.