Reference

Button

A button: its label or block is what it shows, on click what it does.

Button(_ label: String, tone: Enum, size: Enum, shape: Enum, …) { … }

Before 5.0

label

tone

size

shape

width

Saved 0 times

Example

wf

state saved = 0 Row(gap: .sm, justify: .end) { Button("Cancel").outlined Button("Save draft") { on click { saved = saved + 1 } } Button("Publish").primary { on click { toast("Published", tone: .success) } } } Text("Saved {saved} times").muted

Tones

wf

Row(gap: .sm) { Button("Primary").primary Button("Secondary").secondary Button("Success").success Button("Danger").danger Button("Warning").warning Button("Info").info }

Sizes, shapes and widths

wf

Stack(gap: .sm) { Row(gap: .sm, align: .center) { Button("Small").sm Button("Default") Button("Large").lg } Row(gap: .sm) { Button("Rounded").rounded Button("Pill").pill.primary Button("Outlined").outlined.danger } Button("Continue to checkout").primary.full }

Busy and disabled

wf

state agreed = false Checkbox(bind: agreed, label: "I agree to the terms") Row(gap: .sm) { Button("Create account", disabled: !agreed).primary Button("Saving", loading: true) }

A link and a submit

wf

state email = "" Form { on submit { toast("Subscribed") } Input(bind: email, label: "Email").email Row(gap: .sm) { Button("Subscribe", type: .submit).primary Button("Read the guide", to: "/learn").outlined } }

Props

Props of Button
PropTypeUnsetMeaning

label

String (positional)

none

Its words; a block may hold more (an icon, Text) after them

tone:

one of its cases

none: the surface colour with a border

The colour it is filled with, from the theme's tones. Written as a flag, .primary, or by name, tone: .primary.

  • .primary: The brand colour: the page's main action
  • .secondary: The secondary colour
  • .success: Green: done, healthy
  • .danger: Red: destructive, cannot be undone
  • .warning: Amber: attention
  • .info: Blue: neutral notice

size:

one of its cases

md

Its padding and text size. Written as a flag, .sm, or by name, size: .sm.

  • .sm: Less padding, smaller text
  • .md (the default): The default size
  • .lg: More padding, larger text

shape:

one of its cases

none: radius-md corners

Its corners; unset, the theme's radius-md. Written as a flag, .rounded, or by name, shape: .rounded.

  • .rounded: Rounder corners (radius-lg)
  • .pill: Fully rounded ends (radius-full)

width:

one of its cases

none: as wide as its words

How wide it is. Written as a flag, .full, or by name, width: .full.

  • .full: The full width of its container

outlined:

Bool

false

A border and no fill; with .primary or .danger its words and border take that colour. Written as a flag, .outlined, or outlined: true.

type:

one of its cases

button

What it does inside a form; any button not .submit or .reset never submits one. Written as a flag, .button, or by name, type: .button.

  • .button (the default): A plain button
  • .submit: Submits the enclosing form
  • .reset: Resets the enclosing form

to:

Path

none

A route to go to when it is pressed, through the router as a Link's to:; it stays a <button>

disabled:

Bool

false

Whether it is inert: it cannot be pressed or focused. Written as a flag, .disabled, or disabled: true.

loading:

Bool

false

Busy while it holds — loading: Checkout.pay.pending: a spinner in place of its label, at the same width, and a press does nothing. Written as a flag, .loading, or loading: true.

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.

.primary

.secondary

.success

.danger

.warning

.info

.sm

.md

.lg

.rounded

.pill

.full

.outlined

.button

.submit

.reset

.disabled

.loading

Events

The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.

DOM events Button answers
EventSendsMeaning
on clickDOMThe 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-btn, stable across releases, so a stylesheet may target it.