Basic — string message
import { html, renderApp } from 'mates';
import { FilledButton, OutlinedButton, notify } from 'mates-ui';
const App = () => () => html`
<x-row gap="var(--md-space-3)" wrap>
${FilledButton("Notify", { onClick: () => notify("Your changes have been saved.") })}
${OutlinedButton("With title", { onClick: () => notify("Pull request #42 was merged.", { title: "Merged" }) })}
</x-row>
`;
renderApp(App, document.getElementById('app'));
Variants
import { html, renderApp } from 'mates';
import { OutlinedButton, notify } from 'mates-ui';
const App = () => () => html`
<x-row gap="var(--md-space-2)" wrap>
${OutlinedButton("Default", { onClick: () => notify("Default notification.") })}
${OutlinedButton("Info", { onClick: () => notify.info("FYI — deployment started.") })}
${OutlinedButton("Success", { onClick: () => notify.success("File uploaded successfully.") })}
${OutlinedButton("Warning", { onClick: () => notify.warning("Storage is almost full.", { title: "Warning" }) })}
${OutlinedButton("Error", { onClick: () => notify.error("Connection lost.", { title: "Network error" }) })}
</x-row>
`;
renderApp(App, document.getElementById('app'));
Positions
import { html, renderApp } from 'mates';
import { TextButton, notify } from 'mates-ui';
const POSITIONS = ["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"];
const App = () => () => html`
<x-row gap="var(--md-space-2)" wrap>
${POSITIONS.map((pos) => TextButton(pos, { size: "sm", onClick: () => notify("Position: " + pos, { position: pos }) }))}
</x-row>
`;
renderApp(App, document.getElementById('app'));
Action button
import { html, renderApp } from 'mates';
import { FilledButton, OutlinedButton, notify } from 'mates-ui';
const App = () => () => html`
<x-row gap="var(--md-space-3)" wrap>
${FilledButton("With action", { onClick: () => notify("3 files deleted.", { title: "Deleted", action: { label: "Undo", onClick: () => notify.success("Restored!", { ttl: 3000 }) } }) })}
${OutlinedButton("Open PR", { onClick: () => notify.info("Review requested on PR #87.", { title: "New review", action: { label: "Open", onClick: () => {} } }) })}
</x-row>
`;
renderApp(App, document.getElementById('app'));
Rich HTML content
import { html, renderApp } from 'mates';
import { FilledButton, OutlinedButton, notify } from 'mates-ui';
const App = () => () => html`
<x-row gap="var(--md-space-3)" wrap>
${FilledButton("HTML message", { onClick: () => notify(html`Deploy to <strong>production</strong> complete in <em>1m 42s</em>.`, { variant: "success", title: "Deployed" }) })}
${OutlinedButton("Shortcut tip", { onClick: () => notify.info(html`Press <kbd style="background:var(--md-color-border);padding:0.1rem 0.3rem;border-radius:0.2rem;">Ctrl+S</kbd> to save.`) })}
</x-row>
`;
renderApp(App, document.getElementById('app'));
Persistent card + programmatic dismiss
import { html, atom, renderApp } from 'mates';
import { FilledButton, OutlinedButton, TextButton, notify } from 'mates-ui';
const App = () => {
const pid = atom(null);
return () => html`
<x-row gap="var(--md-space-3)" wrap>
${FilledButton("Show persistent", {
disabled: pid() !== null,
onClick: () => {
const id = notify.warning("This card won't auto-dismiss.", { title: "Persistent", ttl: -1, id: "demo-persistent", onDismiss: () => pid.set(null) });
pid.set(id);
},
})}
${OutlinedButton("Dismiss it", { disabled: pid() === null, onClick: () => { if (pid()) notify.dismiss(pid()); } })}
${TextButton("Dismiss all", { onClick: () => notify.dismissAll() })}
</x-row>
`;
};
renderApp(App, document.getElementById('app'));
onDismiss callback
import { html, atom, renderApp } from 'mates';
import { FilledButton, Text, notify } from 'mates-ui';
const App = () => {
const log = atom([]);
return () => html`
<x-col gap="var(--md-space-3)">
${FilledButton("Show + track", {
onClick: () => {
const ts = new Date().toLocaleTimeString();
notify("Dismiss me any way you like.", { title: "Tracked", onDismiss: () => log.set(["Dismissed at " + ts, ...log()].slice(0, 5)) });
},
})}
${log().length === 0
? Text("No events yet", { type: "body-sm", color: "muted" })
: html`<x-col gap="var(--md-space-1)">${log().map((l) => Text(l, { type: "body-sm", color: "muted" }))}</x-col>`}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));