Raft 设计系统

组件 · 数据展示

Badge

A small label — above all the pink unread count and the yellow @ marker, plus soft-tinted and hairline labels.

稳定也叫 unread count, mention marker, count
import { Badge } from "@botiverse/raft-ui";
本页尚未翻译
译文完成之前,这里显示英文原文。 阅读英文版

Badge is a small label. Its main job is the unread count: a pink sticker that says something waits for the person. When someone mentions the person, a yellow @ marker takes its place, because it is more specific. Other appearances of Badge make the soft-tinted and hairline labels that status chips and tags are built from (Status).

When to use

SituationUse
Unread messages on a list row or a sidebar row; new thread replies; new activityThe unread count: variant="accent" (the attention color). In the sidebar, SidebarItemCount (Sidebar)
Someone mentioned the personThe @ marker: variant="primary" (the brand color) with the at-sign icon. In the sidebar, SidebarItemIndicator
Unread items in a muted placeA gray number in Space Mono (text-mono-meta, foreground-hint), not a badge
Something waits, on a rail icon, a tab bar icon or the bellThe attention dot: one pink pixel (Status), never a number
Where a task is, or how an agent isA status chip: TaskStatusBadge (Tasks) or a soft Badge with a pixel (Status)
This is an agent; where it runsThe agent tag and the runtime chip (Status)

Anatomy

  • Badge: the label. It holds a number, a word, or an icon and a word.
  • Badge.Experimental: a preset that reads Experimental, so every experimental surface shows the same label.

Variants

AppearanceUse for
appearance="solid"A sticker: a count or a mark that waits for the person, with an ink edge and ink type. The unread count and the @ marker
appearance="soft"A soft-tinted label with no border: status chips of agent states, the runtime chip
appearance="outline"A hairline label in Space Mono: the agent tag, a reply count beside a task chip

variant picks the color role. Choose it by what the color means, not by how it looks (Meanings of color): on a count, accent is the pink of "to do" and primary the yellow of "you".

States

  • A Badge rendered as a button (render={<button />}) shows the medium tier on hover and press (sticker-medium on a colour badge), and the shared disabled look (States).
  • The selected row never shows a count or an @ marker (States).

Content

  • Write the number alone, in Space Mono. Above 99, write 99+.
  • Don't write a count in the @ marker: it says only that someone mentioned the person.

Accessibility

Badge renders a <span> and wraps no Base UI primitive.

  • Give a count or an @ marker with no words next to it role="img" and an aria-label that says what it means: "3 unread", "Mentions you".
  • Give a Badge rendered as a button an aria-label that names its action ("Open thread replies") when its text doesn't.

Rules

  • Show at most one badge per row, in the same column as the time.
  • When a row has both unread messages and a mention, show only the @ marker.
  • Use the gray number for a muted place, never the pink sticker: the person chose not to be called by it.
  • Put only the attention dot on rail and tab bar icons and on the bell, never a number.

API

Badge

Prop类型默认值
appearance"outline" | "solid" | "soft""solid"
variant"primary" | "accent" | "warning" | "danger" | "default" | "information" | "muted" | "success""default"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

改动

  • 0.6.0 · Breaking ChangesProps that no longer change anything are removed: Badge uppercase; Checkbox size, variant, color; Status pulse, attention (status never animates); Switch / SwitchThumb size; SidebarItem variant; SidebarItemCount / SidebarItemIndicator variant and appearance (the count is always the pink sticker, the indicator the yellow @); NotificationCenterActionButton variant; DrawerContent width (one-go forms use the wide Dialog); AppRailItemIndicator attention; AppRailItemAttention children; Steps size, track, renderIndicator, renderTraveler; FilePreviewBadge type, color. Remove them at call sites.
  • 0.5.39 · FixedBrutal TaskStatusBadge draws a 1px black keyline instead of 2px, matching TaskChip and Badge; py-px keeps it exactly 20px tall, so surrounding layout does not move (Elegant unchanged).
  • 0.5.31 · FixedTaskStatusBadge in Brutal is a square, hard-edged tag again (no radius, 2px black border, bold, 20px tall), matching the Brutal TaskChip and Badge. 0.5.30 rendered it as a rounded pill. Elegant is unchanged.