Primitives
Badge
A small label for short static data, such as a plan, a version, a count or a tag.
Primitives
A small label for short static data, such as a plan, a version, a count or a tag.
import { Badge } from 'ferry-ui'
export default function BadgeHero() {
return (
<div className="flex flex-wrap items-center gap-2">
<span className="text-base font-medium text-foreground">Billing portal</span>
<Badge font="mono" shape="square">
Pro
</Badge>
<Badge variant="outline" font="mono">
v2.4.1
</Badge>
<Badge variant="primary">New</Badge>
</div>
)
}StatusBadge of Status.size="tiny".Import the component. A badge has one part.
import { Badge } from 'ferry-ui'
<Badge />The variant prop sets the color. default and outline are the neutral variants.
import { Badge } from 'ferry-ui'
export default function BadgeVariants() {
return (
<>
<Badge>Default</Badge>
<Badge variant="outline">Outline</Badge>
<Badge variant="success">Stable</Badge>
<Badge variant="warning">Beta</Badge>
<Badge variant="destructive">Deprecated</Badge>
<Badge variant="info">Preview</Badge>
<Badge variant="primary">New</Badge>
</>
)
}| Variant | Role |
|---|---|
default | A neutral badge with a fill. |
outline | A neutral badge with no fill. |
success, warning, destructive, info | A badge with a color, for example a warning "Beta". |
primary | A solid badge for emphasis, for example "New". Use few of them. |
Set font="mono" for values that come from a machine: a plan, a version, a region, an ID.
import { Badge } from 'ferry-ui'
export default function BadgeFont() {
return (
<>
<Badge>Pro</Badge>
<Badge font="mono">Pro</Badge>
<Badge variant="outline" font="mono">
v2.4.1
</Badge>
<Badge variant="outline" font="mono">
eu-west
</Badge>
</>
)
}The shape prop sets the corners. The default is pill. A square badge has a radius of 4px.
import { Badge } from 'ferry-ui'
export default function BadgeShape() {
return (
<>
<Badge shape="pill">Pill</Badge>
<Badge shape="square">Square</Badge>
<Badge variant="outline" shape="square" font="mono">
EUR
</Badge>
</>
)
}A badge shows its text in capital letters. Set case="normal" to show the text as you write it, for example a name.
import { Badge } from 'ferry-ui'
export default function BadgeCase() {
return (
<>
<Badge variant="outline">Design team</Badge>
<Badge variant="outline" case="normal">
Design team
</Badge>
<Badge case="normal">3 seats left</Badge>
</>
)
}Put a lucide icon in the badge, before the text. The badge sets the size of the icon.
import { Badge } from 'ferry-ui'
import { Lock, Sparkles, Users } from 'lucide-react'
export default function BadgeIcons() {
return (
<>
<Badge variant="outline" case="normal">
<Lock />
Private
</Badge>
<Badge case="normal">
<Users />8 members
</Badge>
<Badge variant="primary">
<Sparkles />
New
</Badge>
</>
)
}With asChild, the badge gives its look to its child element. Use it for a link.
import { Badge } from 'ferry-ui'
export default function BadgeAsChild() {
return (
<Badge asChild variant="outline" case="normal">
<a
href="https://github.com/Carter2307/ferry-ui"
target="_blank"
rel="noreferrer"
className="hover:bg-surface-200 hover:text-foreground"
>
Source code
</a>
</Badge>
)
}For text that comes from a user, give the badge a maximum width. Put the text in a truncate element. Keep the full text in title.
import { Badge } from 'ferry-ui'
const PLAN = 'Enterprise annual plan with priority support'
export default function BadgeLongText() {
return (
<div className="flex w-64 rounded-lg border bg-surface-100 p-3">
{/* The badge takes the width of its parent at most. The full text stays in `title`. */}
<Badge variant="outline" case="normal" className="max-w-full justify-start" title={PLAN}>
<span className="truncate">{PLAN}</span>
</Badge>
</div>
)
}badgeVariants() returns the classes of a badge. Use it for an element that cannot be a Badge, such as a list item.
import { badgeVariants } from 'ferry-ui'
const TAGS = ['Design', 'Frontend', 'Roadmap', 'Customer request']
export default function BadgeClassHelper() {
return (
<ul aria-label="Tags" className="flex flex-wrap gap-1.5">
{TAGS.map((tag) => (
<li key={tag} className={badgeVariants({ variant: 'outline', case: 'normal' })}>
{tag}
</li>
))}
</ul>
)
}Badge also accepts each attribute of the <span> element.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "primary" | "outline" | "destructive" | "warning" | "success" | "info" | default |
Tone. | ||
font | "sans" | "mono" | sans |
Typeface: | ||
shape | "pill" | "square" | pill |
Corners: | ||
case | "upper" | "normal" | upper |
Letter case: | ||
asChild | boolean | false |
Render the single child element (e.g. an | ||
badgeVariants(options) returns the classes as a string. Each option is optional.
| Option | Type | Role |
|---|---|---|
variant | 'default' | 'outline' | 'success' | 'warning' | 'destructive' | 'info' | 'primary' | The color. |
font | 'sans' | 'mono' | The font. |
shape | 'pill' | 'square' | The corners. |
case | 'upper' | 'normal' | The letter case. |