Toast

stable 3.4 kB
<hk-toast-host>

Pushed from a service, rendered by one host you drop in once. The stack caps itself, pauses its timers while hovered or focused, and never traps a screen reader mid-announcement. Four tones, including an orange `warn` that sits between info and danger — for the case where something needs attention but nothing has failed yet, which a two-tone set has to misreport as one or the other.

#notification#snackbar
In the package npm i hellskitchen-ui Import hk-toast-host and use it directly.

Live demo

Running in this page — interact with it.

Inputs

NameTypeDefaultDescription
position'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center' | 'inline''bottom-right'Host corner, or `inline` to stay in the normal flow.
maxnumber3Stack cap — oldest drops out first.
tone'success' | 'info' | 'warn' | 'danger''info'Per-toast. `warn` is orange and sits between info and danger: something needs attention, but nothing has failed yet.
durationnumber4200Milliseconds before auto-dismiss. 0 keeps it until dismissed.

Methods

  • push(toast)(toast: HkToast) => string

    Queues a toast and returns its id.

  • dismiss(id)(id: string) => void

    Removes one toast early.

  • clear()() => void

    Empties the stack.

Theming

Component tokens, each falling back to a global one:

PropertyDefaultControls
--hk-toast-gap10pxSpace between stacked toasts.
--hk-toast-width360pxToast width on wide screens.

Accessibility

  • Host is an aria-live region: polite for info, assertive for errors.
  • Timers pause on hover and on keyboard focus so a toast cannot vanish mid-read.

More in Feedback