StatefulButton
Submit button that morphs through saving, saved and failed. It resizes on a transform and swaps its label with a blur. Buttons.
Open playgroundAbout
StatefulButton is a React component in the Buttons category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { StatefulButton } from "@ashutoshswamy/smoui" and set children, onClick, loadingLabel among its 6 props.
Install
npm i @ashutoshswamy/smouiUsage
import { StatefulButton } from "@ashutoshswamy/smoui";
<StatefulButton
className="rounded-full bg-black px-6 py-3 text-white"
onClick={() => api.save()} // resolve: success, reject: error
>
Save changes
</StatefulButton>Props 6
- children
Idle label.
ReactNode- onClick
Return a promise. Resolves to success, rejects to error.
() => void | Promise<unknown>- loadingLabel
Label while the promise is pending.
ReactNodedefault"Saving"- successLabel
Label after it resolves.
ReactNodedefault"Saved"- errorLabel
Label after it rejects.
ReactNodedefault"Failed"- resetMs
Time before it returns to idle.
numberdefault1800
More buttons components
- AddButtonAdd + that opens into a stepper in place. The plus never moves, so a second tap lands where the first did. At one the minus becomes a bin; hold to repeat.
- AddToBagOne pill that is the add button until pressed, then grows a stepper in place. Step back to zero and it folds up again.
- ArrowButtonOn hover the arrow exits right as a second one enters from the left, and the chip swells.
- CopyButtonCopies text, then swaps its label for a drawn checkmark.
- CopyCommandA command line with a Copy button. The icon turns to a check, the word rolls to Copied and the button grows to fit.
- FillButtonThe fill floods in from the edge your pointer entered and drains out through the edge it left by.