Badge
A small label, like a status.
BadgeSecondaryDestructiveOutline
badge-demo.tsx
import { Badge } from './ui/badge.tsx'
export default () => (
<>
<Badge>Badge</Badge>
<Badge variant="secondary">Secondary</Badge>
<Badge variant="destructive">Destructive</Badge>
<Badge variant="outline">Outline</Badge>
</>
)
Installation
dui add badgeOr copy ui/badge.tsx and ui/badge.css into your project, with lib/jsx/jsx-runtime.ts, lib/jsx/jsx-dev-runtime.ts, lib/css.d.ts, and lib/theme.css.
Examples
With an icon, and as a count
Verified899+
badge-icon.tsx
import { Badge } from './ui/badge.tsx'
export default () => (
<>
<Badge variant="secondary">
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M20 6 9 17l-5-5" />
</svg>
Verified
</Badge>
<Badge style="min-width: 1.25rem; border-radius: 9999px; padding-inline: 0.25rem">8</Badge>
<Badge
variant="destructive"
style="min-width: 1.25rem; border-radius: 9999px; padding-inline: 0.25rem"
>
99+
</Badge>
</>
)
As a link
badge-link.tsx
import { Badge } from './ui/badge.tsx'
// With an href, it's an <a>.
export default () => (
<Badge href="/docs/components/badge" variant="outline">
Link
</Badge>
)
Compared to shadcn/ui
- The same four variants.
- No
asChild: give it anhrefand it's an<a>, with a hover color as shadcn's has for links.