$npx @dinachi/cli@latest add badge
Default
Secondary
Destructive
Outline
Success
Warning
Info
sizeroundeddefault
sm
md
lg
none
dismissiblestatus-badges.tsx
import { Badge } from "@/components/ui/badge"
const variants = [
"default", "secondary", "destructive", "outline", "success", "warning", "info",
] as const
export function StatusBadges() {
return (
<div className="flex flex-wrap gap-2">
{variants.map((variant) => (
<Badge key={variant} variant={variant}>
{variant.charAt(0).toUpperCase() + variant.slice(1)}
</Badge>
))}
</div>
)
}Usage
import { Badge } from "@/components/ui/badge"
export function DeployStatus() {
return <Badge variant="success">Live</Badge>
}Examples
Default
Secondary
Destructive
Outline
Success
Warning
Info
Each colour scheme, from default to info.
import { Badge } from '@/components/ui/badge';
export function Example() {
return (
<div className="flex gap-2 flex-wrap">
<Badge variant="default">Default</Badge>
<Badge variant="secondary">Secondary</Badge>
<Badge variant="destructive">Destructive</Badge>
<Badge variant="outline">Outline</Badge>
<Badge variant="success">Success</Badge>
<Badge variant="warning">Warning</Badge>
<Badge variant="info">Info</Badge>
</div>
);
}Badge
A badge with the default style.
import { Badge } from '@/components/ui/badge';
export function Example() {
return <Badge>Badge</Badge>;
}Small
Default
Large
Small, default and large.
import { Badge } from '@/components/ui/badge';
export function Example() {
return (
<div className="flex gap-2 items-center">
<Badge size="sm">Small</Badge>
<Badge size="default">Default</Badge>
<Badge size="lg">Large</Badge>
</div>
);
}Notes
Removing a badge
dismissible only draws the button. Remove the badge from state in onDismiss:
{tags.map((tag) => (
<Badge key={tag} dismissible onDismiss={() => remove(tag)}>
{tag}
</Badge>
))}Styling other elements
badgeVariants() takes the same variant, size and rounded options, to style a link or button as a badge.
API
variant"default" | "secondary" | "destructive" | "outline" | "success" | "warning" | "info" = "default"
The colour scheme.size"sm" | "default" | "lg" = "default"
Padding and text size.rounded"default" | "sm" | "md" | "lg" | "none" = "default"
Corner radius. default is fully rounded.iconReactNode
Shown before the text.dismissibleboolean = false
Adds a remove button after the text.onDismiss() => void
Runs on remove click. The badge does not hide itself.Accessibility
- A plain div with no role; its text reads with the surrounding content.
- Put the status in the text; colour alone does not convey it.
- The remove button is a native button named "Remove" on every badge; let context identify which.
Keyboard
EnterSpaceOn the remove button, runs
onDismissEnterSpaceOn the remove button, runs
onDismiss