Badge

A small label that marks a status, a category or a count, in its tone's colour, info by default.

Badge
import { Badge } from "@produkto/ui/Badge";

const Example = () => <Badge>Badge</Badge>;

export default Example;

Usage

import { Badge } from "@produkto/ui/Badge";
<Badge tone="info | accent | destructive | success | warning">
  Badge
</Badge>

Examples

Tones

tone sets the colour, info by default, accent, destructive, success or warning, each a light fill with its own line and words, as an alert is: one look for every status, and never a grey one.

AccentDestructiveSuccessWarningInfo
import { Badge, type BadgeTone } from "@produkto/ui/Badge";

const tones: { tone: BadgeTone; label: string }[] = [
  { tone: "accent", label: "Accent" },
  { tone: "destructive", label: "Destructive" },
  { tone: "success", label: "Success" },
  { tone: "warning", label: "Warning" },
  { tone: "info", label: "Info" },
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {tones.map(({ tone, label }) => (
      <Badge key={tone} tone={tone}>
        {label}
      </Badge>
    ))}
  </div>
);

export default Example;

Sizes

size sets its height: sm 16px, base 20px (the default) or lg 24px, its words and an icon a step smaller or bigger with it.

SmallBaseLarge
import { Badge, type BadgeSize } from "@produkto/ui/Badge";

const sizes: { size: BadgeSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {sizes.map((item) => (
      <Badge key={item.size} size={item.size}>
        {item.label}
      </Badge>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets the corners on the kit's one scale: none, xs 4px, sm 6px, base 8px, lg 12px, xl 16px, or full to round it, which makes a badge holding a count at least as wide as it is tall, in tabular numerals; base is the default.

nonexssmbaselgxlfull8
import { Badge, type BadgeBorderRadius } from "@produkto/ui/Badge";

const radii: BadgeBorderRadius[] = [
  "none",
  "xs",
  "sm",
  "base",
  "lg",
  "xl",
  "full",
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {radii.map((borderRadius) => (
      <Badge key={borderRadius} borderRadius={borderRadius}>
        {borderRadius}
      </Badge>
    ))}
    <Badge borderRadius="full">8</Badge>
  </div>
);

export default Example;

With icon

An icon goes in as a child, and data-icon="inline-start" or "inline-end" trims the padding on its side.

BadgeBadge
import { Badge } from "@produkto/ui/Badge";
import {
  Bookmark01Icon,
  CheckmarkBadge01Icon,
} from "@hugeicons/core-free-icons";
import { Icon } from "@produkto/ui/Icon";

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    <Badge>
      <Icon icon={CheckmarkBadge01Icon} data-icon="inline-start" />
      Badge
    </Badge>
    <Badge>
      Badge
      <Icon icon={Bookmark01Icon} data-icon="inline-end" />
    </Badge>
  </div>
);

export default Example;

API Reference

Badge

BadgeProps · components/Badge/Badge.types.ts
PropTypeDefault
asChildbooleanfalse
toneBadgeTone"info"
sizeBadgeSize"sm" | "base" | "lg""base"
borderRadiusBadgeBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full""base"

It also takes the props of <span>.