Badge
⋯
Badge is the single display component for the Figma Badge and Badge & Chip/Tag designs. variant selects the visual anatomy. The consumer supplies visible text and any course logo.
import { Badge } from "@nesra/ui/badge";
export function Status() { return ( <Badge appearance="outline" status="verified" variant="status"> Terverifikasi </Badge> );}Badge is also exported from @nesra/ui.
Examples
Section titled “Examples”Label colors and appearances
Section titled “Label colors and appearances”The Figma Soft and Fill label treatments map to appearance="soft" and appearance="fill". Figma colors map to lowercase color values. Figma Purple is bound to the Categorical Violet roles.
import { Badge } from "@nesra/ui/badge";
export function BadgeVariantsExample() { return ( <div className="grid gap-3"> {(["brand", "info", "success", "warning", "error", "neutral", "purple"] as const).map( (color) => ( <div className="flex items-center gap-3" key={color}> <Badge color={color}>{color}</Badge> <Badge appearance="fill" color={color}> {color} </Badge> </div> ), )} </div> );}Label sizes and icons
Section titled “Label sizes and icons”sm targets 20px height and 12px text. md targets 24px height and 14px text. startIcon and endIcon render decorative content.
import { Badge } from "@nesra/ui/badge";import { Circle } from "lucide-react";
export function BadgeSizesExample() { return ( <div className="flex flex-wrap items-center gap-3"> <Badge size="sm">Small</Badge> <Badge size="md">Medium</Badge> <Badge color="info" startIcon={<Circle />}> With icon </Badge> </div> );}With icons
Section titled “With icons”startIcon and endIcon are decorative. Keep the visible label meaningful without them.
import { Badge } from "@nesra/ui/badge";import { ArrowUpRight, CheckCircle2, CircleAlert } from "lucide-react";
export function BadgeIconsExample() { return ( <div className="flex flex-wrap items-center gap-3"> <Badge color="success" startIcon={<CheckCircle2 />}> Verified </Badge> <Badge appearance="fill" color="warning" startIcon={<CircleAlert />}> Attention </Badge> <Badge color="info" endIcon={<ArrowUpRight />}> Details </Badge> <Badge appearance="fill" color="brand" startIcon={<CheckCircle2 />} endIcon={<ArrowUpRight />} > Complete </Badge> </div> );}Removable
Section titled “Removable”onRemove adds a remove button after a label badge. With onRemove, endIcon becomes the button’s
icon, and the default icon is X. The page removes the badge from its own state in the handler.
import { Badge } from "@nesra/ui/badge";import { Button } from "@nesra/ui/button";import { Trash2 } from "lucide-react";import { useState } from "react";
const initialDates = ["03 Oct 2026", "10 Oct 2026", "17 Oct 2026"];
export function BadgeRemovableExample() { const [dates, setDates] = useState(initialDates);
if (dates.length === 0) { return ( <Button size="sm" variant="outline" onClick={() => setDates(initialDates)}> Restore dates </Button> ); }
return ( <ul className="flex flex-wrap items-center gap-3"> {dates.map((date) => ( <li key={date}> <Badge color="neutral" endIcon={<Trash2 />} onRemove={() => setDates((current) => current.filter((item) => item !== date))} > {date} </Badge> </li> ))} </ul> );}In a sentence
Section titled “In a sentence”Badges can sit beside ordinary text without changing the text’s semantics.
import { Badge } from "@nesra/ui/badge";
export function BadgeInlineExample() { return ( <div className="grid gap-3"> <p className="flex flex-wrap items-center gap-2"> Course catalog{" "} <Badge color="info" size="sm"> New </Badge> </p> <p className="flex flex-wrap items-center gap-2"> Payment{" "} <Badge appearance="outline" status="verified" variant="status"> Terverifikasi </Badge> </p> </div> );}Linked badge
Section titled “Linked badge”Wrap a Badge in a native anchor for navigation. The anchor owns the destination and keyboard focus.
import { Badge } from "@nesra/ui/badge";
export function BadgeLinkedExample() { return ( <a className="inline-flex rounded-nesra-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-nesra-stroke-link" href="/changelog/" > <Badge color="info">View changelog</Badge> </a> );}Indicator
Section titled “Indicator”The Figma Mini Badge is variant="indicator". It has dot and check treatments with 8, 12, 16, and 20px diameters.
import { Badge } from "@nesra/ui/badge";
export function BadgeIndicatorsExample() { return ( <div className="flex items-center gap-4"> <Badge aria-label="Online" size={8} variant="indicator" /> <Badge aria-label="Online" size={12} variant="indicator" /> <Badge aria-label="Verified" indicator="check" size={16} variant="indicator" /> <Badge aria-label="Verified" indicator="check" size={20} variant="indicator" /> </div> );}Status
Section titled “Status”status selects the pending, verified, or canceled palette and icon. appearance selects filled or outlined treatment. The text is supplied through children.
import { Badge } from "@nesra/ui/badge";
const statuses = [ { status: "pending", label: "Menunggu Pembayaran" }, { status: "verified", label: "Terverifikasi" }, { status: "canceled", label: "Dibatalkan" },] as const;
export function BadgeStatusExample() { return ( <div className="grid gap-3"> {statuses.map(({ status, label }) => ( <div className="flex flex-wrap gap-3" key={status}> <Badge appearance="fill" status={status} variant="status"> {label} </Badge> <Badge appearance="outline" status={status} variant="status"> {label} </Badge> </div> ))} </div> );}Course categories
Section titled “Course categories”course uses three sizes. Pass the course logo through startIcon; the preview uses a generic spreadsheet icon.
import { Badge } from "@nesra/ui/badge";import { FileSpreadsheet } from "lucide-react";
export function BadgeCourseExample() { return ( <div className="grid gap-3"> <div className="flex flex-wrap items-center gap-3"> <Badge size="xs" startIcon={<FileSpreadsheet />} variant="course"> Microsoft Excel </Badge> <Badge size="sm" startIcon={<FileSpreadsheet />} variant="course"> Microsoft Excel </Badge> <Badge size="md" startIcon={<FileSpreadsheet />} variant="course"> Microsoft Excel </Badge> </div> <div className="flex flex-wrap items-center gap-3"> <Badge size="xs" startIcon={<FileSpreadsheet />} variant="course"> Google Sheets </Badge> <Badge size="sm" startIcon={<FileSpreadsheet />} variant="course"> Google Sheets </Badge> <Badge size="md" startIcon={<FileSpreadsheet />} variant="course"> Google Sheets </Badge> </div> </div> );}XP states
Section titled “XP states”xpState changes the visual state. active shares the default blue treatment; the supplied text distinguishes the claim prompt. A claimed badge shows a check. An actual claim action needs a separate control.
import { Badge } from "@nesra/ui/badge";
export function BadgeXpExample() { return ( <div className="grid gap-3"> <div className="flex flex-wrap items-center gap-3"> <Badge size="xs" variant="xp"> 50XP </Badge> <Badge size="xs" variant="xp" xpState="active"> Klaim 50XP </Badge> <Badge size="xs" variant="xp" xpState="claimed"> 50XP </Badge> </div> <div className="flex flex-wrap items-center gap-3"> <Badge size="sm" variant="xp"> 50XP </Badge> <Badge size="sm" variant="xp" xpState="active"> Klaim 50XP </Badge> <Badge size="sm" variant="xp" xpState="claimed"> 50XP </Badge> </div> </div> );}Levels
Section titled “Levels”level changes the highlighted bars. sm and md change padding around the same 12px text.
import { Badge } from "@nesra/ui/badge";
export function BadgeLevelExample() { return ( <div className="grid gap-3"> <div className="flex flex-wrap items-center gap-3"> <Badge level="easy" size="sm" variant="level"> Mudah </Badge> <Badge level="moderate" size="sm" variant="level"> Sedang </Badge> <Badge level="hard" size="sm" variant="level"> Sulit </Badge> </div> <div className="flex flex-wrap items-center gap-3"> <Badge level="easy" size="md" variant="level"> Mudah </Badge> <Badge level="moderate" size="md" variant="level"> Sedang </Badge> <Badge level="hard" size="md" variant="level"> Sulit </Badge> </div> </div> );}Light and Dark
Section titled “Light and Dark”Badge follows the page theme. Dark applies when an ancestor has the dark class or
data-theme="dark".
| Badge | Fill | Text |
|---|---|---|
| Brand soft | Foundation/bg-brand-primary-50 |
Text/text-body |
| Brand fill | Foundation/bg-brand-primary |
Text/text-on-brand |
| Info soft | Categorical/Blue/subtle |
Text/text-link, icons Icon/icon-info |
| Info fill, XP, Verified | Foundation/bg-info-solid |
Text/text-staticWhite |
| Success soft | Categorical/Green/subtle |
Categorical/Green/foreground |
| Success fill | Foundation/bg-success-solid |
Text/text-staticWhite |
| Warning soft | Categorical/Yellow/subtle |
Categorical/Yellow/foreground, icons Icon/icon-warning |
| Warning fill, Pending | Categorical/Yellow/base |
Text/text-staticDark |
| Error soft | Categorical/Red/subtle |
Categorical/Red/foreground, icons Icon/icon-destructive |
| Error fill | Action/destructive-default |
Text/text-staticWhite |
| Neutral soft | Foundation/bg-gray |
Text/text-body |
| Neutral fill | Categorical/Neutral/base |
Text/text-staticWhite |
| Purple soft | Categorical/Violet/subtle |
Text/text-body, icons Icon/icon-neutral |
| Purple fill | Categorical/Violet/base |
Text/text-staticDark, icons Icon/icon-staticDark |
| Canceled status | Foundation/bg-disabled |
Text/text-tertiary, icon Icon/icon-muted |
| Claimed XP | Surface/card-bg-gray |
Text/text-support |
The soft fills and the Brand fill change between modes. The solid Info, Success, Warning, Error,
Neutral, and Purple fills keep the same color in both modes, so their static text colors stay readable. The
indicator is Foundation/bg-success-solid with a Foundation/bg-neutral border and check, so it
stays separated from the page in both modes. The remove button shows Box Shadow/Focus ring on
soft badges and Box Shadow/Focus ring offset on fill badges, where a plain ring would blend into
the fill.
Accessibility
Section titled “Accessibility”Badge renders a native span. The span itself never acts as a button. With onRemove, a label
badge contains one native <button type="button"> outside the hidden icon slots. Its accessible name
is removeLabel, or Remove {label} built from string or number children, or Remove for other
children. Translate both defaults through NesraI18nProvider. The application moves
focus to a sensible place after removal. Label text, status text, XP text, and level text are exposed to assistive technology. Decorative icons are hidden. Give an indicator an aria-label when it conveys meaning alone, or aria-hidden="true" when nearby text supplies that meaning. The application owns live announcements for changing status and action behavior for clickable XP prompts.
API reference
Section titled “API reference”| Prop | Type | Default | Effect |
|---|---|---|---|
variant |
"label" | "indicator" | "status" | "course" | "xp" | "level" |
"label" |
Selects visual anatomy. |
appearance |
"soft" | "fill" | "outline" |
By variant | Label defaults to soft; status defaults to fill. |
color |
"brand" | "info" | "success" | "warning" | "error" | "neutral" | "purple" |
"brand" |
Label color. |
size |
"xs" | "sm" | "md" | 8 | 12 | 16 | 20 |
By variant | Label: md; indicator: 16px; course and XP: xs; level: sm. |
indicator |
"dot" | "check" |
"dot" |
Indicator glyph. |
status |
"pending" | "verified" | "canceled" |
"pending" |
Status palette and icon. |
xpState |
"default" | "active" | "claimed" |
"default" |
XP color and claimed check. Active shares default styling; its text is consumer supplied. |
level |
"easy" | "moderate" | "hard" |
"easy" |
Number of highlighted level bars. |
children |
ReactNode |
— | Visible label or text. Not rendered for indicator. |
startIcon, endIcon |
ReactNode |
— | Decorative slots. Course uses startIcon for its logo. Pass startIcon={null} to omit a status icon. |
onRemove |
(event: MouseEvent<HTMLButtonElement>) => void |
— | Label only. Renders a remove button that calls the handler. endIcon becomes its icon. |
removeLabel |
string |
— | Accessible name of the remove button. Overrides the translated default. |
Native span attributes, className, and refs are forwarded. badgeVariants returns classes for the label visual axes only. The course example uses a generic spreadsheet icon; applications can pass their licensed Excel or Google Sheets logos through startIcon to match the Figma artwork. Colors come from the Light and Dark semantic color roles; see also shape tokens.