Skip to content
HomeCobalt

State button

Reports a slow action inside the button that started it: after 250ms the label gives way to a spinner and the pending word, then to a check and the success word or a cross and the failure word on a red wash, while the box, the accessible name and keyboard focus stay where they were.

Examples

An export reports itself inside its button, and a press after a failure retries.
Export results
Papers matching “retrieval”, six columns

CSV, 22 KB

Every statusOne label sets the box for every status and variant, so a row never changes width.

idle

pending

SavingSendingDeleting

success

SavedSentDeleted

failure

Not savedNot sentNot deleted
A form's submitEnter in the field submits through the button, and while the rename is on its way a second Enter or press does nothing.

UnconfirmedA payment run whose answer was lost: the button says Check instead of sending again, and Check asks the server whether it went through. Turn on Lose the next answer first.
The server has received the run 0 times.

Usage

Use it when

  • A press starts a request that can take longer than the press: export, save, send, publish, delete.
  • The result belongs where you are looking, on the button, and a toast across the screen would be too far away.

Use something else when

  • The action stays on the page and answers at once, such as copying or showing a key. Use Button with an IconSwap instead; a spinner that shows for under 400ms reads as a flicker.
  • The result lands somewhere else, such as a new row in a list you are not looking at. Use Button and a toast through rule/writing-toast-result instead.
  • The control is on or off. Use Pill or Toggle instead.
  • The whole dialog waits. Use Dialog with DialogContent status instead of dimming the button alone, with a StateButton for the action, as the Dialog's own example does.

Rules

General

Content

Avoid

Limits

Install

npx shadcn@latest add https://kaanarici.com/r/cobalt/state-button.json
import { StateButton } from "@/components/cobalt/ui/state-button"