Badge
Server-safeA compact status or category label.
Live preview
Rendered from the installed VEXA source — the same files you receive.
NeutralOutlinePrimaryActivePendingFailed
Installation
Adds the component source to your project. Registry dependencies are pulled in automatically.
npx shadcn@latest add https://vexa.valfiguer.com/r/badge.jsonInstalls to components/vexa/badge.tsx
npm dependencies
- class-variance-authority
Registry dependencies
- @vexa/utils
Other VEXA items this component needs. Install them first — they are resolved automatically by the CLI.
Source
Copy this into its target path, or install it with the command above.
components/vexa/badge.tsx
import type * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
export const badgeVariants = cva(
[
"inline-flex items-center gap-1 whitespace-nowrap",
"rounded-vexa-sm border px-2 py-0.5 text-xs font-medium",
"[&_svg]:size-3 [&_svg]:shrink-0",
],
{
variants: {
variant: {
neutral:
"border-transparent bg-vexa-secondary text-vexa-secondary-foreground",
outline: "border-vexa-border bg-transparent text-vexa-foreground",
primary:
"border-transparent bg-vexa-primary text-vexa-primary-foreground",
success:
"border-transparent bg-vexa-success text-vexa-success-foreground",
warning:
"border-transparent bg-vexa-warning text-vexa-warning-foreground",
danger: "border-transparent bg-vexa-danger text-vexa-danger-foreground",
},
},
defaultVariants: {
variant: "neutral",
},
},
);
export interface BadgeProps
extends React.ComponentProps<"span">, VariantProps<typeof badgeVariants> {}
/**
* Badge — a compact status or category label.
*
* RSC-safe. Meaning must not rely on color alone: always include text (and,
* optionally, an icon) so status is conveyed non-visually as well.
*/
export function Badge({ className, variant, ...props }: BadgeProps) {
return (
<span
data-slot="badge"
className={cn(badgeVariants({ variant }), className)}
{...props}
/>
);
}
Details
Variants
- variant
- neutraloutlineprimarysuccesswarningdanger
Example
tsx
<Badge variant="success">Active</Badge>Accessibility
Status is conveyed by text (and optional icon), never color alone.