Badge
@codeui/solid v0.3.0
A short, non-interactive status label.
When to use
Use Badge for a snippet state, export format, or short count beside content.
When to choose another component
Use Button for an action. Use Alert for a message with an explanation or recovery action.
Live demo
import { Badge } from "@codeui/solid";
export default function BadgeBasic() {
return (
<>
<Badge>Draft</Badge>
<Badge tone="success">Exported</Badge>
<Badge tone="danger" variant="outline">
Failed
</Badge>
</>
);
}Anatomy
Tap a part to outline it in the demo.
- 01Icon
badge-iconclasses.icon - 02Label
badge-labelclasses.label - 03Root
badgeclasses.root
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Icon | span | icon | badge-icon | None |
Label | span | label | badge-label | None |
Root | span | root | badge | status |
Variants
Tones
import { Badge, Stack } from "@codeui/solid";
export default function Demo() {
return (
<Stack direction="row" gap="2">
<Badge tone="neutral">Draft</Badge>
<Badge tone="info">New</Badge>
<Badge tone="success">Exported</Badge>
<Badge tone="warning">Unsaved</Badge>
<Badge tone="danger">Failed</Badge>
</Stack>
);
}The tones are neutral, info, success, warning, and danger. Text carries the status as well as color.
Sizes
import { Badge, Stack } from "@codeui/solid";
export default function Demo() {
return (
<Stack direction="row" gap="2">
<Badge size="sm">Draft</Badge>
<Badge size="md">Draft</Badge>
</Stack>
);
}sm is the default. md gives the label more height and space.
Variants
import { Badge, Stack } from "@codeui/solid";
export default function Demo() {
return (
<Stack direction="row" gap="2">
<Badge variant="soft">Draft</Badge>
<Badge variant="outline">Draft</Badge>
</Stack>
);
}soft is the default tinted fill. outline uses a transparent fill and a status border.
Ready API
Badge
Badge renders Root with an optional Icon and a Label. BadgeProps adds JSX icon and classes to the root props.
Prop
Type
Inherited behavior from Kobalte badge.
Prop
Type
Styled parts API
Import the parts from @codeui/solid/badge/parts. The root wraps Kobalte badge.
Icon
Decorative icon wrapper. It sets aria-hidden="true".
Prop
Type
Label
Text wrapper with overflow clipping and an ellipsis.
Prop
Type
Root
Styled Kobalte Badge root. It accepts tone, size, and variant.
Prop
Type
Prop
Type
Styles export
badgeStyles
Call badgeStyles.root(), icon(), and label() for the part classes. BadgeStyles types these helpers.
In CSS-only markup, use cui-badge with data-size, data-tone, and data-variant. For example, data-size="sm" data-tone="info" data-variant="outline" selects the small info badge with an outline.
Accessibility
Keyboard
Badge is non-interactive and has no keyboard commands. It does not add a tab stop.
ARIA
Kobalte renders a non-interactive span with role="status", which has implicit polite live-region semantics. Changes can be announced. Icon is hidden from assistive technology. textValue supplies a plain text alternative when the label contains rich content.
Focus
Mounting or removing the component does not move focus. There is no open or close focus cycle. The containing control or application owns focus.
SSR notes
The component renders inline on the server. It has no portal or client-only effect. Use the same initial props on the server and client. No request-shared state is created by the kit wrapper.
Theming hooks
The component reads these theme variables.
--cui-action-brand-base--cui-action-brand-soft-base--cui-action-brand-soft-text--cui-action-caution-base--cui-action-caution-text--cui-action-danger-base--cui-action-danger-text--cui-action-neutral-active--cui-action-neutral-base--cui-action-success-base--cui-action-success-text--cui-border-width--cui-font-family-sans--cui-font-line-height-compact--cui-font-size-badge--cui-font-size-xs--cui-font-weight-normal--cui-from-entries--cui-keys--cui-radius-badge--cui-space-px--cui-space-0-5--cui-space-1--cui-space-1-5--cui-space-2--cui-space-4--cui-space-5--cui-text-danger--cui-text-default--cui-text-panel-muted
Defaults come from the kit theme. See Color, Typography, Space and shape, and Motion.
Composition examples
import { Badge, icons, Stack } from "@codeui/solid";
export default function Demo() {
return (
<Stack direction="row" gap="2">
<Badge tone="success" icon={<icons.CheckIcon />}>
Exported
</Badge>
<Badge textValue="3 PNG exports">
<strong>3</strong> PNG exports
</Badge>
</Stack>
);
}The icon is decorative. The rich label supplies textValue so its accessible text does not depend on markup.
Related
Use Button for an action. Use Alert for a message with an explanation or recovery action.