Reference
Chip
A compact label — a filter, a tag, a person — that can carry an icon, be pressed (selected:, with on click), and be removed (.removable, with on remove). Tag is the one that does none of it.
Chip(_ label: String, icon: String, selected: Bool, removable: Bool)
Since 6.2.0
icon
selected
removable
4 languages, open only: false
Example
state langs = ["Rust", "TypeScript", "Go", "Python"]
state openOnly = false
Stack(gap: .sm, align: .start) {
Row(gap: .xs) {
for l in langs by l {
Chip(l, icon: "code").removable { on remove { langs = langs.filter(x => x != l) } }
}
}
Chip("Open issues only", selected: openOnly) { on click { openOnly = !openOnly } }
Text("{langs.length} languages, open only: {openOnly}").muted
}
A filter row of toggles
state picked: [String] = ["web"]
Row(gap: .xs) {
for f in ["web", "api", "worker"] by f {
Chip(f, selected: picked.includes(f)) {
on click { picked = if picked.includes(f) { picked.filter(x => x != f) } else { picked.concat([f]) } }
}
}
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | — | Its words |
icon: | String | none | An icon's name, drawn before the words |
selected: | Bool | none: not a button unless it has | Pressed ( |
removable: | Bool | false | A button after the words, named |
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.
.selected
.removable
Events
| Event | Sends | Meaning |
|---|---|---|
on remove | — |
Every element also takes the props, the events and the attribute families listed on every element.
Slots
It takes no slots.
Parts
The parts of Chip are written under its name, inside it. Each is described here, with what it takes.
Chip.Action
What pressing a chip presses: its icon and words, a toggle button when it can be selected:.
Chip.Action(_ text: String) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
text | String (positional) | none | Its words |
Chip.Label
Its icon and words, when pressing it does nothing.
Chip.Label(_ text: String) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
text | String (positional) | none | Its words |
Chip.Remove
Its remove button.
Chip.Remove { … }
Renders with the class wf-chip, stable across releases, so a stylesheet may target it.