Badge

Badge

HkBadge is the small tone-coded label: a pill (or a square, or a bare dot) that marks a piece of content with a state — a count, a version, a "beta", a live indicator — without taking a click. Its colour model is variable-driven: a variant sets the text, background and border channels coherently, and color / bgColor / borderColor override any single channel.

  • A removable chip whose × runs the remove — a token, a filter, a selection — is a Tag.
  • A count or a dot pinned to a corner of another element is HkCornerBadge.
  • An identity chip that carries a person's picture or initial is HkAvatar.

Import

tsx
1
import { HkBadge } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // Badge, BadgeVariant, BadgeSize
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, Badge(BadgeProps { … }). Inside rsx! every prop may be omitted and the component's children are the badge text — Badge { "Beta" } renders the same markup as <HkBadge>Beta</HkBadge>.

Variants

Seven tones: default (the plain neutral pill), primary, success, error, warning, info and muted. Each one sets all three colour channels at once, and each rides the theme palette, so a themed host recolours them together.

DefaultPrimarySuccessWarningErrorInfoMuted

Size, shape and typography

size has two steps, sm and md (the default), carried by data-size. pill defaults to true; pill={false} gives the square-cornered chip. mono switches the label to the monospace family and uppercase upper-cases it with a little extra tracking — useful for a version tag or a code.

SmallMediumSquarev0.55.530Beta

Dot and colour overrides

dot puts a small round marker before the text, and with no content at all the badge collapses into the dot alone — the badge drops its padding, border and background so that what remains is the indicator, not a dot inside an empty pill. In the Vue form pulse animates that dot (a live / in-flight state); it only takes effect together with dot, and a prefers-reduced-motion host gets the still dot.

The three colour props write the --hk-badge-text / --hk-badge-bg / --hk-badge-border custom properties, so they override exactly one channel of the variant and leave the other two alone.

OnlineLiveCustom ink

API

Vue

Props

NameTypeDefaultRequired
variantString as PropType<BadgeVariant>"default"—
dotBooleanfalse—
pulseBooleanfalse—
size<code>String as PropType<"sm" | "md"></code>"md"—
monoBooleanfalse—
uppercaseBooleanfalse—
pillBooleantrue—
colorStringundefined—
bgColorStringundefined—
borderColorStringundefined—

Rust

Props — Badge

PropTypeDefaultDescription
variantBadgeVariantBadgeVariant::Default—
dotboolfalseRender the leading dot marker.
sizeBadgeSizeBadgeSize::Md—
monoboolfalseMonospace ink (data-mono).
uppercaseboolfalseUppercase ink (data-uppercase).
pillbooltruePill radius (Vue default true; false emits data-pill="false").
colorOption<String>None--hk-badge-text override.
bg_colorOption<String>None--hk-badge-bg override.
border_colorOption<String>None--hk-badge-border override.
childrenElement(empty)The badge content (Vue: the default slot).

Accessibility

  • The badge is a <span>: it carries no role, is not focusable and takes no clicks, so it never enters the tab order.
  • The text is the accessible content — a variant colour never is. A badge that only says "Success" through its green fill is announced as the word "Success" and nothing more, so keep the meaning in the text.
  • A dot with no text renders an empty marker, which is decorative; it announces nothing, and that is deliberate. If the dot is the only carrier of the state, put the state in the surrounding text.
  • uppercase is a visual transform only: the text node keeps its original case for assistive technology and for copy-paste.

Related components

  • Tag — the removable chip, with an optional close button.
  • HkCornerBadge — a dot or a count anchored to another element's corner.
  • HkAvatar — the round identity chip.