Buttons in every tone and emphasis, and a toggle that stays pressed.
Installation
Usage
import { Button, Toggle } from "./ui/uicontext/components/Button.ts"const Message = UiSchema.TaggedEnum({ ClickedSave: {}, ClickedPin: {} })// `pinned` lives in your Model; ClickedPin flips itexport const Actions = (h: Html.H<typeof Message.Type>, pinned: boolean) => [ Button(h, { tone: "primary" }).on("click", Message.ClickedSave()).children("Save changes"), Toggle(h, { pressed: pinned }).on("click", Message.ClickedPin()).children("Pin"),]Examples
API reference
ButtonView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | "lg" | md | Height, padding and text size; md by default. |
tone | "neutral" | "accent" | "danger" | "warning" | "success" | "info" | "primary" | neutral | What it means, or primary for the main action, in the accent color unless the app sets inkPrimary; neutral by default. |
emphasis | "solid" | "soft" | "outline" | "ghost" | — | How loud it is: filled, tinted, outlined or bare. A neutral button is outlined and any other tone is solid by default. |
iconOnly | boolean | — | A square button with only an icon; give it an aria-label. |
type | "button" | "submit" | "reset" | button | What pressing it does in a form: submit sends the form and reset clears it; button by default. |
style | Style | — | StyleX styles applied after the button's own. |
ToggleView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | "lg" | md | Height, padding and text size; md by default. |
tone | "neutral" | "accent" | "danger" | "warning" | "success" | "info" | "primary" | neutral | What it means, or primary for the main action, in the accent color unless the app sets inkPrimary; neutral by default. |
emphasis | "solid" | "soft" | "outline" | "ghost" | — | How loud it is: filled, tinted, outlined or bare. A neutral button is outlined and any other tone is solid by default. |
iconOnly | boolean | — | A square button with only an icon; give it an aria-label. |
type | "button" | "submit" | "reset" | button | What pressing it does in a form: submit sends the form and reset clears it; button by default. |
style | Style | — | StyleX styles applied after the button's own. |
pressedrequired | boolean | — | Whether it's on. The caller keeps it and flips it on click. |
Accessibility
- Renders a native
<button>(typebuttonunless you set it), so Enter and Space press it and it shows a focus ring on keyboard focus. Togglesetsaria-pressed, so screen readers say whether it's on. An icon-only button needs anaria-label.