GUILD OF GLEKS UIv21.4.4

gog-toast

Toast

Fire-and-forget notifications via ToastService, rendered by a positioned gog-toast-container — with per-corner stacking, action buttons, sticky and timed variants, and automatic deduping of repeated calls.

Overview

Import ToastContainerComponent and mount <gog-toast-container /> once — typically near the root of your app. Every ToastService call renders through that single outlet, so it only needs to exist once no matter how many places call it.

typescript
import { ToastContainerComponent, ToastService } from '@guildofgleks/ui';

@Component({
  // ...
  imports: [ToastContainerComponent],
})
export class AppComponent {
  // Mount <gog-toast-container /> once, near the root of your app.
}

Basic usage — inject the service, call a shorthand method:

<gog-button (gogClick)="showToast()">Preview toast</gog-button>
<gog-toast-container />

Examples

Fully configurable

Every field below feeds a single show() call — message, type, and position are all consumer-controlled.

<gog-inputfield label="Message" [(value)]="toastMessage" />
<gog-select label="Type" [options]="toastTypes" [(value)]="toastType" />
<gog-select label="Position" [options]="positions" [(value)]="toastPosition" />
<gog-button (gogClick)="showConfigured()">Preview toast</gog-button>

Types

Each type gets a default icon (success/error/warning/info) unless iconName or iconTemplate overrides it.

this.toastService.success('Success — saved successfully.');
this.toastService.error('Error — something went wrong.');
this.toastService.warning('Warning — check this before continuing.');
this.toastService.info('Info — just so you know.');

Action buttons

actions renders buttons inside the toast — each gets the full Toast object in its onClick, so it can read back the message, type, or id it belongs to.

this.toastService.show({
  message: 'File deleted',
  type: 'info',
  actions: [
    { label: 'Undo', iconName: 'close', onClick: () => this.restoreFile() },
  ],
});

Sticky & duration

isSticky disables auto-dismiss entirely; duration overrides the 4s default.

this.toastService.show({
  message: 'Stays until dismissed or dismissAll() is called.',
  type: 'warning',
  isSticky: true,
});

this.toastService.show({
  message: 'Auto-dismisses after 10s instead of the 4s default.',
  type: 'info',
  duration: 10000,
});

Queueing & stacking

Only the front toast in a corner counts down — the rest wait behind it with a frozen progress bar, so a burst of notifications never all expire at once. maxVisiblePerPosition on the container caps how many stack visibly at a time.

for (let index = 1; index <= 7; index += 1) {
  this.toastService.info(`Queued toast ${index}`, { position: 'top-right' });
}

App-wide defaults

The corner toasts appear in and how long they stay up were constants until 21.3.0; both are now settable once, app-wide. An individual show() call still overrides them. See Global Configuration for the full set of keys.

typescript
import { provideGogConfig } from '@guildofgleks/ui';

bootstrapApplication(App, {
  providers: [
    provideGogConfig({
      toast: {
        position: 'top-right',
        duration: 6000,
      },
    }),
  ],
});

How a toast is announced 21.3.2

Announcements come from two permanently-mounted live regions on gog-toast-container — one polite, one assertive — and the toast's type decides which one its text is written into (assertive for error and warning, polite otherwise).

Individual toasts therefore carry no role or aria-live of their own. A live region has to exist before the text lands in it to be announced at all; one created together with the toast is a region the screen reader has not been watching. This only matters to you if you were styling or querying those attributes on a toast element.

API Reference

ToastConfig

Passed to ToastService.show(config).

NameTypeDefaultDescription
messagestringrequiredThe toast text.
type'success' | 'error' | 'warning' | 'info''info'Drives the accent color, the default icon, and which live region announces the toast (assertive for error/warning, polite otherwise).
iconNameGogIconNameper-type defaultOverrides the type-based default icon.
iconTemplateTemplateRef<unknown> | nullnullFully custom icon, taking priority over iconName.
actionsToastAction[][]Action buttons rendered in the toast: { label, onClick(toast), iconName?, iconTemplate? }.
isStickybooleanfalseDisables auto-dismiss entirely — the toast stays until dismissed manually or via dismissAll().
durationnumberGOG_CONFIG.toast.duration ?? 4000Auto-dismiss delay in ms. Ignored when isSticky is true.
position'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'GOG_CONFIG.toast.position ?? 'bottom-right'Which corner stack this toast joins. Each corner stacks and animates independently.
dedupeKeystringderived from message/type/icon/iconTemplate/position/actionsToasts sharing a dedupe key collapse into one instance instead of stacking duplicates — calling show() again just bumps its revision and restarts the timer. Pass '' to opt a specific call out of deduping.

ToastService methods

SignatureDescription
show(config: ToastConfig): stringShows a toast with full control over every option. Returns its id.
success(message, config?) / error(...) / warning(...) / info(...)Shorthands for show() that set type for you; config overrides everything else.
dismiss(id: string): voidDismisses a single toast by id.
dismissAll(): voidDismisses every visible toast, including sticky ones.

gog-toast-container — Inputs

NameTypeDefaultDescription
maxVisiblePerPositionnumber5Caps how many toasts stack at once per corner; the oldest (front of queue) stay visible first.

Styling Tokens

Every CSS custom property the toast paints with. Override any of them — on a single instance, a subtree, or a theme — to restyle it. See the Theming guide for the full token-layering model, or the Theme Generator to tweak these live.

TokenDescription
--gog-toast-bg / -color / -borderCard surface.
--gog-toast-success-color / -error-color / -warning-color / -info-colorAccent stripe and icon color, per toast type.
--gog-toast-padding / -radiusCard padding and corner radius.
--gog-toast-stack-peek / -stack-scale-step / -stack-expanded-gapCard-stack geometry when several toasts are visible at once.