Reference
Toast
Temporary notification.
Toast(_ message: String, tone: Enum)
Before 5.0
tone
success
danger
warning
info
0 archived
Example
state archived = 0
Row(gap: .sm) {
Button("Archive conversation") {
on click {
archived = archived + 1
toast("Conversation archived", action: "Undo", onAction: () => toast("Restored"))
}
}
Button("Save draft").primary { on click { toast("Draft saved", tone: .success) } }
}
Text("{archived} archived").muted
The element, while a state holds
state saved = false
Button("Save") { on click { saved = true } }
if saved { Toast("Saved").success }
Following a promise
Button("Copy the invite link") {
on click { toast.promise(navigator.clipboard.writeText("https://ledger.example.com/invite/42"), loading: "Copying…", done: "Link copied", failed: "Could not copy") }
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
message | String (positional) | — | The message, shown above everything for 3 s once the element is drawn, and said to a screen reader; the element itself draws nothing in place |
tone: | one of its cases | info | The kind of notice, which sets its colours;
|
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
.success
.danger
.warning
.info
Events
Every element also takes the props, the events and the attribute families listed on every element.
Slots
It takes no slots.
Renders with the class wf-toast, stable across releases, so a stylesheet may target it.
Codes this can raise
These controls list the props' cases; the example below shows them written.