Skip to content

Toaster

Class: FxToaster · Tag: <fx-toaster>

<fx-toaster> hosts a stack of alerts at a screen corner (or the top center). Call FxToaster.danger('…') (or info, success, …). Use setup only when you need to change defaults. You rarely place the host in markup yourself.


import '@salsafx/ui';

Press a button to show a toast (sticky stays until you close it):

import { FxToaster } from '@salsafx/ui';
FxToaster.danger('Gearbox oil temp high');
FxToaster.setup({ duration: 0 }).warning('Sticky alarm stays until dismissed');
FxToaster.setup({ placement: 'top-end' }).info('Pitch calibration in progress');

Use setup when the defaults are not enough. The handle keeps those options for later show / danger / … calls. A later setup patch merges with the previous handle.

const toast = FxToaster.setup({
placement: 'top-end',
duration: 4000,
margin: 24,
size: 'large',
});
toast.success('Generator online');
toast.setup({ duration: 1000 }).danger('Short danger');

Defaults: top-center, 4000 ms, margin 16px, variant info, icon on, shadow on, size large.

top or bottom, combined with start, center, or end:

top-start · top-center · top-end · bottom-start · bottom-center · bottom-end

A duration greater than 0 auto-hides the toast. Click the toast to dismiss it early.

duration: 0 keeps the toast until the close control is used.

Long messages wrap. The icon stays vertically centered on the wrapped text.


FieldTypeDefaultDescription
placementToasterPlacement"top-center"Screen corner or top/bottom center.
durationnumber4000Milliseconds. 0 is sticky.
marginstring | number16Inset from the viewport edge.
variantVariantInfoDefault look for show().
iconstring""Icon override. Empty uses the variant icon.
hasIconbooleantrueLeading icon.
hasShadowbooleantrueDrop shadow.
size"small" | "medium" | "large""large"Alert size.

The handle exposes show(text, options?) plus primary, secondary, success, danger, warning, info, light, and dark. Each helper sets that variant. show / helpers return a toast id.

Per-call options may override variant, icon, hasIcon, hasShadow, size, duration, and placement.

PropertyAttributeTypeDefaultDescription
placementplacementString"top-center"Same tokens as setup.
durationdurationNumber4000Default auto-hide for show() on this host.
marginmarginString | Number16Viewport inset.

The same helpers exist on FxToaster itself (FxToaster.danger('…'), …) and use the default setup. The handle from setup is for a custom configuration.


classDiagram
    direction TB
    class FxElement
    class FxToaster
    FxElement <|-- FxToaster

See also Architecture, Alert, and Variants.