# KptToast (kpt-toast-container + KptToastService)
Notifications (toasts) driven by a service. The container renders them fixed in a corner.
Import: `import { KptToastService, KptToastContainer } from '@konce-pt/angular';`
## Setup
Place the container once in the application: ``.
## The service (KptToastService, providedIn: root)
private toast = inject(KptToastService);
toast.success('Saved', { title: 'OK' });
toast.error('Connection failed');
toast.info(msg, opts); toast.warning(msg, opts);
toast.show(msg, { variant, title, duration }); // duration in ms, 0 = no auto-dismiss
toast.dismiss(id); toast.clear();
toast.success('Deleted', { duration: 8000, action: { label: 'Undo', run: () => restore() } });
toast.pause(); toast.resume();
## KptToast
`{ id, message, title?, variant: 'info'|'success'|'warning'|'danger', duration, action?: { label, run }, position?, appearance, closable, progress }`
## Position
`` - the corner for toasts without their own `position`:
`top-start`, `top-center`, `top-end`, `bottom-start`, `bottom-center`, `bottom-end` (default).
`start`/`end` are logical (they swap in RTL). Each corner is its own stack (`data-position`); the
newest toast is always next to the edge (bottom of a bottom stack, top of a top one) and slides in
from it. Distance from the edge: `--kpt-toast-offset` (default `--kpt-space-4`) plus the safe area;
below 40rem a stack takes the full width. One toast can go elsewhere: `{ position: 'bottom-center' }`.
## Appearance
`appearance: 'outline'` (default) - a raised surface with the accent on the start edge;
`'filled'` - the whole toast in the variant colour, content in `--kpt-color--contrast` (white
on every variant in the light theme, dark in the dark theme).
Icon, text, action and close button are centred on one axis.
## Closing and the time bar
`closable: false` hides the close button. A toast without the close button, without an action and
with `duration: 0` could never be closed, so it gets `KPT_TOAST_FALLBACK_DURATION` (5000 ms).
`progress: true` draws a time bar at the bottom that shrinks over `duration` and stops while the
timers are paused (`service.paused()` -> `data-paused` on the stack). It ignores the motion switch -
it shows time, it is not decoration.
## App-wide defaults
bootstrapApplication(App, { providers: [provideKptToast({ appearance: 'filled', progress: true, duration: 5000 })] });
`KptToastConfig`: `duration`, `appearance`, `closable`, `progress`. Order: toast option >
`provideKptToast` > library default. `resolveKptToast(id, message, options, config)` is the same
resolution as a pure function.
## Actions and pausing
`action: { label, run }` adds one button to the toast (typically "Undo"); a click calls `run` and
dismisses the toast. Give such toasts a longer `duration`, and keep the action available elsewhere.
`pause()` / `resume()` stop and continue every timer; the container calls them on hover and focus,
and resumes by itself when the stack empties.
## Tokens
`--kpt-color-surface-raised`, `--kpt-elevation-3`, the accent `--kpt-color-{info,success,warning,danger}`,
content of `filled` `--kpt-color-{info,success,warning,danger}-contrast`, edge distance `--kpt-toast-offset`,
stacking `--kpt-z-toast`.
## Accessibility
Announcements go through two permanent, visually hidden live regions next to the stack -
`aria-live="polite"` for ordinary toasts and `aria-live="assertive"` for `danger` - and not through
the toasts themselves: a live region has to exist before content appears in it, and nested regions
are read twice by some screen readers. Each region is cleared before it is written, so the same
text twice is announced twice, and a dismissed toast never re-announces an older one. While there
are toasts the stack is `role="region"` named `toast.region` ("Notifications"). Pointer or focus on
the stack pauses every timer (WCAG 2.2.1); the timers resume with the time that was left. The close
button is labelled from `common.close`.
## Toasts with an action
A toast with `action` does not close by itself (`duration` defaults to 0): a keyboard or screen-reader user cannot reach the "Undo" button at the end of the page within four seconds (WCAG 2.2.1). An explicit `duration` still wins.