Badge
Compact counts, statuses and metadata with a standalone component, a hydration-safe arbitrary-anchor directive and native Button integration.
GET STARTED
Import
Import the canonical component and directive from the granular entry point.
Values and numeric caps
Strings and every finite number are valid. max only caps presentation; the uncapped number remains the accessible value.
Semantic severities
Every semantic role follows the active primary, surface and color-mode tokens.
Sizes, dots and projected content
Three presets, optional square geometry, meaningful dots and rich projected content cover compact metadata without a second component.
Live counter
Signal values update directly. Use a polite live region only when the update deserves an announcement.
Arbitrary anchor directive
NeuralBadgeDirective creates the real Badge component on any suitable host after hydration.
Logical positions
Inline start/end participate in layout. Four corner positions overlay the anchor and mirror automatically in RTL.
Visibility and empty values
Zero is content. A directive value of null or undefined removes its generated host; badgeHidden is the explicit component visibility switch.
Unstyled and typed class slots
Structural hooks remain while all NeuralNg visual ownership moves to consumer classes.
Composition boundaries
Standalone
Inline status, count or projected metadata.
Directive
Decoration for arbitrary non-void anchors.
Button API
The shortest contract for action-owned badges.
ACCESSIBILITY
Small visual, complete meaning
Badge never replaces the accessible name of the object it decorates.
Labels and caps
A capped 99+ Badge exposes the real numeric value through its generated aria-label. Set ariaLabel when the number needs context, and keep the anchor's own name complete.
Meaningful dots
A decorative dot needs no announcement. A dot that means online, unread or failed must receive ariaLabel; development mode warns when it is missing.
Live regions
ariaLive="off" is intentionally the default. Prefer polite for user-relevant background counts and reserve assertive for truly urgent changes.
Anchor semantics
The directive does not change role, focus or keyboard behavior. Use a real Button for actions. Wrap void or replaced elements such as img and input before applying the directive.
RTL and logical placement
start and end are logical, not physical. All corner offsets use logical inset properties and follow the document direction without a second API.
PUBLIC API
Badge contract
Canonical symbols are NeuralBadge and NeuralBadgeDirective. Legacy aliases remain deprecated for migration only.
NeuralBadge inputs
| Input | Type | Default | Purpose |
|---|---|---|---|
| value | string | number | null | undefined | null | Visible value; absence projects content. |
| max | number | null | null | Finite non-negative numeric visual cap. |
| severity | NeuralBadgeSeverity | 'neutral' | Semantic color treatment. |
| size | small | medium | large | 'medium' | Preset dimensions and type scale. |
| rounded | boolean | true | Uses pill radius when enabled. |
| dot | boolean | false | Renders a visual dot without value text. |
| badgeHidden | boolean | false | Explicitly hides the component host. |
| ariaLabel | string | null | null/capped value | Accessible label override. |
| ariaLive | off | polite | assertive | 'off' | Live-region announcement mode. |
| unstyled | boolean | false | Removes NeuralNg visual classes. |
| badgeClass | string | '' | Additive root class. |
| classes | NeuralBadgeClasses | {} | Typed additive class slots. |
NeuralBadgeDirective inputs
| Input | Type | Default | Purpose |
|---|---|---|---|
| neuralBadge | string | number | null | undefined | null | Generated Badge value. |
| neuralBadgePosition | NeuralBadgePosition | 'top-end' | Inline or logical-corner placement. |
| neuralBadgeSeverity | NeuralBadgeSeverity | 'neutral' | Generated Badge severity. |
| neuralBadgeSize | NeuralBadgeSize | 'small' | Generated Badge size. |
| neuralBadgeMax | number | null | null | Numeric visual cap. |
| neuralBadgeAriaLabel | string | null | null | Accessible Badge label. |
| neuralBadgeAriaLive | NeuralBadgeAriaLive | 'off' | Live-region behavior. |
| neuralBadgeClass | string | '' | Class for generated Badge root. |
| neuralBadgeHostClass | string | '' | Class for generated host element. |
| neuralBadgeRounded | boolean | true | Rounded generated Badge. |
| neuralBadgeDot | boolean | false | Dot generated Badge. |
| neuralBadgeHidden | boolean | false | Explicitly removes generated host. |
| neuralBadgeUnstyled | boolean | false | Removes generated visual classes. |
Typed class slots
rootvaluecontentPublic types
NeuralBadgeSeverityprimary | secondary | neutral | info | success | warning | error
NeuralBadgeSizesmall | medium | large
NeuralBadgeAriaLiveoff | polite | assertive
NeuralBadgePositionstart | end | top-start | top-end | bottom-start | bottom-end
DESIGN TOKENS
Badge tokens
Neutral responds to runtime primary, surface and mode. Glass and Futuristic override the same contract without changing markup.
Base tokens
--neural-badge-min-widthComponent minimum inline size.
--neural-badge-heightComponent block size.
--neural-badge-paddingComponent internal spacing.
--neural-badge-colorComponent foreground color.
--neural-badge-backgroundComponent background surface.
--neural-badge-borderComponent border shorthand.
--neural-badge-radiusComponent corner radius.
--neural-badge-rounded-radiusRounded corner radius.
--neural-badge-shadowComponent box shadow.
--neural-badge-font-familyComponent font family.
--neural-badge-font-sizeComponent font size.
--neural-badge-font-weightComponent font weight.
--neural-badge-line-heightComponent line height.
--neural-badge-small-min-widthSmall minimum inline size.
--neural-badge-small-heightSmall block size.
--neural-badge-small-paddingSmall internal spacing.
--neural-badge-small-font-sizeSmall font size.
--neural-badge-large-min-widthLarge minimum inline size.
--neural-badge-large-heightLarge block size.
--neural-badge-large-paddingLarge internal spacing.
--neural-badge-large-font-sizeLarge font size.
--neural-badge-dot-sizeDot width and height.
--neural-badge-dot-small-sizeDot small width and height.
--neural-badge-dot-large-sizeDot large width and height.
--neural-badge-content-gapSpacing between content items.
Severity tokens
--neural-badge-primary-colorPrimary severity foreground color.
--neural-badge-primary-backgroundPrimary severity background surface.
--neural-badge-primary-border-colorPrimary severity border color.
--neural-badge-secondary-colorSecondary severity foreground color.
--neural-badge-secondary-backgroundSecondary severity background surface.
--neural-badge-secondary-border-colorSecondary severity border color.
--neural-badge-neutral-colorNeutral severity foreground color.
--neural-badge-neutral-backgroundNeutral severity background surface.
--neural-badge-neutral-border-colorNeutral severity border color.
--neural-badge-info-colorInfo severity foreground color.
--neural-badge-info-backgroundInfo severity background surface.
--neural-badge-info-border-colorInfo severity border color.
--neural-badge-success-colorSuccess severity foreground color.
--neural-badge-success-backgroundSuccess severity background surface.
--neural-badge-success-border-colorSuccess severity border color.
--neural-badge-warning-colorWarning severity foreground color.
--neural-badge-warning-backgroundWarning severity background surface.
--neural-badge-warning-border-colorWarning severity border color.
--neural-badge-error-colorError severity foreground color.
--neural-badge-error-backgroundError severity background surface.
--neural-badge-error-border-colorError severity border color.
Anchor tokens
--neural-badge-anchor-offsetAnchor positional offset.
--neural-badge-anchor-z-indexAnchor stacking order.