Reference
Alert
Inline notice; a danger or warning one is announced as an alert.
Alert(_ message: String, tone: Enum) { … }
Before 5.0
message
tone
Example
Stack(gap: .sm) {
Alert("Your changes were saved.").success
Alert("Your trial ends in 3 days.").warning
Alert("The server is not answering. We will try again in a minute.").danger
Alert("A new version of the editor is available.").info
}
With actions in its block
Alert("Billing failed for the card ending 4242.").danger {
Button("Update card").sm
}
Shown while something holds
state failed = true
if failed {
Alert("Could not reach the build server.").danger {
Button("Dismiss").sm { on click { failed = false } }
}
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
message | String (positional) | — | The message; its block, when it has one, follows it |
tone: | one of its cases | none: the surface colour, announced politely | 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
children
Renders with the class wf-alert, stable across releases, so a stylesheet may target it.