• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-webcomponents / 18867307154

28 Oct 2025 07:26AM UTC coverage: 98.135% (-0.001%) from 98.136%
18867307154

Pull #1889

github

web-flow
Merge c277148ad into c96cf90a5
Pull Request #1889: feat(badge): design enhancement

5302 of 5582 branches covered (94.98%)

Branch coverage included in aggregate %.

24 of 25 new or added lines in 1 file covered. (96.0%)

35310 of 35802 relevant lines covered (98.63%)

1641.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.2
/src/components/badge/badge.ts
1
import { html, LitElement, type PropertyValues } from 'lit';
10✔
2
import { property } from 'lit/decorators.js';
10✔
3
import { addThemingController } from '../../theming/theming-controller.js';
10✔
4
import { addInternalsController } from '../common/controllers/internals.js';
10✔
5
import { addSlotController } from '../common/controllers/slot.js';
10✔
6
import { registerComponent } from '../common/definitions/register.js';
10✔
7
import { partMap } from '../common/part-map.js';
10✔
8
import type { BadgeShape, StyleVariant } from '../types.js';
10✔
9
import { styles } from './themes/badge.base.css.js';
10✔
10
import { styles as shared } from './themes/shared/badge.common.css.js';
10✔
11
import { all } from './themes/themes.js';
10✔
12

10✔
13
/**
10✔
14
 * The badge is a component indicating a status on a related item or an area
10✔
15
 * where some active indication is required.
10✔
16
 *
10✔
17
 * @element igc-badge
10✔
18
 *
10✔
19
 * @slot - Default slot for the badge.
10✔
20
 *
10✔
21
 * @csspart base - The base wrapper of the badge.
10✔
22
 */
10✔
23
export default class IgcBadgeComponent extends LitElement {
10✔
24
  public static readonly tagName = 'igc-badge';
10✔
25
  public static override styles = [styles, shared];
10✔
26

10✔
27
  /* blazorSuppress */
10✔
28
  public static register(): void {
10✔
29
    registerComponent(IgcBadgeComponent);
1✔
30
  }
1✔
31

10✔
32
  private _iconPart = false;
10✔
33

10✔
34
  private readonly _slots = addSlotController(this, {
10✔
35
    onChange: this._handleSlotChange,
10✔
36
  });
10✔
37

10✔
38
  protected _handleSlotChange(): void {
10✔
39
    const assignedNodes = this._slots.getAssignedNodes('[default]', true);
1✔
40
    this._iconPart = assignedNodes.some(
1✔
41
      (node) =>
1✔
42
        node.nodeType === Node.ELEMENT_NODE &&
1!
NEW
43
        (node as Element).tagName.toLowerCase() === 'igc-icon'
×
44
    );
1✔
45
  }
1✔
46

10✔
47
  private readonly _internals = addInternalsController(this, {
10✔
48
    initialARIA: { role: 'status' },
10✔
49
  });
10✔
50

10✔
51
  /**
10✔
52
   * The type of badge.
10✔
53
   * @attr
10✔
54
   */
10✔
55
  @property({ reflect: true })
10✔
56
  public variant: StyleVariant = 'primary';
10✔
57

10✔
58
  /**
10✔
59
   * Sets whether to draw an outlined version of the badge.
10✔
60
   * @attr
10✔
61
   */
10✔
62
  @property({ type: Boolean, reflect: true })
10✔
63
  public outlined = false;
10✔
64

10✔
65
  /**
10✔
66
   * The shape of the badge.
10✔
67
   * @attr
10✔
68
   */
10✔
69
  @property({ reflect: true })
10✔
70
  public shape: BadgeShape = 'rounded';
10✔
71

10✔
72
  /**
10✔
73
   * Sets whether to render a dot type badge.
10✔
74
   * @attr
10✔
75
   */
10✔
76
  @property({ type: Boolean, reflect: true })
10✔
77
  public dot = false;
10✔
78

10✔
79
  constructor() {
10✔
80
    super();
18✔
81
    addThemingController(this, all);
18✔
82
  }
18✔
83

10✔
84
  protected override willUpdate(changedProperties: PropertyValues<this>): void {
10✔
85
    if (changedProperties.has('variant')) {
13✔
86
      this._internals.setARIA({ ariaRoleDescription: `badge ${this.variant}` });
9✔
87
    }
9✔
88
  }
13✔
89

10✔
90
  protected override render() {
10✔
91
    return html`
13✔
92
      <span part=${partMap({ base: true, icon: this._iconPart })}>
13✔
93
        <slot></slot>
13✔
94
      </span>
13✔
95
    `;
13✔
96
  }
13✔
97
}
10✔
98

10✔
99
declare global {
10✔
100
  interface HTMLElementTagNameMap {
10✔
101
    'igc-badge': IgcBadgeComponent;
10✔
102
  }
10✔
103
}
10✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc