Reference
IconButton
Icon-only button. label is its accessible name, never visible text.
IconButton(icon: String, label: String, size: Enum, …) { … }
Before 5.0
icon
label
size
tone
type
button
submit
reset
disabled
0 stars
Example
state stars = 0
Row(gap: .sm, align: .center) {
IconButton(icon: "star", label: "Star this project").primary { on click { stars = stars + 1 } }
IconButton(icon: "edit", label: "Edit")
IconButton(icon: "copy", label: "Copy link")
IconButton(icon: "trash", label: "Delete").danger
Text("{stars} stars").muted
}
Sizes
Row(gap: .sm, align: .center) {
IconButton(icon: "close", label: "Close").sm
IconButton(icon: "close", label: "Close")
IconButton(icon: "close", label: "Close").lg
}
Saying what it opens
state open = false
IconButton(icon: "menu", label: "Actions", aria-haspopup: "menu", aria-expanded: open) { on click { open = !open } }
Disabled
IconButton(icon: "download", label: "Download", disabled: true)
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
icon: | String | The icon it shows, one of the built-in icon names; a value that reads state follows it | |
label: | String | none | Its accessible name ( |
size: | one of its cases | md | Its square size. Written as a flag,
|
tone: | one of its cases | none: the text colour | The icon's colour; the button stays transparent. Written as a flag,
|
type: | one of its cases | button | What it does inside a form; any button not
|
disabled: | Bool | false | Whether it is inert: it cannot be pressed or focused. Written as a flag, |
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.
.sm
.md
.lg
.primary
.danger
.button
.submit
.reset
.disabled
Events
The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.
| Event | Sends | Meaning |
|---|---|---|
on click | DOM | The element was clicked or activated |
Every element also takes the props, the events and the attribute families listed on every element.
Slots
children
Renders with the class wf-icon-btn, stable across releases, so a stylesheet may target it.