Components
Loading Button
A button that spins while busy, then shows a tick.
<LoadingButton>
Save
</LoadingButton>Installation
npx shadcn@latest add https://ui.zjkm.tech/r/loading-button.jsonimport { LoadingButton } from "@/components/loading-button"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Pass the task's state. While loading, the button shows a spinner, is disabled and sets aria-busy. On success it draws a tick. The label stays in place, hidden, so the width never jumps. Click the demo to run a fake task.
import { LoadingButton } from "@/components/loading-button";
export function SaveButton({ save }: { save: () => Promise<void> }) {
const [state, setState] = useState<"idle" | "loading" | "success">("idle");
return (
<LoadingButton
state={state}
onClick={async () => {
setState("loading");
await save();
setState("success");
}}
>
Save
</LoadingButton>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | The label. | |
state | "idle" | "loading" | "success" | "idle" | What the task is doing. |
...props | button props | Every native <button> prop: onClick, disabled, type and so on. |
With reduced motion, the spinner turns slowly and the tick appears without drawing.