Badge

A short label for a status, a category or a count.

Source
$npx @dinachi/cli@latest add badge
Default
Secondary
Destructive
Outline
Success
Warning
Info
size
rounded
dismissible

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>
  );
}

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.