Skip to content

Transient feedback fired from anywhere. A toast() that stacks, pauses on hover and dismisses itself, rendered by the plugin.

import { BbToast } from 'bitboss-ui';

On this page

Use it for

A toast is a short notification about what just happened: "Changes saved", "Upload complete", "Copied to clipboard". It appears in a corner of the screen, stacks with its siblings, and disappears on its own after four seconds.

Use something else when

  • BbAlert, when the message describes the current state of the page and has to stay until someone deals with it
  • BbConfirm, when the user has to decide rather than be told

Never put information a user must act on only in a toast: it is gone before they look up.

Like BbConfirm, this is not a control you place. The plugin renders the <BbHost /> that shows every toast, and everything you write goes through useToast().

Passthrough

Hover or tap a part to outline it. The toggles turn on loading, errors and warnings where the component has them; only parts get a row.

Nothing to mount, then a function

Install the plugin and call toast(): it works from anywhere, and there is nothing to mount. The plugin (app.use(bitbossUiPlugin), or the Nuxt module) renders a <BbHost /> beside your app, and the same host renders every confirm too.

ts
const { toast } = useToast();
toast({ text: 'Saved', variant: 'success' });

toast, update and dismiss all operate on one shared module-level stack, so every useToast() call in the app talks to the same host. Without the plugin there is no host: messages wait in a queue and show once one mounts.

A toast takes the pt scope and the theme tokens of the place its host sits, not of the code that fired it, and the plugin's host sits beside the app. When areas of the app sit under different named scopes and toasts need each area's look, place one <BbHost /> inside each area's layout, within its <BbConfigScope>. A placed host takes over from the plugin's while it is mounted, so a page outside every area keeps the plugin's. Never place one per page: a second placed host renders nothing.

Fire toasts from event handlers and settled requests, never from setup during server rendering: on the server there is nothing to render them into.

What toast() takes

OptionDefaultWhat it does
titlenoneThe bold line, a string or a function that renders it; toast('…') sets only this
textnoneBody copy under the title, a string or a function
variant'default'success, info, warning, destructive or a registered name
iconthe variant'sThe leading icon, such as 'lucide:circle-check'; wins over the variant's
hideIconfalseHides the icon, the variant's or its own; the spinner still shows
prioritythe variant's'assertive' interrupts the screen reader, 'polite' waits its turn
loadingfalseA spinner in place of the icon; keeps the toast open
duration4000Milliseconds on screen, always above zero
persistentloadingNever leaves on its own
hideClosefalseHides the ×; with persistent, only when your code calls dismiss(id)
positionthe plugin's BbToast.positionA corner, physical or by reading direction
actionsnoneButtons under the text
portal, datanoneA <BbToastPortal> name, or a component, that renders the whole body; data is what it renders
onClosenoneRuns once as it leaves, with the reason: 'close', 'swipe', 'hide', 'auto' or 'action'
idgeneratedReuse one to patch that toast in place

useToast() returns toast, update(id, patch) and dismiss(id); dismiss() with no id clears every toast.

Communicate an outcome

toast('Changes saved.') is the whole shorthand. The object form adds a body, a tone and an icon.

A variant tints the icon and sets the announcement priority, nothing else. Without an icon, a success toast looks like a default one, so give each variant its icon once, in the plugin options (Variants and CSS hooks), instead of on every call. Dev builds warn when a built-in variant arrives without one.

warning and destructive announce assertively (role="alert"); every other variant is polite. Use the loud two sparingly, or they stop meaning anything. A toast's own priority wins over its variant's, for the one message that has to interrupt (or the one warning that can wait).

duration defaults to 4000ms and must be greater than zero, or toast() throws. "Never dismiss" is persistent: true, not duration: 0. Set the app's default in the plugin's components map: BbToast: { duration: 6000 }. The call returns the message id, which the next two sections are about.

Coming from v2

The options object was rewritten: theme is variant, timeout is duration (its default fell from 6000ms to 4000ms), and showClose inverted into hideClose. They are call options, not template attributes, so no markup check sees them. A dev build warns once per call that still passes one and names the replacement; a production build drops the key.

Loading, then the result

Work that takes a moment gets one message, not two.

loading: true shows a spinner and pins the toast open. It implies persistent, so the countdown never starts and a swipe cannot lose it. Keep the id, and when the work settles update(id, …) morphs the same card in place and restarts the countdown. Pass loading: false in that update, or the spinner and the pinning stay.

update on an id that has already left the stack is a safe no-op. A slow request resolving after the user cleared the corner is not a crash. Each toast is announced whole, so the morph from loading to done is read out again.

A message that must stay until dismissed takes persistent: true. Add hideClose only when your own code will call dismiss(id): the two together, with nothing to dismiss the toast, trap it on screen forever.

One toast per concern

Pass your own id and toast() becomes an upsert.

0 revisions this session

If a toast with that id is still live, it is patched in place and its countdown restarts instead of a duplicate stacking behind it. Use a stable id for anything repeatable, such as autosave ticks, connection status or "copied to clipboard", so hammering the action never floods the corner.

Fields you omit keep their previous value; fields you pass overwrite, including the ones you can set back to undefined. It is the same mechanism update uses; the difference is that update never creates.

Buttons on a toast

An actions array renders buttons in a row under the text, and carries the undo pattern.

Saved replies

  • Thanks, we are on it
  • Your refund is on its way
  • Escalated to engineering

Commit the delete immediately, with no confirm dialog, and let the toast hold the escape hatch: the action's closure keeps the removed record, and if the toast expires the delete stands. This is the right trade when undoing is cheap and complete. When it is not, you want BbConfirm before the fact instead.

While a button's onClick runs it shows a spinner, its siblings are disabled and the countdown is held; the toast dismisses itself when the callback resolves. Two behaviours compose out of that: a rejected handler keeps the toast open and resumes the countdown, which is a retry, and a handler that calls update(id, …) takes ownership: the toast morphs in place with a fresh countdown rather than dismissing.

Each action is a small primary button unless you pass variant or size; iconOnly with a prepend:icon shows the icon alone, its text kept as the accessible name. An action with items becomes a split button whose entries run like the action itself (as on the dialog). One or two actions is the limit. A message that needs more, or that must not be missed, is a dialog.

For a bold name or a badge inside the line, pass a function as title or text. It renders in place, and a reactive value read inside it updates the toast.

ts
import { h } from 'vue';
import { BbBadge } from 'bitboss-ui';

toast({
    title: 'Upload finished',
    text: () => ['3 files ', h(BbBadge, { text: 'New' })],
});

When the body needs more than an icon, a title, text and buttons, register your own with <BbToastPortal> and fire a toast that names it.

Ingrid Halvorsen

Ingrid Halvorsen

Financial Analyst, Finance

The portal replaces the whole body, so icon, title, text and actions stop rendering and the portal owns its own buttons. The slot scope is { toast, data, close }, where data is the call's data. A component passed as portal gets the keys of data as its props, plus a close prop. Links, fields and labels in it take clicks as anywhere else: pressing one never starts a swipe. Reach for it rarely.

Where toasts appear

Six corners: top-left, top-center, top-right, bottom-left, bottom-center, bottom-right. For a page that may be read right to left, top-start, top-end, bottom-start and bottom-end name the corner by reading order.

Each message resolves its corner in two steps: its own position, then position in the plugin's BbToast entry (bottom-end out of the box: bottom right in a left-to-right page, bottom left in a right-to-left one).

ts
// nuxt.config.ts
export default defineNuxtConfig({
    bitboss: { components: { BbToast: { position: 'top-end' } } },
});

Messages in different corners form independent stacks. Pick one corner per product and stay there; a per-message position is for the rare control that lives somewhere else on the screen, like a copy button pinned to the top.

Everything else about the stack is automatic and worth not rebuilding: toasts pile up newest in front with only the front three visible, hovering or focusing the pile fans it out and pauses every timer, timers also pause while the browser tab is hidden and resume with the time remaining, and a toast can be swiped towards its nearest screen edge. Under 600px the stack goes full width.

The stacks are promoted into the browser's top layer (they stay in the DOM where the host sits), so they paint above dialogs, off-canvas panels and menus. When a modal opens, the region moves inside it: a modal makes everything outside itself inert, and a toast nobody can click is worse than no toast. When a non-modal panel claims a screen edge, the stack yields: a bottom sheet pushes bottom stacks up, a right panel pushes right stacks left, in step with the slide. Your own docked panels are ordinary page markup that the stack cannot see, so a details sidebar claims its edge the same way with one call: useSafeArea({ side: 'right', size: 352 }).

Coming from v2

placement became position, and the value vocabulary changed with it. bottom is bottom-center; v2's bottom-start and bottom-end keep their names but now follow the reading direction (bottom left and bottom right in a left-to-right page), and the same for top. The composable's return changed too: it is { toast, dismiss, update } now. dismissAll() is gone; dismiss() with no argument clears the stack, and nothing catches the old name for you, because it is not a template attribute either.

Variants and CSS hooks

Register the names your product needs: only registered names type-check.

ts
// nuxt.config.ts
export default defineNuxtConfig({
    bitboss: { components: { BbToast: { variants: ['upgrade'] } } },
});

The object form also sets each variant's icon for the whole app. A key registers its name (a built-in name only gets its icon):

ts
// nuxt.config.ts
export default defineNuxtConfig({
    bitboss: {
        components: {
            BbToast: {
                variants: {
                    success: { icon: 'lucide:circle-check' },
                    destructive: { icon: 'lucide:circle-x' },
                    upgrade: {}, // a project variant, no icon
                },
            },
        },
    },
});

A toast without its own icon uses its variant's, its own wins, and hideIcon: true hides either:

ts
toast({ variant: 'success', title: 'Saved' }); // the check
toast({ variant: 'success', title: 'Sent', icon: 'lucide:send' }); // its own
toast({ variant: 'success', title: 'Copied', hideIcon: true }); // none
css
.bb-toast__panel.bb-toast__panel--upgrade {
    --icon-color: var(--bb-primary);
}

A registered variant buys you the .bb-toast__panel--<variant> class hook and nothing else. The built-ins only set --icon-color too, from --bb-success, --bb-info, --bb-warn and --bb-danger, so retuning those theme tokens retints every toast. A project variant announces politely unless its entry in the object form says otherwise: variants: { outage: { icon: 'lucide:zap-off', priority: 'assertive' } }.

To restyle part of every toast, set pt in the plugin's BbToast entry; the host takes no pt of its own. The card is panel; inside it sit icon, content, title, text, footer (the row of actions), action (each button) and close, and loading is a state per toast. root is the region around one corner's stack.

bitboss-ui.components.ts
import type { BbComponentsMap } from 'bitboss-ui/nuxt';

export const components = {
    BbToast: {
        pt: {
            action: 'min-w-20',
            footer: 'justify-end',
            'icon:loading': 'text-(--bb-text-muted)',
            'panel:loading': 'opacity-80',
        },
    },
} satisfies BbComponentsMap;

The row inside each card (the icon, the text and the ×) reads two locals you set through panel: --gap (12px) and --align (flex-start, the icon on the title's line). panel: '[--gap:8px] [--align:center]' centres the icon on a one-line toast. The space between stacked toasts is --gap on root, which the cards never change.

A portal toast renders its own body, so it has no icon, title, text, footer or action. Each part also carries a class (.bb-toast__panel, .bb-toast__title, …); the region's is .bb-toast. Do not fight the stack with your own z-index, and do not mount extra hosts inside an overlay to get above it: the top layer already handles that.