Toggle

Buttons in every tone and emphasis, and a toggle that stays pressed.

solid
soft
outline
ghost

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/button-family

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

Toggle

A button that stays pressed: pressed comes from your Model and a click asks to flip it.

API reference

ButtonView function

Options

Button options
NameTypeDefaultDescription
size"sm" | "md" | "lg"mdHeight, padding and text size; md by default.
tone"neutral" | "accent" | "danger" | "warning" | "success" | "info" | "primary"neutralWhat 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.
iconOnlyboolean—A square button with only an icon; give it an aria-label.
type"button" | "submit" | "reset"buttonWhat pressing it does in a form: submit sends the form and reset clears it; button by default.
styleStyle—StyleX styles applied after the button's own.

ToggleView function

Options

Toggle options
NameTypeDefaultDescription
size"sm" | "md" | "lg"mdHeight, padding and text size; md by default.
tone"neutral" | "accent" | "danger" | "warning" | "success" | "info" | "primary"neutralWhat 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.
iconOnlyboolean—A square button with only an icon; give it an aria-label.
type"button" | "submit" | "reset"buttonWhat pressing it does in a form: submit sends the form and reset clears it; button by default.
styleStyle—StyleX styles applied after the button's own.
pressedrequiredboolean—Whether it's on. The caller keeps it and flips it on click.

Accessibility

  • Renders a native <button> (type button unless you set it), so Enter and Space press it and it shows a focus ring on keyboard focus.
  • Toggle sets aria-pressed, so screen readers say whether it's on. An icon-only button needs an aria-label.

Source