Credit Badge
Balance status pill for credits, wallet states, and billing health. Install Credit Badge from the VLLNT UI registry with the shadcn CLI.
Balance status pill for credits, wallet states, and billing health. Part of the content family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.
Preview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
Add Credit Badge to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:
pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/credit-badge.jsonSource
import * as React from "react";
import { cn } from "../../lib/utils";
import { badgeVariants } from "../badge/badge";
export type CreditBadgeStatus = "depleted" | "healthy" | "low" | "overdue";
export type CreditBadgeProps = Omit<
React.ComponentPropsWithoutRef<"span">,
"children"
> & {
amount?: string;
label?: string;
status: CreditBadgeStatus;
};
function getStatusLabel(status: CreditBadgeStatus): string {
switch (status) {
case "depleted":
return "No credits left";
case "healthy":
return "Credits available";
case "low":
return "Credits running low";
case "overdue":
return "Balance overdue";
}
}
function getStatusClasses(status: CreditBadgeStatus): string {
switch (status) {
case "depleted":
return "border-slate-500/30 bg-slate-500/10 text-slate-700 dark:text-slate-300";
case "healthy":
return "border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300";
case "low":
return "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300";
case "overdue":
return "border-destructive/30 bg-destructive/10 text-destructive";
}
}
export const CreditBadge = ({
amount,
className,
label,
ref: reference,
status,
...props
}: CreditBadgeProps & { ref?: React.Ref<HTMLSpanElement> }) => {
return (
<span
className={cn(
badgeVariants({ variant: "outline" }),
"gap-1.5 rounded-full px-2.5 py-1 text-[11px] font-medium shadow-none",
getStatusClasses(status),
className,
)}
ref={reference}
{...props}
>
<span aria-hidden="true" className="size-1.5 rounded-full bg-current" />
<span>
{amount
? `${amount} • ${label ?? getStatusLabel(status)}`
: (label ?? getStatusLabel(status))}
</span>
</span>
);
};
CreditBadge.displayName = "CreditBadge";
Stories
Explore every variant and state in the interactive Storybook:
Preview
Switch between light and dark to inspect the embedded Storybook preview.