Skip to content
Haze UI

Action swap

A real checkbox styled as one action that exchanges its label and icon when the state changes.

pnpm dlx shadcn@latest add @haze/action-swap
Open preview in a new tab
Livesmall script

When to use

  • A follow or subscribe action has two lasting states
  • A compact action needs to show the checked result in place

When not to use

  • For a single asynchronous save with pending and error states, use stateful-button
  • For several independent choices, use toggle-group

Installation

Add the Haze registry to components.json once, then install Action swap with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/action-swap
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique caller-supplied prefix for this component and its related elements.
namestringidForm submission name.
labelstring"Follow project"Visible label before selection.
activeLabelstring"Following"Visible label while selected.
checkedbooleanfalseInitial checkbox state.
disabledboolean–Disables the native control and its enhancement.
classstring–Additional classes for the component root.
...attributesnative control attributes–Other attributes are forwarded to the real form control.

Keyboard interactions

Tab, Space
Focus the checkbox and exchange its lasting state.

Accessibility

  • The visible label remains associated with the real checkbox as it changes.
  • The checked value submits through native forms, including with scripts disabled; haze:action-swap reports enhanced changes.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Action swap" with `npx shadcn@latest add @haze/action-swap`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ActionSwap from "@/components/haze/ui/action-swap.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/action-swap.md

  • Customize with real content

    Adapt the Haze action-swap ui for our product. Replace the demo values of these props with our real content: id, name, label, activeLabel, checked, disabled, class, ...attributes. Keep the layout, the heading level rules and these accessibility details: The visible label remains associated with the real checkbox as it changes. The checked value submits through native forms, including with scripts disabled; haze:action-swap reports enhanced changes. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using action-swap, check it fits: use it when a follow or subscribe action has two lasting states; a compact action needs to show the checked result in place. Avoid it when for a single asynchronous save with pending and error states, use stateful-button; for several independent choices, use toggle-group. Alternatives: @haze/toggle, @haze/stateful-button, @haze/toggle-group.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog