Badge

A badge or a component that looks like a badge.

API Reference
Loading...
Loading code...

Installation

pnpm dlx shadcn@latest add @uitopia/badge

Usage

import { Badge } from "@/components/ui/badge"
<Badge>Badge</Badge>

You can use the render prop to make another component look like a badge. Here's an example of a link that looks like a badge.

import Link from "next/link"

import { Badge } from "@/components/ui/badge"

export function LinkAsBadge() {
  return <Badge render={<Link href="/pricing" />}>New</Badge>
}

Examples

Outline

Loading...
Loading code...

Secondary

Loading...
Loading code...

Destructive

Loading...
Loading code...

Info

Loading...
Loading code...

Success

Loading...
Loading code...

Warning

Loading...
Loading code...

Error

Loading...
Loading code...

Large

Loading...
Loading code...

With Icon

Loading...
Loading code...
Loading...
Loading code...

Comparing with Radix / shadcn

If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with ui/topia quickly.

Prop Mapping

ComponentRadix UI PropBase UI Prop
BadgeasChildrender

Quick Checklist

  • Replace asChildrender on Badge

Additional Notes

Size Comparison

Compared to shadcn/ui, our Badge component includes size variants for better density control. shadcn/ui badges have a fixed size, while our component offers flexible sizing with sm, default, and lg options.

So, if you want to preserve the original shadcn/ui badge size, you should use the lg size in ui/topia.

New Variants

We've added new colored variants to the existing ones (default, destructive, outline, secondary) for better semantic meaning and visual communication:

We've added new colored variants for better semantic meaning:

VariantDescription
infoBlue badge for information
successGreen badge for success states
warningYellow badge for warnings
errorRed badge for errors

Ensure you have the following variables imported in your CSS file:

  • --destructive-foreground
  • --info
  • --info-foreground
  • --success
  • --success-foreground
  • --warning
  • --warning-foreground

Comparison Example

shadcn/ui
import Link from "next/link"
import { Badge } from "@/components/ui/badge"

export function LinkAsButton() {
  return (
    <Badge asChild>
      <Link href="/login">Login</Link>
    </Badge>
  )
}
ui/topia
import Link from "next/link"
import { Badge } from "@/components/ui/badge"

export function LinkAsButton() {
  return (
    <Badge render={<Link href="/login" />}>Login</Badge>
  )
}