Badge
Status labels. 5 colors × 3 styles × 2 sizes.
In stock
import { Badge } from "@/components/ui/badge";
export default function Example() {
return <Badge color="success">In stock</Badge>;
}
Installation
$ npx uix-ui@latest add badgeThis copies the file into components/ui/badge.tsx in your project. npx shadcn@latest add @uix/badge works too.
Usage
import { Badge } from "@/components/ui/badge";
<Badge color="success">In stock</Badge>
Examples
Colours
DraftNewDeliveredPackingCancelled
import { Badge } from "@/components/ui/badge";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge color="neutral">Draft</Badge>
<Badge color="brand">New</Badge>
<Badge color="success">Delivered</Badge>
<Badge color="warning">Packing</Badge>
<Badge color="error">Cancelled</Badge>
</div>
);
}
Appearances
subtleDraftUnpaid
solidDraftUnpaid
outlineDraftUnpaid
import { Badge } from "@/components/ui/badge";
export default function Example() {
return (
<div style={{ display: "grid", gap: 10 }}>
{(["subtle", "solid", "outline"] as const).map(a => (
<div key={a} className="flex flex-wrap items-center gap-2">
<Badge appearance={a} color="brand">{a}</Badge>
<Badge appearance={a} color="neutral">Draft</Badge>
<Badge appearance={a} color="error">Unpaid</Badge>
</div>
))}
</div>
);
}
Dot, icon and removable
OnlineBestsellerSylhetOrganic
import * as React from "react";
import { Badge } from "@/components/ui/badge";
import { Star } from "@/components/ui/icons";
export default function Example() {
const [tags, setTags] = React.useState(["Sylhet", "Organic"]);
return (
<div className="flex flex-wrap items-center gap-2">
<Badge dot color="success">Online</Badge>
<Badge size="sm" color="brand" leadingIcon={<Star />}>Bestseller</Badge>
{tags.map(t => <Badge key={t} color="neutral" onClose={() => setTags(s => s.filter(x => x !== t))}>{t}</Badge>)}
</div>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
color | neutral | brand | success | warning | error | "neutral" | |
appearance | subtle | solid | outline | "subtle" | |
size | sm | md | "md" | |
dot | boolean | false | Shows a small dot before the label. |
leadingIcon | React.ReactNode | – | Icon before the label. |
onClose | () => void | – | Shows a close button and calls this when it is pressed. |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.tscomponents/ui/icons.tsx