Synertech Web/ui v0.57.5 Site Storybook

Documentation / Display & media

Badge

Server-compatible@synertech/uiOpen in Storybook

A compact label to qualify an item: a status, a category, a counter. Nine semantic or decorative colours, four variants (soft by default, solid, outlined, subtle) and three sizes.

The badge can carry a dot (dot) or an icon (icon) before the text — the dot wins if both are given. It is pill-shaped by default (pill={false} for square corners). A hook-free component: it renders on the server.

Examples

Basic usage

The text goes in as children; color gives the meaning.

Open in a tab
import { Badge } from "@synertech/ui";

export function Basic() {
  return (
    <div className="flex flex-wrap gap-2">
      <Badge>Brouillon</Badge>
      <Badge color="primary">Nouveau</Badge>
      <Badge color="success">Actif</Badge>
      <Badge color="warning">En attente</Badge>
      <Badge color="error">Rejeté</Badge>
    </div>
  );
}

Variants

From the strongest to the most discreet: solid, soft, outlined, subtle.

Open in a tab
import { Badge } from "@synertech/ui";

export function Variants() {
  return (
    <div className="flex flex-wrap gap-2">
      <Badge color="indigo" variant="solid">
        Solid
      </Badge>
      <Badge color="indigo" variant="soft">
        Soft
      </Badge>
      <Badge color="indigo" variant="outlined">
        Outlined
      </Badge>
      <Badge color="indigo" variant="subtle">
        Subtle
      </Badge>
    </div>
  );
}

Sizes and shape

size sets the padding and the type size; pill={false} swaps the pill for square corners.

Open in a tab
import { Badge } from "@synertech/ui";

export function SizesAndShape() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <Badge size="sm" color="teal">
        Petit
      </Badge>
      <Badge size="md" color="teal">
        Moyen
      </Badge>
      <Badge size="lg" color="teal">
        Grand
      </Badge>
      <Badge size="md" color="teal" pill={false}>
        Coins droits
      </Badge>
    </div>
  );
}

Dot and icon

dot adds a dot in the badge’s colour; icon places an icon before the text.

Open in a tab
import { Badge } from "@synertech/ui";

const CheckIcon = () => (
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
    <path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
  </svg>
);

export function DotAndIcon() {
  return (
    <div className="flex flex-wrap gap-2">
      <Badge color="success" dot>
        En ligne
      </Badge>
      <Badge color="default" dot>
        Hors ligne
      </Badge>
      <Badge color="primary" icon={<CheckIcon />}>
        Vérifié
      </Badge>
    </div>
  );
}

Statuses in a list

A common case: the status of each row of an orders table.

Open in a tab
import { Badge, type BadgeColor } from "@synertech/ui";

const orders: { id: string; status: string; color: BadgeColor }[] = [
  { id: "CMD-1042", status: "Livrée", color: "success" },
  { id: "CMD-1043", status: "En préparation", color: "warning" },
  { id: "CMD-1044", status: "Annulée", color: "error" },
  { id: "CMD-1045", status: "Expédiée", color: "info" },
];

export function OrderStatuses() {
  return (
    <ul className="divide-y divide-gray-200 rounded-lg border border-gray-200 dark:divide-gray-700 dark:border-gray-700">
      {orders.map((order) => (
        <li key={order.id} className="flex items-center justify-between px-4 py-2 text-sm">
          <span className="font-mono text-gray-700 dark:text-gray-300">{order.id}</span>
          <Badge color={order.color} dot>
            {order.status}
          </Badge>
        </li>
      ))}
    </ul>
  );
}

API reference

Components

Badge

ComponentServer-compatible
import { Badge } from "@synertech/ui";

Props — BadgeProps

PropTypeDefaultDescription
children ReactNode —
color BadgeColor "default"
dot boolean false
icon ReactNode —
pill boolean true
size BadgeSize "md"
variant BadgeVariant "soft"

+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

type BadgeColor = | "default"
  | "primary"
  | "success"
  | "warning"
  | "error"
  | "info"
  | "purple"
  | "indigo"
  | "teal"
type BadgeSize = "sm" | "md" | "lg"
type BadgeVariant = "solid" | "soft" | "outlined" | "subtle"