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.success('Generator online');
FxToaster.info('Pitch calibration in progress. Check hydraulic pressure, yaw encoder offset, and generator temperature before continuing.');
FxToaster.setup({ duration: 0 }).warning('Sticky alarm stays until dismissed');

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');
toast.setup({ alertTheme: 'light' }).info('Pitch calibration in progress');

Defaults: top-center, 4000 ms, margin 16px, variant info, icon on, shadow on at 0.5 opacity, size large. alertTheme follows Fx.configure({ alertTheme }) unless setup overrides it.

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.

Toasts use the same x-small, small, medium, and large sizes as Alert. Default is large.

FxToaster.setup({ size: 'x-small' }).info('Pitch calibration in progress');
FxToaster.setup({ size: 'small' }).info('Pitch calibration in progress');
FxToaster.setup({ size: 'medium' }).info('Pitch calibration in progress');
FxToaster.setup({ size: 'large' }).info('Pitch calibration in progress');

alertTheme: 'light' uses the same pale fill and dark text as Alert. Variant accent stays on the icon and left rule. App-wide default is Fx.configure({ alertTheme: 'light' }).

const toast = FxToaster.setup({ alertTheme: 'light' });
toast.danger('Gearbox oil temp high');
toast.info('Pitch calibration in progress');

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.
shadowOpacitynumber0.5Drop shadow opacity (0–1). Sets --fx-alert-shadow-opacity on each toast.
backgroundColorstring""Fill override on each toast. Empty uses the variant background.
alertTheme"dark" | "light"from Fx.configureLight uses dark text on a pale fill. Empty follows Setup.
size"x-small" | "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, shadowOpacity, backgroundColor, alertTheme, 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.