Button

A button and a matching link in default, outline, ghost and destructive styles.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/button

Usage

import { Button } from "./ui/uicontext/button.ts"
const Message = UiSchema.TaggedEnum({ ClickedSave: {} })export const SaveButton = (h: Html.H<typeof Message.Type>) =>	Button(h, { variant: "outline" })		.on("click", Message.ClickedSave())		.children("Save changes")

Examples

Sizes

Small for dense toolbars, the default for forms, and a square icon button.

With an icon

An icon before the label. It's decorative, so the label names the button.

Loading

While the request runs the button is disabled, says what it's doing and marks itself busy.

ButtonLink renders a real link with the button's look, for going somewhere instead of doing something.

API reference

Options

Button options
NameTypeDefaultDescription
variant"default" | "outline" | "ghost" | "destructive"defaultHow much the button stands out: default for the main action, outline and ghost for quieter ones, destructive for one that deletes; default by default.
size"default" | "sm" | "icon" | "icon-sm" | "icon-xs"defaultHeight and padding. The icon sizes are square, for a button that holds only an icon; default by default.
styleStyleXStyles—StyleX styles applied after the button's own.
type"button" | "submit" | "reset"buttonWhat pressing it does in a form: submit sends the form, reset clears it; button by default, which does nothing on its own.

Accessibility

  • Renders a native <button>, so Enter and Space press it and it joins the tab order. ButtonLink renders a real <a> with the same look.
  • An icon-only button needs an aria-label.

Source