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
Export results
Papers matching “retrieval”, six columns
CSV, 22 KB
idle
pending
SavingSendingDeletingsuccess
SavedSentDeletedfailure
Not savedNot sentNot deletedUsage
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-resultinstead. - The control is on or off. Use Pill or Toggle instead.
- The whole dialog waits. Use Dialog with
DialogContent statusinstead 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.jsonimport { StateButton } from "@/components/cobalt/ui/state-button"