Reference

Alert

Inline notice; a danger or warning one is announced as an alert.

Alert(_ message: String, tone: Enum) { … }

Before 5.0

message

tone

Your changes were saved.
A new version of the editor is available.

Example

wf

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

wf

Alert("Billing failed for the card ending 4242.").danger { Button("Update card").sm }

Shown while something holds

wf

state failed = true if failed { Alert("Could not reach the build server.").danger { Button("Dismiss").sm { on click { failed = false } } } }

Props

Props of Alert
PropTypeUnsetMeaning

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; .danger and .warning are announced at once (role="alert"), the rest politely (role="status"). Written as a flag, .success, or by name, tone: .success.

  • .success: Green: done, healthy
  • .danger: Red: destructive, failed
  • .warning: Amber: attention
  • .info: Blue: neutral notice

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.