Skip to content
Kappa
Badge
@dicehub/kappav0.4.2

Badge

A compact label for status, classification, and supporting metadata.

PrimarySecondaryReady12 warningsFailed
<script setup>
import { Badge } from "@dicehub/kappa/components/badge";
</script>

<template>
  <div class="status-row">
    <Badge>Primary</Badge>
    <Badge variant="secondary">Secondary</Badge>
    <Badge variant="success">Ready</Badge>
    <Badge variant="warning">12 warnings</Badge>
    <Badge variant="error">Failed</Badge>
  </div>
</template>

Installation

Barrel

import { Badge } from "@dicehub/kappa";

Granular

import { Badge } from "@dicehub/kappa/components/badge";

Usage

Badge renders a non-interactive <span> by default and forwards standard attributes to that element.

Stable
<script setup>
import { Badge } from "@dicehub/kappa/components/badge";
</script>

<template>
  <Badge>Stable</Badge>
</template>

Examples

Semantic Variants

Prefer semantic variants for application state. Their meaning remains stable when the theme changes.

General
PrimarySecondaryOutlineBeta
Status
InfoSuccessWarningErrorDestructive
<script setup>
import { Badge } from "@dicehub/kappa/components/badge";
</script>

<template>
  <Badge>Primary</Badge>
  <Badge variant="secondary">Secondary</Badge>
  <Badge variant="outline">Outline</Badge>
  <Badge variant="beta">Beta</Badge>
  <Badge variant="info">Info</Badge>
  <Badge variant="success">Success</Badge>
  <Badge variant="warning">Warning</Badge>
  <Badge variant="error">Error</Badge>
  <Badge variant="destructive">Destructive</Badge>
</template>

Color Variants

Use color variants for categorical data with a legend or text label—not as the only indication of state.

RedOrangeGreenTealTeal subtleBluePurpleNeutral
<script setup>
import { Badge } from "@dicehub/kappa/components/badge";
</script>

<template>
  <Badge variant="red">Red</Badge>
  <Badge variant="orange">Orange</Badge>
  <Badge variant="green">Green</Badge>
  <Badge variant="teal">Teal</Badge>
  <Badge variant="teal-subtle">Teal subtle</Badge>
  <Badge variant="blue">Blue</Badge>
  <Badge variant="purple">Purple</Badge>
  <Badge variant="neutral">Neutral</Badge>
</template>

With Icons

Mark decorative icons with aria-hidden. Add data-icon="inline-start"or data-icon="inline-end" for optically balanced padding in both directions.

Verified Pinned
<script setup>
import { Badge } from "@dicehub/kappa/components/badge";
</script>

<template>
  <Badge variant="success">
    <svg data-icon="inline-start" viewBox="0 0 16 16" aria-hidden="true">
      <path d="m3 8 3 3 7-7" />
    </svg>
    Verified
  </Badge>
  <Badge variant="outline">
    Pinned
    <svg data-icon="inline-end" viewBox="0 0 16 16" aria-hidden="true">
      <path d="m5 2 6 6-2 1 3 3-1 1-3-3-1 2-2-10Z" />
    </svg>
  </Badge>
</template>

Set as="a" when the badge navigates. The resulting anchor retains native keyboard and link semantics.

In a Sentence

Badge aligns with surrounding text without changing the sentence semantics.

Simulation Complete in 18m 42s.

<script setup>
import { Badge } from "@dicehub/kappa/components/badge";
</script>

<template>
  <p>Simulation <Badge variant="success">Complete</Badge> in 18m 42s.</p>
</template>

Numeric Values

Legacy Badge versions accepted value, maxVal, and maxLen. Format numeric content in application code and pass it through the default slot instead.

128queued jobs
<script setup>
import { Badge } from "@dicehub/kappa/components/badge";

const queuedJobs = 128;
</script>

<template>
  <Badge variant="secondary">
    <span aria-hidden="true">{{ queuedJobs > 99 ? "99+" : queuedJobs }}</span>
    <span class="visually-hidden">{{ queuedJobs }}</span>
  </Badge>
  <span>queued jobs</span>
</template>

<style scoped>
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
</style>
When visible content is shortened, hide that shortcut from assistive technology and preserve the full value in visually hidden text.

Accessibility

  • Badge is presentational text; it does not add a role or live-region behavior.
  • Keep labels short. Badge preserves its complete visible text instead of truncating it.
  • Use meaningful text so state never depends on color or an icon alone.
  • Decorative icons should use aria-hidden="true".
  • Use as="a" for navigation. Badge does not render buttons; use Button for actions.
  • For changing status, place Badge inside an appropriately labelled live region managed by the application.

API Reference

Badge

Forwards remaining attributes and listeners to the rendered element.

PropTypeDefaultDescription
variantBadgeVariant"primary"Selects a semantic or color treatment.
as"span" | "a""span"Changes the rendered element while retaining Badge styling and attributes.

Semantic Variants

VariantPurpose
primaryStrong default label or classification.
secondaryQuiet supporting metadata.
outlineNeutral label on the surrounding surface.
betaPre-release or experimental availability.
infoInformational state.
successSuccessful or ready state.
warningCaution or degraded state.
errorFailed or invalid state.
destructiveDestructive state; retained as the solid red compatibility treatment.

Color Variants

red | orange | green | teal | teal-subtle | blue | purple | neutral

Exports

ExportDescription
BadgePresentational badge with semantic element composition.
BADGE_VARIANTSReadonly map of supported variant names.
BADGE_DEFAULT_VARIANTThe default variant name: primary.
BADGE_DEFAULT_ELEMENTThe default rendered element: span.
isBadgeElementRuntime type guard for span and a element names.
isBadgeVariantRuntime type guard for variant strings.
BadgeVariantUnion of supported variant names.
BadgeElementUnion of the supported span and a element names.
BadgePropsPublic as and variant props.