Badge
Badge adds short status, count, or classification markers around nearby content.
@duskmoon-dev/components/badge Usage
When to use
- Use it to clarify state, metadata, content hierarchy, or loading without creating a new workflow.
- Pair it with semantic content so visual treatment never becomes the only source of meaning.
Implementation notes
Features
Focuses on status, metadata, empty/loading states, or content grouping without owning application state.
Uses DuskMoon tokens so the component follows the active docs theme.
Badge is most often configured through `color`, `appearance`, `size`.
Renders children correctly
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Colors
Badge supports the full semantic color palette: primary, secondary, tertiary, accent, neutral, base, info, success, warning, error.
import "@duskmoon-dev/components/styles.css";
import { Badge } from "@duskmoon-dev/components/badge";
const colors = [
"primary",
"secondary",
"tertiary",
"accent",
"neutral",
"base",
"info",
"success",
"warning",
"error"
] as const;
export function BadgeColorsDemo() {
return (<div style={{ display: "grid", gap: 12 }}>
{(["filled", "outline", "tonal", "ghost"] as const).map((appearance) => (
<div key={appearance} style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
{colors.map((color) => (
<Badge key={color} color={color} appearance={appearance}>
{color}
</Badge>
))}
</div>
))}
</div>);
} Basic usage
Import the component stylesheet and Badge from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Badge } from "@duskmoon-dev/components/badge";
export function Example() {
return (<Badge
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>);
} Renders children correctly
test-backedBadge scenario from the component test coverage: renders children correctly.
import "@duskmoon-dev/components/styles.css";
import { Badge } from "@duskmoon-dev/components/badge";
export function BadgeRendersChildrenCorrectlyDemo() {
return (<Badge
// Renders children correctly
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>);
} Applies default classes
test-backedBadge scenario from the component test coverage: applies default classes.
import "@duskmoon-dev/components/styles.css";
import { Badge } from "@duskmoon-dev/components/badge";
export function BadgeAppliesDefaultClassesDemo() {
return (<Badge
// Applies default classes
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>);
} Applies color, appearance, and size classes
test-backedBadge scenario from the component test coverage: applies color, appearance, and size classes.
import "@duskmoon-dev/components/styles.css";
import { Badge } from "@duskmoon-dev/components/badge";
export function BadgeAppliesColorAppearanceAndDemo() {
return (<Badge
// Applies color, appearance, and size classes
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>);
} Applies custom className
test-backedBadge scenario from the component test coverage: applies custom classname.
import "@duskmoon-dev/components/styles.css";
import { Badge } from "@duskmoon-dev/components/badge";
export function BadgeAppliesCustomClassNameDemo() {
return (<Badge
// Applies custom className
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Badge
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>
</div>
<div data-theme="moonlight">
<Badge
color="primary"
appearance="tonal"
>
DuskMoon Badge
</Badge>
</div> API
The API reference below lists every parsed exported type or interface for Badge. Start with `color`, `appearance`, `size` for common usage.
packages/components/src/components/badge/Badge.types.ts
Scenarios: packages/components/src/components/badge/Badge.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
color | BadgeColor | No | color configures Badge. |
appearance | BadgeAppearance | No | appearance configures Badge. |
size | BadgeSize | No | size configures Badge. |
| "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error" "filled" | "outline" | "tonal" | "ghost" "sm" | "md" | "lg"