<kern-toast>
Short, non-blocking feedback after an action („Snapshot gespeichert“). Usually created with toast(), which stacks them at the bottom right. Closes itself after duration (paused while hovered or focused), with the × or the optional action. toast() announces it through a polite live region; danger interrupts as an alert.
Examples
Showing a toast
Usually you call toast(), imported from '@yfridelance/kern'. It stacks toasts at the bottom right (at most four), announces them through a polite live region and resolves with the reason the toast closed: 'timeout', 'close' or 'action'. A plain string works as the message.
Undo action and persistent errors
actionLabel adds a button; the promise then resolves with 'action' when it is clicked. duration is in milliseconds (default 5000, paused while hovered or focused); 0 keeps the toast until the user closes it, which suits errors. danger interrupts as an alert. All toasts share one live region; setToastRegionLabel('Notifications') sets its accessible name (default „Benachrichtigungen“).
The element itself
kern-toast can also be placed directly, e.g. in a custom container. It closes itself after duration, with × (close-label) or the action, emitting kernAction and kernClose with the reason. Here duration="0" keeps them on the page.
Properties
actionLabelstring | undefined
Text of an optional action, e.g. „Rückgängig“.
closeLabelstring | undefined
durationnumber
Milliseconds until it closes itself; 0 keeps it until closed.
headingstring | undefined
tone"danger" | "info" | "neutral" | "ok" | "warn"
Events
kernActionCustomEvent<void>
The action was clicked (the toast then closes).
kernCloseCustomEvent<{ reason: KernToastReason; }>
The toast closed; reason says why.
Methods
close()close(reason?: KernToastReason) => Promise<void>
Closes the toast.
Slots
(default)Message text
CSS parts
actionThe action button