Components/Feedback/Toast
COMPONENT50.50

Toast

Stacked notifications via window.mo.toast or declarative data-toast triggers. Hover pauses the timer; placement and duration are options.


INSTALL

1pnpm dlx @sayagodev/mo add toast

Or import the files from the package (no copy):

1import "@sayagodev/mo/css/toast.css";2import "@sayagodev/mo/js/toast.js";

EXAMPLES

Show toast
Types
Promise result
With action
Triggers

USAGE

1<!-- declarative -->2<button data-toast="Saved!" data-toast-title="Success"3        data-toast-variant="success" data-toast-placement="bottom-right">4  Show Toast5</button>6 7<!-- imperative -->8mo.toast('Message', 'Title', { variant: 'success', placement: 'top-right' })9mo.toast.promise(promise, {10  loading: 'Saving…',11  success: (data) => `Saved as ${data.name}`,12  error: (err) => err.message,13})14mo.toast.el(templateOrElement, { duration: 0 })15mo.toast.clear(placement?)16mo.toast.dismiss(placement?)  // alias of clear

API

NAMEKINDDESCRIPTION
[data-toast]attributeClick-to-toast trigger; message is the value
-title / -variant / -placement / -durationattributeTrigger option attributes
mo.toast.elelementRender a <template>/element as toast; duration: 0 keeps it until dismissed
mo.toast.dismisselementAlias of clear; dismisses all toasts (or one placement)
mo.toast.promiseelementLoading → success/error on one toast updated in place; success/error take msg or fn(result|error)
varianttokeninfo · success · warning · danger (sets --variant-color)
placementtokentop/bottom + left/center/right
.toast-title / .toast-messageclassMarkup API for custom el() toasts

FILES

src/css/toast.csssrc/js/toast.js
Install:mo add toast

THEMING · PLAYGROUND

This is the exact component from the examples above, wearing a completely different theme. Edit the tokens and --mo-* hooks in the editor — autocomplete knows them all — and the preview obeys in real time. Your CSS always wins.

Tokens & hooks — edit live
Global tokens
--border--destructive--foreground--muted-foreground--popover--popover-foreground--radius--success--warning
Component hooks
--mo-toast-max-width--mo-toast-min-width--mo-toast-padding

Preview

Your CSS

Try it: type --mo- for the component hooks, or edit any value — the preview obeys in real time.