Badge

The <smart-badge> component renders a small inline status / label indicator. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract BadgeBaseComponent defines the shared API — text (required), color, size, optional IBadgeOptions, cssClass (alias class), a removed output, and a remove() method that emits removed. BadgeStandardComponent is a barebones placeholder concrete implementation. BadgeComponent is the public wrapper that renders BadgeStandardComponent by default and accepts a custom replacement via BADGE_STANDARD_COMPONENT_TOKEN.


Usage

@if (visible()) {
  <smart-badge
    [text]="text"
    [color]="color"
    size="sm"
    [options]="options"
    (removed)="onRemoved()"
  />
}

The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Components

BadgeComponent (<smart-badge>)

Main wrapper component. Renders BadgeStandardComponent by default. When BADGE_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and passes it every input, class included. Re-emits removed from whichever component it renders.

BadgeStandardComponent (<smart-badge-standard>)

Barebones placeholder concrete implementation. Renders a <span> host with data-color and data-size attributes, an optional leading dot when options.withDot is true, the badge text, and an optional remove button when options.withRemove is true that emits the removed output on click. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.

BadgePresetComponent (<smart-badge-preset>)

Styled variation that extends BadgeBaseComponent and is a drop-in replacement for BadgeStandardComponent. Register it via BADGE_STANDARD_COMPONENT_TOKEN ({ provide: BADGE_STANDARD_COMPONENT_TOKEN, useValue: BadgePresetComponent }) to restyle every <smart-badge>, register every preset at once with provideSmartPresets(), or use the <smart-badge-preset> selector directly. It groups the solid / soft / outline color presets into a single component, selected through options.variant (default 'soft'), across the full SmartBadgeColor palette. Honors options.pill (default true → rounded-full; false → rounded-md), size (sm/md), options.withDot (leading SVG dot), and options.withRemove (remove button emitting removed). All classes are smart:-prefixed Tailwind with explicit dark: variants; the per-variant/color class recipes are internal to the preset (not exported).

Used directly, <smart-badge-preset> takes the extra classes as class or [cssClass]; on <smart-badge> pass class and the wrapper forwards it.

BadgeBaseComponent (abstract)

Abstract base directive for extending custom badge implementations. Exposes text as a required InputSignal<string>, color as an InputSignal<SmartBadgeColor> (default 'gray'), size as an InputSignal<'sm' | 'md'> (default 'md'), options as an InputSignal<IBadgeOptions | undefined>, cssClass as an InputSignal<string> (with alias class), removed as an OutputEmitterRef<void>, and a remove() method that emits the removed output.

API

Inputs

InputTypeDefaultDescription
textInputSignal<string> (required)-Badge label text
colorInputSignal<SmartBadgeColor>'gray'Semantic color of the badge
sizeInputSignal<'sm' | 'md'>'md'Visual size variant
optionsInputSignal<IBadgeOptions | undefined>-Optional configuration (variant, dot, etc.)
classInputSignal<string>''External CSS classes (alias for cssClass)

Outputs

OutputTypeDescription
removedOutputEmitterRef<void>Emits when the user clicks the remove button (with withRemove)

SmartBadgeColor

SmartBadgeColor is 'gray' | 'red' | 'yellow' | 'green' | 'blue' | 'indigo' | 'purple' | 'pink'. The preset styles every colour; the standard exposes it as data-color.

IBadgeOptions

FieldTypeDefaultDescription
variant'solid' | 'soft' | 'outline''soft'Styled by the preset: solid filled with inverse text, soft tinted with same-hue text, outline transparent with a coloured border. The standard does not style it; it exposes it as data-variant.
pillbooleantrueFully rounded pill; false renders rounded-md corners. Styled by the preset; the standard exposes it as data-pill="true" | "false".
withDotbooleanfalseRenders a coloured dot before the text (a • in the standard, an SVG dot in the preset).
withRemovebooleanfalseRenders a remove button that emits removed.

BadgeStandardComponent renders withDot (a leading bullet) and withRemove (a remove button that emits removed). variant and pill are purely visual and styled only by the preset; the standard exposes them as data-variant (default "soft") and data-pill ("true" unless pill === false) on the same root <span> that carries data-color and data-size, so you can target them with plain CSS. BadgePresetComponent styles all of variant, pill, withDot, and withRemove.

BADGE_STANDARD_COMPONENT_TOKEN

InjectionToken that allows replacing the default BadgeStandardComponent with a custom implementation. Provide a Type<BadgeBaseComponent> to override; the wrapper passes it every input it declares, class included, and re-emits its removed.

Extending the base class

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  ViewEncapsulation,
} from '@angular/core';

import {
  BadgeBaseComponent,
  BadgeComponent,
  BADGE_STANDARD_COMPONENT_TOKEN,
  IBadgeOptions,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-badge',
  template: `
    <span [class]="containerClasses()" [attr.data-color]="color()">
      @if (options()?.withDot) {
        <span class="docs-badge__dot" aria-hidden="true">&bull;</span>
      }

      <span class="docs-badge__text">{{ text() }}</span>

      @if (options()?.withRemove) {
        <button
          type="button"
          class="docs-badge__remove"
          aria-label="Remove"
          (click)="remove()"
        >
          &times;
        </button>
      }
    </span>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomBadgeComponent extends BadgeBaseComponent {
  containerClasses = computed(() =>
    [
      'docs-badge',
      `docs-badge--${this.size()}`,
      this.options()?.pill === false ? '' : 'docs-badge--pill',
      this.cssClass(),
    ]
      .filter(Boolean)
      .join(' '),
  );
}

@Component({
  selector: 'docs-badge-custom-example',
  imports: [BadgeComponent],
  providers: [
    {
      provide: BADGE_STANDARD_COMPONENT_TOKEN,
      useValue: CustomBadgeComponent,
    },
  ],
  template: `
    <smart-badge
      text="In review"
      color="yellow"
      size="md"
      [options]="options"
    />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BadgeCustomExampleComponent {
  options: IBadgeOptions = { withDot: true, withRemove: true };
}

Source

The component lives in packages/shared/angular/src/lib/components/badge and is documented for Claude Code by the angular-components-badge skill.

SmartBadge is a small label for a status or a tag: text, a color from the badge palette, two sizes, and options for the variant (solid, soft, outline), pill shape, a leading dot and a remove button reported through onRemoved. SmartBadgeStandard (the default) is unstyled markup exposing color, size, variant and pill as data-* attributes; SmartBadgePreset is the styled look.


Usage

import { useState } from 'react';

import {
  IBadgeOptions,
  SmartBadge,
  SmartBadgeColor,
} from '@smartsoft001/react';

const text = 'Active';
const color: SmartBadgeColor = 'green';

const options: IBadgeOptions = { withDot: true, withRemove: true };

export function BadgeUsageExample() {
  const [visible, setVisible] = useState(true);

  if (!visible) return null;

  return (
    <SmartBadge
      text={text}
      color={color}
      size="sm"
      options={options}
      onRemoved={() => setVisible(false)}
    />
  );
}

The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Exports

All from @smartsoft001/react.

ExportKindWhat it is
SmartBadgecomponentRenders the implementation registered as components.badge on SmartProvider, SmartBadgeStandard by default.
SmartBadgePresetcomponentStyled badge variation (preset).
SmartBadgeStandardcomponentThe default badge rendering: unstyled markup exposing color, size, options.variant and options.pill as data-* attributes for the application's own CSS.
useBadgehookThe behaviour every badge variant shares: remove() reports the click on the remove button through onRemoved.

The preset's class helpers (getBadgeClasses, getDotClasses, getRemoveClasses) and their SmartBadgePresetVariant type ('solid' | 'soft' | 'outline') are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartBadgeProps

PropTypeDefaultDescription
textstringrequiredThe label.
color?SmartBadgeColor'gray'Colour from the badge palette.
size?'sm' | 'md''md'sm or md.
options?IBadgeOptions—Variant, pill shape, dot and remove button.
className?string—Classes on the root element.
onRemoved?() => void—Click on the remove button (options.withRemove).

IBadgeOptions

FieldTypeDefaultDescription
variant?'solid' | 'soft' | 'outline''soft'Visual style variant (default 'soft'). Styled by SmartBadgePreset: • solid — filled background with inverse text • soft — tinted background with same-hue text • outline — transparent background with colored border + text SmartBadgeStandard does not style it; it exposes the value as the data-variant attribute on its root element.
pill?booleantrueFully rounded pill shape (default true); false renders rounded-md corners. Styled by SmartBadgePreset; SmartBadgeStandard exposes it as data-pill="true" | "false" on its root element.
withDot?boolean—Renders a coloured dot before the text.
withRemove?boolean—Renders a remove button that calls onRemoved.
  • SmartBadgeColor: 'gray' \| 'red' \| 'yellow' \| 'green' \| 'blue' \| 'indigo' \| 'purple' \| 'pink' — The colours a badge can take.

Replacing the Implementation

SmartBadge renders the component registered under the 'badge' key of SmartProvider's components, and SmartBadgeStandard when nothing is registered there. Every SmartBadge below the provider then renders the registered component, which receives the same props.

SmartBadgePreset is the styled (preset) implementation: register it under the 'badge' key of SmartProvider's components, render it directly in place of SmartBadge, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.

The useBadge hook

The behaviour every badge variant shares: remove() reports the click on the remove button through onRemoved.

ReturnsTypeDescription
remove() => voidReports the remove click through onRemoved.
import {
  IBadgeOptions,
  SmartBadge,
  SmartBadgeProps,
  SmartProvider,
  useBadge,
} from '@smartsoft001/react';

export function CustomBadge({
  text,
  color = 'gray',
  size = 'md',
  options,
  className,
  onRemoved,
}: SmartBadgeProps) {
  const { remove } = useBadge({ onRemoved });

  const containerClasses = [
    'docs-badge',
    `docs-badge--${size}`,
    options?.pill === false ? '' : 'docs-badge--pill',
    className,
  ]
    .filter(Boolean)
    .join(' ');

  return (
    <span className={containerClasses} data-color={color}>
      {options?.withDot && (
        <span className="docs-badge__dot" aria-hidden="true">
          &bull;
        </span>
      )}

      <span className="docs-badge__text">{text}</span>

      {options?.withRemove && (
        <button
          type="button"
          className="docs-badge__remove"
          aria-label="Remove"
          onClick={remove}
        >
          &times;
        </button>
      )}
    </span>
  );
}

// A module constant: a new object on every render would change the context.
const components = { badge: CustomBadge };

const options: IBadgeOptions = { withDot: true, withRemove: true };

export function BadgeCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartBadge text="In review" color="yellow" size="md" options={options} />
    </SmartProvider>
  );
}

Styling

  • SmartBadgeStandard carries no visual styling: style data-color, data-size, data-variant and data-pill with your own CSS.
  • SmartBadgePreset styles the three variants across the SmartBadgeColor palette, with smart:dark: variants.

Source

The component lives in packages/shared/react/src/lib/components/badge and is documented for Claude Code by the react-components-badge skill.