Components Overlays
Toast
Announce a completed action in a dismissible status notification.
Usage
Use Trigger, Title, Description, and Dismiss for a short status message. The notification stays available until dismissed. Your application can dispatch a mono:notify event on the root, with detail.title and detail.description, to show new text.
Register toast with Head and pass its properties to Render. Go setup guide
Go usage
err := mono.UI.Render(w, "toast", mono.Props{
"Description": "Your print proof is ready for review.",
"Dismiss": "Dismiss",
"Title": "Proof ready",
"Trigger": "Show notification",
})Rendered HTML
<div id="demo-toast" data-mono="toast" class="mu-stack" data-title="Proof ready" data-description="Your print proof is ready for review.">
<button class="mu-btn" type="button" data-notify>Show notification</button>
<div class="mu-card" data-toast hidden>
<div><strong data-heading></strong><p data-body class="mu-muted"></p></div>
<button class="mu-btn mu-ghost" type="button" data-dismiss>Dismiss</button>
</div>
<span class="mu-sr-only" role="status" aria-atomic="true"></span>
</div>Go template
<div id="{{.ID}}" data-mono="toast" class="mu-stack" data-title="{{.Title}}" data-description="{{.Description}}">
<button class="mu-btn" type="button" data-notify>{{.Trigger}}</button>
<div class="mu-card" data-toast hidden>
<div><strong data-heading></strong><p data-body class="mu-muted"></p></div>
<button class="mu-btn mu-ghost" type="button" data-dismiss>{{.Dismiss}}</button>
</div>
<span class="mu-sr-only" role="status" aria-atomic="true"></span>
</div>Component CSS
[data-mono="toast"] > button { align-self: flex-start; justify-self: start; }
[data-mono="toast"] [data-toast]:not([hidden]) { display: flex; gap: 1rem; align-items: flex-start; max-width: 24rem; border-left: 3px solid #222; }
[data-mono="toast"] [data-body] { margin: .35rem 0 0; }JavaScript module
export function mount(root) {
const toast = root.querySelector('[data-toast]');
const trigger = root.querySelector('[data-notify]');
const status = root.querySelector('[role="status"]');
function show(detail = {}) {
const title = detail.title ?? root.dataset.title;
const description = detail.description ?? root.dataset.description;
toast.querySelector('[data-heading]').textContent = title;
toast.querySelector('[data-body]').textContent = description;
toast.hidden = false;
status.textContent = title + '. ' + description;
}
trigger.addEventListener('click', () => show());
root.addEventListener('mono:notify', event => show(event.detail ?? {}));
toast.querySelector('[data-dismiss]').addEventListener('click', () => {
toast.hidden = true;
status.textContent = '';
trigger.focus();
});
}Use the HTML in a static site
Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.
Shared CSS Component CSS Ready-to-use module
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./toast.css">
<script type="module" src="./toast.js"></script>Copy into your project
Run this command from the Mono checkout. Set -out to the component directory in your application.
go run ./cmd/mono-ui add -out ./components toastExample properties (JSON)
{
"Description": "Your print proof is ready for review.",
"Dismiss": "Dismiss",
"Title": "Proof ready",
"Trigger": "Show notification"
}