ComponentUpdated in v15

Badge

A small label for a count or a status.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrBadge, WrTag } from 'ngwr/badge';

@Component({ imports: [WrBadge, WrTag] })
export class MyComponent {}

Basic usage

New
<wr-badge>New</wr-badge>

Colors

primarysuccesswarningdangerinfo
<wr-badge color="primary">Primary</wr-badge>
<wr-badge color="success">Success</wr-badge>

Sizes

121212
<wr-badge size="sm">12</wr-badge>
<wr-badge size="md">12</wr-badge>
<wr-badge size="lg">12</wr-badge>

Shape

shape is rounded (default), pill or squircle.

rounded
primarysuccesswarningdangerinfo
pill
primarysuccesswarningdangerinfo
squircle
primarysuccesswarningdangerinfo
<wr-badge color="primary">Beta</wr-badge>
<wr-badge color="primary" shape="pill">Beta</wr-badge>
<wr-badge color="primary" shape="squircle">Beta</wr-badge>

Outlined

outlined drops the fill and keeps a coloured ring.

primarysuccesswarningdangerinfo
<wr-badge color="primary" outlined>Beta</wr-badge>

Tag

<wr-tag>, also from ngwr/badge, adds icon, loading and transparent.

<wr-tag color="success" icon="checkmark">Done</wr-tag>
<wr-tag color="primary" outlined rounded>Beta</wr-tag>
<wr-tag color="warning" loading>Saving</wr-tag>
DoneBetaSaving

Colour is not a label

Write the state in the label (Failed, not a red Build), and give a status tag an icon you register.

import { CircleCheck, OctagonAlert } from 'lucide';
import { lucideIcons, provideWrIcons } from 'ngwr/icon';

@Component({
  providers: [provideWrIcons(lucideIcons({ 'circle-check': CircleCheck, 'octagon-alert': OctagonAlert }))],
})
export class BuildStatus {}
PassedFailedDegraded
<wr-tag color="success" icon="circle-check">Passed</wr-tag>
<wr-tag color="danger" icon="octagon-alert">Failed</wr-tag>
<wr-badge color="warning">Degraded</wr-badge>

API

Inputs of <wr-badge>.

NameDescriptionTypeDefault
colorColor variant. Maps to --wr-color-* CSS variables from the theme. It is decoration or category, never the state on its own: four of the five intents share one lightness and success against danger is 1.004:1, so the label has to say the state (Offline, not a red Status). A badge draws no icon — when a chip must stand for a status without words, use <wr-tag> with its icon input.WrColor | null'primary'
sizeSize variant.WrBadgeSize'md'
shapeCorner treatment. Mirrors <wr-btn> — rounded (default) uses the small form-radius; pill rounds the ends fully.WrBadgeShape'rounded'
outlinedOutlined style — transparent fill, colored border and text.booleanfalse

Tag API

Inputs of <wr-tag>.

NameDescriptionTypeDefault
colorIntent colour. null is neutral gray.WrColor | null'primary'
iconIcon beside the label.WrIconName | nullnull
iconPositionWhich side the icon sits on.'start' | 'end''start'
outlinedColoured text and ring on a light tint.booleanfalse
transparentColoured text on a low-opacity tint, no border.booleanfalse
roundedPill radius instead of the default.booleanfalse
hoverableAdd a hover affordance.booleanfalse
loadingSwap the icon for a spinner.booleanfalse

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/badge's own element.

VariableDefaultDeclared on
--wr-badge-bgvar(--wr-color-fill).wr-badge +2 variant overrides
--wr-badge-bordervar(--wr-border-base).wr-badge +1 variant override
--wr-badge-colorvar(--wr-color-on-surface).wr-badge +2 variant overrides
--wr-badge-font-sizevar(--wr-text-xs).wr-badge +2 variant overrides
--wr-badge-font-weight600.wr-badge
--wr-badge-min-height1.5rem.wr-badge +2 variant overrides
--wr-badge-padding-xvar(--wr-space-sm).wr-badge +3 variant overrides
--wr-badge-padding-yvar(--wr-space-xs).wr-badge +2 variant overrides
--wr-badge-radiusvar(--wr-border-radius-sm).wr-badge +1 variant override
--wr-tag-bgvar(--wr-color-fill).wr-tag +3 variant overrides
--wr-tag-bordervar(--wr-border-base).wr-tag +3 variant overrides
--wr-tag-colorvar(--wr-color-on-surface).wr-tag +3 variant overrides
--wr-tag-font-familyvar(--wr-font-family-base).wr-tag
--wr-tag-font-sizevar(--wr-text-xs).wr-tag
--wr-tag-font-weightvar(--wr-font-weight-medium).wr-tag
--wr-tag-gapvar(--wr-space-xs).wr-tag
--wr-tag-line-heightnormal.wr-tag
--wr-tag-min-height1.375rem.wr-tag
--wr-tag-padding-xvar(--wr-space-sm).wr-tag +1 variant override
--wr-tag-padding-y0.125rem.wr-tag
--wr-tag-radiusvar(--wr-border-radius-sm).wr-tag +1 variant override

Dependencies

Built onIcon, Spinner

See also