Equality
Equality

Badge

Badge with sizes and variants

View Markdown

Overview

The Badge component comes with four color variants to visually communicate different statuses or contexts:

  • Primary: The default style, suitable for general labeling.
  • Secondary: Use after primary but information is of secondary (or equal) importance
  • Neutral: For non-critical, informational, or secondary status.
  • Warning: Indicates something that is worthy of more attention.
  • Danger: Indicates an error or danger state that requires serious attention.
  • Success: Represents positive outcomes or completed statuses.

For control compliance and resource types see ControlStatusBadge and ResourceBadge respectively.

Usage

Import the component:

import { Badge } from "@eqtylab/equality";

primary is the default variant. Select another by using the variant prop, for example:

<Badge variant="danger">Danger Badge</Badge>

Basic Variants

Badge Variant
Primary
Secondary
Neutral
Warning
Danger
Success
With Icons

Primary

Secondary

Neutral

Warning
Danger
Success
Icon Only

Sizes

The Badge comes in two sizes. The default md size is 20px tall and should be used in most situations, while sm is 16px tall for use in tighter layouts where density is desired (such as log viewers). Small badges generally look better with pill={false} applied.

Medium (Default)

Small

Small square

Usage

<Badge size="md">Medium (Default)</Badge>
<Badge size="sm">Small (Square)</Badge>
<Badge size="sm" pill={false}>Small (Square)</Badge>

Pill Shape

Badges are pill-shaped by default. Set pill={false} when using badges along with dense in-line text.

Pill (Default)
Square

Usage

<Badge>Pill (Default)</Badge>
<Badge pill={false}>Square</Badge>

Display Modes

The Badge component supports three display modes to control what content is shown:

Both (Default)

Text Only

Usage

{
  /* Default - shows both icon and text */
}
<Badge variant="primary" icon="Shield">
  Both Icon and Text
</Badge>;

{
  /* Text only - hides the icon */
}
<Badge variant="primary" icon="Shield" display="text-only">
  Text Only
</Badge>;

{
  /* Icon only - hides the text */
}
<Badge variant="primary" icon="Shield" display="icon-only" />;

Closable Variant


The closable variant of the Badge is commonly used to represent active filters or selections, such as when content is filtered by a search bar. This allows users to easily remove specific filters by clicking the close button on the corresponding badge.

Truncation

The Badge component supports text truncation for long content. Use the truncate prop to enable truncation, and optionally set a custom truncateLength (defaults to 50 characters). When text exceeds the specified length, it will be truncated with an ellipsis (”…”), and the full text will be displayed in a tooltip on hover. This is particularly useful for maintaining consistent badge sizes when displaying variable-length content.

Monospace

Use the monospace prop when badges will be rendered atop one another and their contents always or often share the same character count.

v1.3.0

0x1a2b

build-482

Usage

<Badge monospace>v1.3.0</Badge>

Icons

You can enhance your badge by displaying an icon. The icon prop accepts either a string corresponding to any Lucide React icon key (such as "Layers" or "CheckCircle"), or you can provide a custom icon component. For custom icons, pass a React component or element to the icon prop.

This is a badge

Usage

// Using a Lucide React icon by name
<Badge icon="Layers">With Lucide Icon</Badge>

// Using a custom icon component
<Badge icon={<MyCustomIcon />}>With Custom Icon</Badge>

Props

PropTypeDefaultDescription
variant"neutral" | "primary" | "secondary" | "warning" | "danger" | "success""primary"The visual style variant of the badge.
size"sm" | "md""md"The size of the badge. "md" renders at 20px tall, "sm" at 16px tall.
display"both" | "text-only" | "icon-only""both"Controls what elements are displayed. "both" shows icon and text, "text-only" shows only text, "icon-only" shows only icon.
iconstring | ReactElement-Icon to display. Can be a Lucide icon name or a custom React element.
pillbooleantrueWhen true (default), badge is pill-shaped. Set to false for a square badge with subtle border radius.
monospacebooleanfalseWhen true, renders badge text in a monospace font.
closeablebooleanfalseWhen true, displays a close button on the badge.
handleClosable() => void-Callback function called when the close button is clicked. Required when closeable is true.
truncatebooleanfalseWhen true, truncates long text with an ellipsis and shows full text on hover.
truncateLengthnumber50Maximum character length before truncation occurs.
classNamestring-Additional CSS classes to apply to the badge.