GitHub

Reference headless

toast

interface 4 type 6 function 1
interface Interfaces 4

# CreateToastOptions

Members

defaultDuration?
optional defaultDuration?: number

Default 5000ms.

###### Inherited from

CreateToastInput.defaultDuration

id?
optional id?: string
initial?
optional initial?: ToastItem[]

Initial toasts — useful for SSR hydration.

###### Inherited from

CreateToastInput.initial

max?
optional max?: number

Default 5; oldest dropped when full. Use Infinity to disable trim.

###### Inherited from

CreateToastInput.max

onAdd?
optional onAdd?: (toast) => void

###### Parameters

###### toast

ToastItem

###### Returns

void

onRemove?
optional onRemove?: (id) => void

###### Parameters

###### id

string

###### Returns

void

interface

# ToastContext

Members

defaultDuration
defaultDuration: number

Default duration applied to ADDs that omit it.

max
max: number

Hard limit; older toasts dropped from the front when exceeded.

toasts
toasts: readonly ToastItem[]

# ToastController

Members

closeButton
readonly closeButton: (toastId) => Attachment

###### Parameters

###### toastId

string

###### Returns

Attachment

context
readonly context: Readonly<ToastContext>
id
readonly id: string
item
readonly item: (toastId) => Attachment

###### Parameters

###### toastId

string

###### Returns

Attachment

machine
readonly machine: ToastMachine
state
readonly state: "idle"
toasts
readonly toasts: readonly ToastItem[]
viewport
readonly viewport: Attachment
viewportId
readonly viewportId: string

Stable id used as aria-describedby target by viewport.

add()
add(toast): string

Push a toast. If id is omitted, a fresh uid is generated. Returns the id used so the caller can later dismiss/update it.

###### Parameters

###### toast

Partial<ToastItem> & object

###### Returns

string

clear()
clear(): void

###### Returns

void

dismiss()
dismiss(id): void

###### Parameters

###### id

string

###### Returns

void

setMax()
setMax(value): void

###### Parameters

###### value

number

###### Returns

void

subscribe()
subscribe(listener): () => void

###### Parameters

###### listener

(snapshot) => void

###### Returns

() => void

update()
update(id, patch): void

###### Parameters

###### id

string

###### patch

Partial<Omit<ToastItem, "id">>

###### Returns

void

interface

# ToastItem

Members

description?
optional description?: string
duration?
optional duration?: number

Auto-dismiss delay in ms. -1 (or Infinity) = sticky. Default 5000.

id
id: string

Stable identifier — caller-supplied or generated by Layer 3.

meta?
optional meta?: Record<string, unknown>

Free-form metadata — passed back to the consumer's render.

politeness?
optional politeness?: ToastPoliteness
title
title: string
type?
optional type?: ToastType
type Type Aliases 6

# Attachment

Attachment = (node) => void | (() => void)

Parameters

node
HTMLElement

Returns

void | (() => void)
type

# ToastEvent

ToastEvent = { toast: ToastItem; type: "ADD"; } | { id: string; type: "REMOVE"; } | { id: string; patch: Partial<Omit<ToastItem, "id">>; type: "UPDATE"; } | { type: "CLEAR"; } | { type: "SET.MAX"; value: number; }
type

# ToastPoliteness

ToastPoliteness = "polite" | "assertive"

ARIA-live politeness; mapped to aria-live on the toast wrapper.

type

# ToastState

ToastState = "idle"
type

# ToastType

ToastType = "info" | "success" | "warning" | "error"
function Functions 1