Skip to main content
v7

ActionSwap

A pill button that cycles through related states, like Pin and Pinned, with width, tone, icon and label morphing together.

Package@g4rcez/componentsSectionDisplay Components

Examples

Pin a language

Each press moves to the next state and wraps around. Only the characters that change roll in; width, tone and icon move together.

Two states

Async action with a confirmation

Return a promise from onAction to show a working phase, at least 450ms so it never flashes. The next state shows when it resolves. A rejection shows failureLabel for 1.8 seconds and pressing again retries. holdFor sends the button back on its own.

Compile, compiled, and a failure

The first press fails and the second succeeds, so you can see both paths.

Controlled with three states

Pass value and onValueChange to own the state. The list can have any length; the state is identified by its id.

Type checking

Current value: dynamic

When to use ActionSwap

Use when

Use ActionSwap for a single control that cycles through a short list of related states: pin and unpin, compile and compiled, dynamic, gradual and static typing.

Avoid when

Avoid it for a one-off save, where a Button with a loading state is enough, and for choosing between many options, where a Select or Tabs fit better.

Accessibility

It is a native button. Its accessible name is the visible label (the state's label while it is working), Enter and Space advance the state, and a polite live region announces each new label and any failure. While an action is pending it sets aria-busy and aria-disabled.