Reference
Code
Inline code, or a code block with block; language: colours it.
Code(_ content: String or Number or Bool, block: Bool, language: String)
Before 5.0
Start the dev server with
wf serve
, then open the page.
page Home(path: "/", title: "Home") {
state count = 0
Button("+1") { on click { count = count + 1 } }
}
Example
Stack(gap: .sm) {
Text { Text("Start the dev server with ") Code("wf serve") Text(", then open the page.") }
Code("""
page Home(path: "/", title: "Home") {
state count = 0
Button("+1") { on click { count = count + 1 } }
}
""", language: "wf").block
}
A shell command on its own
Code("wf build --stats", language: "bash").block
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
content | String or Number or Bool (positional) | none | The code, as text in a monospace font |
block: | Bool | false | A block of several lines that keeps its line breaks and scrolls sideways, on the terminal colours, rather than a span in a line. Written as a flag, |
language: | String | none: plain | Colours the code as this language: |
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.
.block
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-code, stable across releases, so a stylesheet may target it.