Stateful Badge
An animated badge component that transitions smoothly between different states.
Installation
npx shadcn@latest add https://raw.githubusercontent.com/FifthWit/ui/refs/heads/main/public/r/stateful-badge.jsonUsage
import { useRef } from "react";
import {
StatefulBadge,
type StatefulBadgeHandle,
} from "@/components/stateful-badge";
export function Example() {
const badgeRef = useRef<StatefulBadgeHandle>(null);
const handleClick = () => {
badgeRef.current?.updateState("loading");
// fake async func
setTimeout(() => {
badgeRef.current?.updateState("success");
}, 2000);
};
return (
<div>
<StatefulBadge initialState="idle" ref={badgeRef} />
<button onClick={handleClick}>Start</button>
</div>
);
}API Reference
StatefulBadge
Prop
Type
StatefulBadgeHandle
The ref exposes the following method:
Prop
Type
State Types
The badge's supported states are: idle, loading, success, warning, and error