Toast
A Duostrap timed notification with hover/focus pause, keyboard access, and action buttons.
Toast displays brief, non-blocking notifications styled with Duostrap .alert surfaces, supporting auto-dismiss timers, hover or focus pause, a top-right × close control, and link actions.
Preview
Section titled “Preview”<proto-ui-duostrap-button id="bs-toast-trigger">
Show Toast
</proto-ui-duostrap-button>
<proto-ui-duostrap-toast-viewport>
<proto-ui-duostrap-toast-root id="bs-toast-root">
<proto-ui-duostrap-toast-close>×</proto-ui-duostrap-toast-close>
<proto-ui-duostrap-toast-title>
Event has been created
</proto-ui-duostrap-toast-title>
<proto-ui-duostrap-toast-description>
Sunday, December 03, 2023 at 9:00 AM
</proto-ui-duostrap-toast-description>
<proto-ui-duostrap-toast-action>
Undo
</proto-ui-duostrap-toast-action>
</proto-ui-duostrap-toast-root>
</proto-ui-duostrap-toast-viewport>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#bs-toast-root');
setElementProps(root, { defaultOpen: false, duration: 5000 });
document
.querySelector('#bs-toast-trigger')
.addEventListener('click', () => root.getExposes().openToast());
</script>Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. Import the prototypes directly from @proto.ui/prototypes-duostrap/toast and adapt them for your target runtime.
import { toastViewport, toastRoot, toastTitle, toastDescription, toastAction, toastClose,} from '@proto.ui/prototypes-duostrap/toast';Follow Duostrap’s .alert markup convention by placing Close (×) first inside Root so its float offsets align with the top-right corner:
<DuostrapToastViewport a11yLabel="Notifications"> <DuostrapToastRoot defaultOpen={false} duration={5000}> <DuostrapToastClose>×</DuostrapToastClose> <DuostrapToastTitle>Event has been created</DuostrapToastTitle> <DuostrapToastDescription> Sunday, December 03, 2023 at 9:00 AM </DuostrapToastDescription> <DuostrapToastAction a11yLabel="Undo event creation">Undo</DuostrapToastAction> </DuostrapToastRoot></DuostrapToastViewport>- Timing and pause:
Rootstays open for5000msby default; passduration={0}to keep it open indefinitely. Hovering over the toast or focusingAction/Closepauses the remaining timer. - Actions and dismissal:
Close, pressingEscapewhile focused, andActionall request dismissal, while your application handles any side effects fromAction. In controlledopenmode, timeout emits a single dismissal request until the parent updates state. - Shortcut:
ViewportbindsF8to move keyboard focus to the notification region.
Examples
Section titled “Examples”Alert Variants
Section titled “Alert Variants”Use variant to switch between Duostrap .alert (default), .alert-info (info), .alert-success (success), and .alert-error (error).
<proto-ui-duostrap-button id="bs-info-btn">
Info
</proto-ui-duostrap-button>
<proto-ui-duostrap-toast-viewport>
<proto-ui-duostrap-toast-root id="bs-info-toast">
<proto-ui-duostrap-toast-close>×</proto-ui-duostrap-toast-close>
<proto-ui-duostrap-toast-title>
Heads up!
</proto-ui-duostrap-toast-title>
<proto-ui-duostrap-toast-description>
Arrive 10 minutes before the session starts.
</proto-ui-duostrap-toast-description>
</proto-ui-duostrap-toast-root>
</proto-ui-duostrap-toast-viewport>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const toast = document.querySelector('#bs-info-toast');
setElementProps(toast, { defaultOpen: false, variant: 'info' });
document
.querySelector('#bs-info-btn')
.addEventListener('click', () =>
toast.getExposes().openToast()
);
</script>Action
Section titled “Action”Use Action to expose an inline link command alongside the toast message.
<proto-ui-duostrap-button id="bs-schedule">
Schedule Meeting
</proto-ui-duostrap-button>
<proto-ui-duostrap-toast-viewport>
<proto-ui-duostrap-toast-root id="bs-scheduled">
<proto-ui-duostrap-toast-close>×</proto-ui-duostrap-toast-close>
<proto-ui-duostrap-toast-title>
Meeting scheduled
</proto-ui-duostrap-toast-title>
<proto-ui-duostrap-toast-description>
Design review set for Tuesday at 2:00 PM.
</proto-ui-duostrap-toast-description>
<proto-ui-duostrap-toast-action>
Undo
</proto-ui-duostrap-toast-action>
</proto-ui-duostrap-toast-root>
</proto-ui-duostrap-toast-viewport>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const toast = document.querySelector('#bs-scheduled');
setElementProps(toast, {
defaultOpen: false,
duration: 6000,
variant: 'info',
});
document
.querySelector('#bs-schedule')
.addEventListener('click', () =>
toast.getExposes().openToast()
);
</script>Controlled & Persistent
Section titled “Controlled & Persistent”Pass controlled open with duration={0} to keep a critical alert visible until the user or application dismisses it.
<proto-ui-duostrap-button id="bs-open">
Show Persistent Toast
</proto-ui-duostrap-button>
<proto-ui-duostrap-toast-viewport>
<proto-ui-duostrap-toast-root id="bs-persistent">
<proto-ui-duostrap-toast-close>×</proto-ui-duostrap-toast-close>
<proto-ui-duostrap-toast-title>
Connection lost
</proto-ui-duostrap-toast-title>
<proto-ui-duostrap-toast-description>
Changes are paused until you reconnect or dismiss this notice.
</proto-ui-duostrap-toast-description>
</proto-ui-duostrap-toast-root>
</proto-ui-duostrap-toast-viewport>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const toast = document.querySelector('#bs-persistent');
setElementProps(toast, {
open: false,
duration: 0,
politeness: 'assertive',
variant: 'error',
});
document
.querySelector('#bs-open')
.addEventListener('click', () =>
setElementProps(toast, { open: true })
);
toast.addEventListener('openChange', (e) =>
setElementProps(toast, { open: e.detail.open })
);
</script>| Prop | Type | Default |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | true |
duration | number | 5000 |
paused | boolean | false |
politeness | 'polite' 'assertive' | 'polite' |
variant | 'default' 'info' 'success' 'error' | 'default' |
appear | boolean | false |
enterDuration | number | 0 |
leaveDuration | number | 0 |
interrupt | 'reverse' 'wait' 'immediate' | 'reverse' |
Viewport, Action & Close
Section titled “Viewport, Action & Close”| Prop | Type | Default |
|---|---|---|
Viewport.a11yLabel | string | 'Notifications' |
Viewport.hotkey | string | 'F8' |
Action.disabled | boolean | false |
Action.a11yLabel | string | — |
Close.disabled | boolean | false |
Events and exposed methods:
- Events:
RootemitsopenChange({ open: boolean; reason: string });Actionemitsaction(void). - Methods:
RootexposesopenToast(),close(reason?),pause(), andresume();ViewportexposesfocusFirst().