Latitude ComponentsLibrary 0.1.0

Toast

A brief message confirming an action that has no visible result, such as copying a link, or reporting a problem. Called "Visual bell" in Figma. It floats at the bottom center of the window, one at a time, and screen readers announce it politely. Rules: UX Elements & Rules → Toast (R-F1).

Add it to a page

Load the pinned file once in your Latitude Site or web page, then use the tag.

<script type="module" src="https://web-components.sites.latd.com/components/lat-toast/0.1.0/lat-toast.js"></script>

The file is an ES module. It loads Lit, the design-system tokens and the Roobert stylesheet from this catalog once per page, however many components you use.

Version0.1.0
File/components/lat-toast/0.1.0/lat-toast.js (2.8 KB gzipped)
SHA-256453e43b1c33c226c64579e806b259b71ab79bb203525fff4a71252e94e42608c

An icon goes in the icon slot, usually a <lat-icon>, so load that file too. Warning and Danger bring their own.

Permutations

Default and Warning toasts leave after 5 seconds, paused while the pointer or focus is on them. Danger toasts report an error, so they stay until dismissed with their close button.

Show a toast

Dark
Copy link Link copied Save draft Some fields are missing Upload video Upload failed. Try again.
Light
Copy link Link copied Save draft Some fields are missing Upload video Upload failed. Try again.
<lat-button onclick="this.nextElementSibling.show()">Copy link</lat-button>
<lat-toast><lat-icon slot="icon" name="check"></lat-icon>Link copied</lat-toast>
<lat-button onclick="this.nextElementSibling.show()">Save draft</lat-button>
<lat-toast tone="warning" action="Review">Some fields are missing</lat-toast>
<lat-button onclick="this.nextElementSibling.show()">Upload video</lat-button>
<lat-toast tone="danger">Upload failed. Try again.</lat-toast>

Tones, shown in place

Dark
Link copied Some fields are missing Upload failed. Try again.
Light
Link copied Some fields are missing Upload failed. Try again.
<div style="display: grid; gap: 12px; justify-items: start">
  <lat-toast inline><lat-icon slot="icon" name="check"></lat-icon>Link copied</lat-toast>
  <lat-toast inline tone="warning" action="Review">Some fields are missing</lat-toast>
  <lat-toast inline tone="danger">Upload failed. Try again.</lat-toast>
</div>

From script

Dark
Copy link Move to Archive
<lat-button onclick="customElements.get('lat-toast').show('Link copied')">Copy link</lat-button>
<lat-button onclick="customElements.get('lat-toast').show(
  'Video moved to Archive', { action: 'Undo' })">Move to Archive</lat-button>

Showing one from script

show() creates the toast, adds it to the page, and removes it once it closes. A toast made this way sits on the page's own ground, so it follows data-theme on <html> or <body>.

customElements.get("lat-toast").show("Link copied");

customElements.get("lat-toast").show("Video moved to Archive", {
  action: "Undo",
  onAction: () => restoreVideo(),
});

customElements.get("lat-toast").show("Upload failed. Try again.", { tone: "danger" });

Attributes

AttributeValuesNotes
tonedefault, warning, dangerWarning: the action failed because conditions weren't met. Danger: an error at the system level.
actiontextLabel of an optional action link. Selecting it fires action and closes the toast.
durationmillisecondsDefault 5000; Danger defaults to 0, which stays until dismissed.
openbooleanWhether it's showing. Use show() and hide().
inlinebooleanShows it in the page flow, always visible, with no timer or announcement. For previews and mockups.

Slots, methods and events

NameKindNotes
(default)slotThe message: a few words, sentence case.
iconslotAn optional 20px icon.
show(), hide()methodsShow it, replacing any toast that's showing, or close it.
LatToast.show(message, options)static methodOptions: tone, action, onAction, duration. Returns the element.
actioneventThe action link was selected.
closeeventdetail.reason is timeout, dismiss, action, replaced or api.