Components
A polymorphic button built on Base UI's useRender. Ships 8 visual variants (default, secondary, outline, ghost, link, destructive, destructive-outline) and a full set of sizes including icon sizes (xs–xl). Has a built-in loading state that overlays an inline spinner and hides the label, a render prop for rendering as any element or as a child, and focus-visible / pressed styling out of the box.
npx @21st-dev/cli add cnippet.dev/cnippet-buttonLoading preview...
"use client";
import { CheckIcon, CloudUploadIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/cnippet-button";
type State = "idle" | "loading" | "success";
export default function ButtonLoading() {
const [state, setState] = useState<State>("idle");
const handleClick = () => {
if (state !== "idle") return;
setState("loading");
setTimeout(() => {
setState("success");
setTimeout(() => setState("idle"), 2000);
}, 1800);
};
return (
<Button
disabled={state === "loading"}
loading={state === "loading"}
onClick={handleClick}
variant={state === "success" ? "outline" : "default"}
>
{state === "success" ? (
<>
<CheckIcon className="size-4 text-emerald-500" />
Saved
</>
) : (
<>
<CloudUploadIcon className="size-4" />
{state === "loading" ? "Saving…" : "Save Changes"}
</>
)}
</Button>
);
}
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...