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.
| Version | 0.1.0 |
|---|---|
| File | /components/lat-toast/0.1.0/lat-toast.js (2.8 KB gzipped) |
| SHA-256 | 453e43b1c33c226c64579e806b259b71ab79bb203525fff4a71252e94e42608c |
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
<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
<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
<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
| Attribute | Values | Notes |
|---|---|---|
tone | default, warning, danger | Warning: the action failed because conditions weren't met. Danger: an error at the system level. |
action | text | Label of an optional action link. Selecting it fires action and closes the toast. |
duration | milliseconds | Default 5000; Danger defaults to 0, which stays until dismissed. |
open | boolean | Whether it's showing. Use show() and hide(). |
inline | boolean | Shows it in the page flow, always visible, with no timer or announcement. For previews and mockups. |
Slots, methods and events
| Name | Kind | Notes |
|---|---|---|
| (default) | slot | The message: a few words, sentence case. |
icon | slot | An optional 20px icon. |
show(), hide() | methods | Show it, replacing any toast that's showing, or close it. |
LatToast.show(message, options) | static method | Options: tone, action, onAction, duration. Returns the element. |
action | event | The action link was selected. |
close | event | detail.reason is timeout, dismiss, action, replaced or api. |