@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.5 → 2.2.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +542 -6
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +539 -7
  4. package/dist/components/alert-button-item/alert-button-item.css.js +65 -1
  5. package/dist/components/alert-button-item/alert-button-item.css.js.map +1 -1
  6. package/dist/components/alert-button-item/alert-button-item.d.ts +14 -1
  7. package/dist/components/alert-button-item/alert-button-item.d.ts.map +1 -1
  8. package/dist/components/alert-button-item/alert-button-item.js +19 -2
  9. package/dist/components/alert-button-item/alert-button-item.js.map +1 -1
  10. package/dist/components/alert-subsystem-button/alert-subsystem-button.css.js +120 -0
  11. package/dist/components/alert-subsystem-button/alert-subsystem-button.css.js.map +1 -0
  12. package/dist/components/alert-subsystem-button/alert-subsystem-button.d.ts +101 -0
  13. package/dist/components/alert-subsystem-button/alert-subsystem-button.d.ts.map +1 -0
  14. package/dist/components/alert-subsystem-button/alert-subsystem-button.js +107 -0
  15. package/dist/components/alert-subsystem-button/alert-subsystem-button.js.map +1 -0
  16. package/dist/components/alert-subsystem-counter/alert-subsystem-counter.css.js +4 -0
  17. package/dist/components/alert-subsystem-counter/alert-subsystem-counter.css.js.map +1 -1
  18. package/dist/components/alert-subsystem-counter/alert-subsystem-counter.d.ts +3 -1
  19. package/dist/components/alert-subsystem-counter/alert-subsystem-counter.d.ts.map +1 -1
  20. package/dist/components/alert-subsystem-counter/alert-subsystem-counter.js +7 -1
  21. package/dist/components/alert-subsystem-counter/alert-subsystem-counter.js.map +1 -1
  22. package/dist/components/diagnostic-button/diagnostic-button.css.js +18 -0
  23. package/dist/components/diagnostic-button/diagnostic-button.css.js.map +1 -0
  24. package/dist/components/diagnostic-button/diagnostic-button.d.ts +71 -0
  25. package/dist/components/diagnostic-button/diagnostic-button.d.ts.map +1 -0
  26. package/dist/components/diagnostic-button/diagnostic-button.js +52 -0
  27. package/dist/components/diagnostic-button/diagnostic-button.js.map +1 -0
  28. package/dist/components/diagnostic-menu/diagnostic-menu.css.js +109 -0
  29. package/dist/components/diagnostic-menu/diagnostic-menu.css.js.map +1 -0
  30. package/dist/components/diagnostic-menu/diagnostic-menu.d.ts +103 -0
  31. package/dist/components/diagnostic-menu/diagnostic-menu.d.ts.map +1 -0
  32. package/dist/components/diagnostic-menu/diagnostic-menu.js +90 -0
  33. package/dist/components/diagnostic-menu/diagnostic-menu.js.map +1 -0
  34. package/dist/components/icon-button/icon-button.js +2 -2
  35. package/dist/components/icon-button/icon-button.js.map +1 -1
  36. package/dist/components/top-bar/top-bar.css.js +1 -0
  37. package/dist/components/top-bar/top-bar.css.js.map +1 -1
  38. package/dist/components/top-bar/top-bar.d.ts +4 -0
  39. package/dist/components/top-bar/top-bar.d.ts.map +1 -1
  40. package/dist/components/top-bar/top-bar.js +1 -0
  41. package/dist/components/top-bar/top-bar.js.map +1 -1
  42. package/dist/generated/locales/es-419.d.ts +6 -0
  43. package/dist/generated/locales/es-419.d.ts.map +1 -1
  44. package/dist/generated/locales/es-419.js +6 -0
  45. package/dist/generated/locales/es-419.js.map +1 -1
  46. package/dist/generated/locales/fi-FI.d.ts +6 -0
  47. package/dist/generated/locales/fi-FI.d.ts.map +1 -1
  48. package/dist/generated/locales/fi-FI.js +6 -0
  49. package/dist/generated/locales/fi-FI.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/components/alert-button-item/alert-button-item.css +13 -1
  52. package/src/components/alert-button-item/alert-button-item.spec.ts +69 -0
  53. package/src/components/alert-button-item/alert-button-item.stories.ts +13 -0
  54. package/src/components/alert-button-item/alert-button-item.ts +32 -2
  55. package/src/components/alert-subsystem-button/alert-subsystem-button.css +42 -0
  56. package/src/components/alert-subsystem-button/alert-subsystem-button.spec.ts +142 -0
  57. package/src/components/alert-subsystem-button/alert-subsystem-button.stories.ts +69 -0
  58. package/src/components/alert-subsystem-button/alert-subsystem-button.ts +168 -0
  59. package/src/components/alert-subsystem-counter/alert-subsystem-counter.css +4 -0
  60. package/src/components/alert-subsystem-counter/alert-subsystem-counter.ts +10 -2
  61. package/src/components/diagnostic-button/diagnostic-button.css +7 -0
  62. package/src/components/diagnostic-button/diagnostic-button.spec.ts +80 -0
  63. package/src/components/diagnostic-button/diagnostic-button.stories.ts +30 -0
  64. package/src/components/diagnostic-button/diagnostic-button.ts +100 -0
  65. package/src/components/diagnostic-menu/diagnostic-menu.css +69 -0
  66. package/src/components/diagnostic-menu/diagnostic-menu.spec.ts +114 -0
  67. package/src/components/diagnostic-menu/diagnostic-menu.stories.ts +135 -0
  68. package/src/components/diagnostic-menu/diagnostic-menu.ts +171 -0
  69. package/src/components/icon-button/icon-button.stories.ts +51 -1
  70. package/src/components/icon-button/icon-button.ts +2 -2
  71. package/src/components/top-bar/top-bar-diagnostics.spec.ts +59 -0
  72. package/src/components/top-bar/top-bar.css +1 -0
  73. package/src/components/top-bar/top-bar.stories.ts +58 -0
  74. package/src/components/top-bar/top-bar.ts +5 -0
  75. package/src/generated/locales/es-419.ts +6 -0
  76. package/src/generated/locales/fi-FI.ts +6 -0
@@ -24,7 +24,8 @@
24
24
  }
25
25
  }
26
26
 
27
- .icon {
27
+ .icon,
28
+ ::slotted([slot="icon"]) {
28
29
  display: block;
29
30
  width: var(--app-components-alert-button-item-icon-size);
30
31
  height: var(--app-components-alert-button-item-icon-size);
@@ -175,6 +176,17 @@
175
176
  }
176
177
  }
177
178
 
179
+ /* After the type rules, which it ties on specificity. Not named .activated:
180
+ the mixin's own activated state would match twice, and the selected style
181
+ has no tokens for it. */
182
+ .alert-button.selected {
183
+ @mixin style style=selected visibleWrapperClass=.visible-wrapper;
184
+
185
+ & .visible-wrapper {
186
+ color: var(--on-selected-active-color);
187
+ }
188
+ }
189
+
178
190
  .flash-fast {
179
191
  & .visible-wrapper {
180
192
  opacity: var(--flash-fast-on);
@@ -2,7 +2,9 @@ import {describe, expect, it} from 'vitest';
2
2
  import {render} from 'vitest-browser-lit';
3
3
  import {userEvent} from '@vitest/browser/context';
4
4
  import {html} from 'lit';
5
+ import '../../main.css';
5
6
  import './alert-button-item.js';
7
+ import '../../icons/icon-placeholder.js';
6
8
  import {ObcAlertButtonItem, ObcAlertButtonType} from './alert-button-item.js';
7
9
  import {
8
10
  ObcAlertCounterItemType,
@@ -314,6 +316,28 @@ describe('obc-alert-button-item accessibility', () => {
314
316
  expect(button(el).getAttribute('aria-label')).toBe('Engine alerts');
315
317
  });
316
318
 
319
+ it('forwards aria-expanded to the inner button, absent until set', async () => {
320
+ const el = await setup();
321
+ expect(button(el).hasAttribute('aria-expanded')).toBe(false);
322
+
323
+ el.setAttribute('aria-expanded', 'true');
324
+ await el.updateComplete;
325
+ expect(button(el).getAttribute('aria-expanded')).toBe('true');
326
+
327
+ el.ariaExpanded = 'false';
328
+ await el.updateComplete;
329
+ expect(button(el).getAttribute('aria-expanded')).toBe('false');
330
+ });
331
+
332
+ it('forwards only the true and false tokens of aria-expanded', async () => {
333
+ const el = await setup();
334
+ for (const value of ['undefined', '', 'yes']) {
335
+ el.setAttribute('aria-expanded', value);
336
+ await el.updateComplete;
337
+ expect(button(el).hasAttribute('aria-expanded'), value).toBe(false);
338
+ }
339
+ });
340
+
317
341
  it('activates with Enter and Space', async () => {
318
342
  const el = await setup();
319
343
  let clicks = 0;
@@ -342,3 +366,48 @@ describe('obc-alert-button-item announcement', () => {
342
366
  expect(region?.textContent?.trim()).toBe('Alerts, 4, Alarm');
343
367
  });
344
368
  });
369
+
370
+ describe('obc-alert-button-item icon slot and activated', () => {
371
+ it('a slotted icon replaces the bell and never flashes', async () => {
372
+ const screen = render(
373
+ html`<obc-alert-button-item
374
+ .alertType=${AlertType.Alarm}
375
+ .nAlerts=${3}
376
+ counter
377
+ blinking
378
+ ><obi-placeholder slot="icon"></obi-placeholder
379
+ ></obc-alert-button-item>`
380
+ );
381
+ const el = screen.container.querySelector(
382
+ 'obc-alert-button-item'
383
+ ) as ObcAlertButtonItem;
384
+ await el.updateComplete;
385
+ const slot =
386
+ el.shadowRoot!.querySelector<HTMLSlotElement>('slot[name="icon"]')!;
387
+
388
+ expect(slot.assignedElements().map((e) => e.tagName)).toEqual([
389
+ 'OBI-PLACEHOLDER',
390
+ ]);
391
+ expect(durations(el)).toEqual([]);
392
+ expect(el.shadowRoot!.querySelector('.blink')).toBeNull();
393
+ });
394
+
395
+ it('activated draws the selected style', async () => {
396
+ const el = await setup();
397
+ el.activated = true;
398
+ await el.updateComplete;
399
+ const probe = document.createElement('div');
400
+ probe.style.backgroundColor = 'var(--selected-enabled-background-color)';
401
+ document.body.append(probe);
402
+ const wrapper = el.shadowRoot!.querySelector('.visible-wrapper')!;
403
+
404
+ expect(button(el).classList.contains('selected')).toBe(true);
405
+ expect(getComputedStyle(probe).backgroundColor).not.toBe(
406
+ 'rgba(0, 0, 0, 0)'
407
+ );
408
+ expect(getComputedStyle(wrapper).backgroundColor).toBe(
409
+ getComputedStyle(probe).backgroundColor
410
+ );
411
+ probe.remove();
412
+ });
413
+ });
@@ -4,6 +4,7 @@ import {ObcAlertButtonItem, ObcAlertButtonType} from './alert-button-item.js';
4
4
  import './alert-button-item.js';
5
5
  import {ObcAlertCounterItemType} from '../alert-counter-item/alert-counter-item.js';
6
6
  import {AlertType, FlashingSpeed, type AlertCounts} from '../../types.js';
7
+ import '../../icons/icon-placeholder.js';
7
8
 
8
9
  type ItemArgs = Pick<
9
10
  ObcAlertButtonItem,
@@ -18,6 +19,7 @@ type ItemArgs = Pick<
18
19
  | 'blinking'
19
20
  | 'flashingSpeed'
20
21
  | 'fillHeight'
22
+ | 'activated'
21
23
  >;
22
24
 
23
25
  const SEVERITY_COUNTS: AlertCounts = {
@@ -43,6 +45,7 @@ const renderItem = (args: Partial<ItemArgs>) =>
43
45
  .blinking=${args.blinking ?? false}
44
46
  .flashingSpeed=${args.flashingSpeed ?? FlashingSpeed.Default}
45
47
  .fillHeight=${args.fillHeight ?? false}
48
+ .activated=${args.activated ?? false}
46
49
  ></obc-alert-button-item>`;
47
50
 
48
51
  const meta: Meta<ItemArgs> = {
@@ -204,3 +207,13 @@ export const FillHeight: Story = {
204
207
  })}
205
208
  </div>`,
206
209
  };
210
+
211
+ export const Activated: Story = {args: {activated: true}};
212
+
213
+ /** The slot takes any icon; the item then never flashes. */
214
+ export const SlottedIcon: Story = {
215
+ render: () =>
216
+ html`<obc-alert-button-item nAlerts="3" counter
217
+ ><obi-placeholder slot="icon"></obi-placeholder
218
+ ></obc-alert-button-item>`,
219
+ };
@@ -1,6 +1,7 @@
1
- import {LitElement, html, nothing, unsafeCSS} from 'lit';
1
+ import {LitElement, PropertyValues, html, nothing, unsafeCSS} from 'lit';
2
2
  import {property} from 'lit/decorators.js';
3
3
  import {classMap} from 'lit/directives/class-map.js';
4
+ import {ifDefined} from 'lit/directives/if-defined.js';
4
5
  import {localized, msg} from '@lit/localize';
5
6
  import componentStyle from './alert-button-item.css?inline';
6
7
  import {customElement} from '../../decorator.js';
@@ -66,6 +67,10 @@ export enum ObcAlertButtonType {
66
67
  * resolves (#1224).
67
68
  * - **Fill height:** `fillHeight` stretches the visible button to the host
68
69
  * height, as the tall `obc-alert-button` does.
70
+ * - **Icon slot:** the `icon` slot replaces the bell with any icon; the item
71
+ * then never flashes.
72
+ * - **Activated:** `activated` draws the selected style, for a button whose
73
+ * panel is showing.
69
74
  *
70
75
  * ---
71
76
  *
@@ -116,7 +121,10 @@ export enum ObcAlertButtonType {
116
121
  * @property flashingSpeed - Flash tempo while `blinking` is on: `default` resolves from `alertType`, `fast`, `slow`, `very-slow` force a tempo, `fixed` never flashes.
117
122
  * @availableWhen flashingSpeed blinking==true
118
123
  * @property fillHeight - Stretches the visible button to the host height instead of the 32 px visual target.
124
+ * @property activated - Draws the button in the selected style, for a button whose panel is showing.
119
125
  * @property ariaLabel - Accessible name forwarded to the inner `<button>`, mapped to the `aria-label` attribute; replaces the generated label. `aria-labelledby` is not supported: ID references cannot cross the shadow boundary.
126
+ * @property ariaExpanded - Whether the panel the button opens is showing, forwarded to the inner `<button>` as `aria-expanded`; mapped to the `aria-expanded` attribute. Set it with `activated` from the flag that drives the panel; left unset, the button announces no panel.
127
+ * @slot icon - Replaces the bell. The flash cross-fades two bells, so a slotted icon never flashes and `blinking` has no effect while the slot is filled.
120
128
  * @fires click - Fired when the button is clicked.
121
129
  * @experimental
122
130
  */
@@ -137,11 +145,24 @@ export class ObcAlertButtonItem extends LitElement {
137
145
  @property({type: String}) flashingSpeed: FlashingSpeed =
138
146
  FlashingSpeed.Default;
139
147
  @property({type: Boolean}) fillHeight = false;
148
+ @property({type: Boolean}) activated = false;
140
149
 
141
150
  // Reactive so a consumer changing the name re-renders the shadow button.
142
151
  @property({type: String, attribute: 'aria-label'})
143
152
  override ariaLabel: string | null = null;
144
153
 
154
+ @property({type: String, attribute: 'aria-expanded'})
155
+ override ariaExpanded: string | null = null;
156
+
157
+ private hasSlottedIcon = false;
158
+
159
+ protected override willUpdate(changedProperties: PropertyValues<this>) {
160
+ super.willUpdate(changedProperties);
161
+ // Read before the first paint, so the flash is never installed for an
162
+ // icon that replaces the bell; the slot's change event re-runs it.
163
+ this.hasSlottedIcon = this.querySelector(':scope > [slot="icon"]') !== null;
164
+ }
165
+
145
166
  protected readonly flashing = new FlashingController(
146
167
  this,
147
168
  () => this.resolvedFlashingSpeed
@@ -150,6 +171,7 @@ export class ObcAlertButtonItem extends LitElement {
150
171
  get resolvedFlashingSpeed(): ResolvedFlashingSpeed {
151
172
  if (
152
173
  this.globalCounter ||
174
+ this.hasSlottedIcon ||
153
175
  !this.blinking ||
154
176
  this.nAlerts <= 0 ||
155
177
  this.alertType === undefined
@@ -264,9 +286,15 @@ export class ObcAlertButtonItem extends LitElement {
264
286
  counter: showCount && !this.globalCounter,
265
287
  'global-counter': this.globalCounter,
266
288
  'fill-height': this.fillHeight,
289
+ selected: this.activated,
267
290
  [`flash-${tempo}`]: true,
268
291
  })}
269
292
  aria-label=${this.accessibleName}
293
+ aria-expanded=${ifDefined(
294
+ this.ariaExpanded === 'true' || this.ariaExpanded === 'false'
295
+ ? this.ariaExpanded
296
+ : undefined
297
+ )}
270
298
  >
271
299
  ${
272
300
  tempo === FlashingSpeed.Fixed
@@ -281,7 +309,9 @@ export class ObcAlertButtonItem extends LitElement {
281
309
  <div class="visible-wrapper">
282
310
  ${this.globalCounter ? this.renderCounts() : nothing}
283
311
  <div class="content">
284
- ${this.renderIcon(styleType, false)}
312
+ <slot name="icon" @slotchange=${() => this.requestUpdate()}
313
+ >${this.renderIcon(styleType, false)}</slot
314
+ >
285
315
  ${showCount ? this.renderCount() : nothing}
286
316
  </div>
287
317
  </div>
@@ -0,0 +1,42 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+
5
+ :host {
6
+ display: inline-flex;
7
+ }
8
+
9
+ .wrapper {
10
+ display: flex;
11
+ align-items: stretch;
12
+ }
13
+
14
+ .counter-button {
15
+ appearance: none;
16
+ background: none;
17
+ border: none;
18
+ padding: 0;
19
+ display: flex;
20
+ align-items: center;
21
+ height: var(--ui-components-button-touch-target-size);
22
+ color: var(--on-normal-neutral-color);
23
+ @mixin style style=normal visibleWrapperClass=.visible-wrapper;
24
+ }
25
+
26
+ /* Scoped like the mixin's rules, which it has to outrank for the border */
27
+ .counter-button .visible-wrapper {
28
+ display: flex;
29
+ align-items: center;
30
+ height: var(--ui-components-icon-button-visual-target-size);
31
+ padding: 0 8px; /* the design's counter frame inset */
32
+ border-radius: var(--ui-components-button-border-radius-top-left) 0 0
33
+ var(--ui-components-button-border-radius-bottom-left);
34
+ border-right: none; /* the list half's left border is the shared edge */
35
+ }
36
+
37
+ .counter::part(frame) {
38
+ background: none;
39
+ border: none;
40
+ border-radius: 0;
41
+ padding: 0; /* the counter's own frame gives way to the button's */
42
+ }
@@ -0,0 +1,142 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html} from 'lit';
4
+ import '../../main.css';
5
+ import './alert-subsystem-button.js';
6
+ import type {ObcAlertSubsystemButton} from './alert-subsystem-button.js';
7
+ import type {ObcIconButton} from '../icon-button/icon-button.js';
8
+ import type {ObcAlertCounterItem} from '../alert-counter-item/alert-counter-item.js';
9
+ import type {ObcAlertSubsystemCounter} from '../alert-subsystem-counter/alert-subsystem-counter.js';
10
+ import {tabStops} from '../../internal/_test-utils.js';
11
+
12
+ type ButtonProps = Partial<
13
+ Pick<
14
+ ObcAlertSubsystemButton,
15
+ | 'counts'
16
+ | 'hasAlert'
17
+ | 'label'
18
+ | 'emptyText'
19
+ | 'disabled'
20
+ | 'counterDisabled'
21
+ | 'listDisabled'
22
+ >
23
+ >;
24
+
25
+ async function setup(props: ButtonProps = {}) {
26
+ const screen = render(
27
+ html`<obc-alert-subsystem-button
28
+ .counts=${props.counts ?? {countCaution: 2}}
29
+ .hasAlert=${props.hasAlert ?? true}
30
+ .label=${props.label ?? ''}
31
+ .emptyText=${props.emptyText ?? 'No alerts'}
32
+ .disabled=${props.disabled ?? false}
33
+ .counterDisabled=${props.counterDisabled ?? false}
34
+ .listDisabled=${props.listDisabled ?? false}
35
+ ></obc-alert-subsystem-button>`
36
+ );
37
+ const el = screen.container.querySelector(
38
+ 'obc-alert-subsystem-button'
39
+ ) as ObcAlertSubsystemButton;
40
+ await el.updateComplete;
41
+ const counterButton = el.shadowRoot!.querySelector(
42
+ '[data-testid="counter-button"]'
43
+ ) as HTMLButtonElement;
44
+ const listButton = (
45
+ el.shadowRoot!.querySelector('[data-testid="list-button"]') as ObcIconButton
46
+ ).shadowRoot!.querySelector('button')!;
47
+ return {el, counterButton, listButton};
48
+ }
49
+
50
+ describe('obc-alert-subsystem-button', () => {
51
+ it('reports the counter and the list half as their own events, and lets no click out', async () => {
52
+ const {el, counterButton, listButton} = await setup();
53
+ const fired: string[] = [];
54
+ for (const name of ['counter-click', 'alert-list-click', 'click']) {
55
+ el.addEventListener(name, () => fired.push(name));
56
+ }
57
+
58
+ counterButton.click();
59
+ listButton.click();
60
+
61
+ expect(fired).toEqual(['counter-click', 'alert-list-click']);
62
+ });
63
+
64
+ it('disables the halves separately', async () => {
65
+ const a = await setup({counterDisabled: true});
66
+ expect([a.counterButton.disabled, a.listButton.disabled]).toEqual([
67
+ true,
68
+ false,
69
+ ]);
70
+
71
+ const b = await setup({listDisabled: true});
72
+ expect([b.counterButton.disabled, b.listButton.disabled]).toEqual([
73
+ false,
74
+ true,
75
+ ]);
76
+
77
+ const c = await setup({disabled: true});
78
+ expect([c.counterButton.disabled, c.listButton.disabled]).toEqual([
79
+ true,
80
+ true,
81
+ ]);
82
+ });
83
+
84
+ it('passes the counts to the counter item and names the counter half', async () => {
85
+ const {el, counterButton} = await setup({
86
+ label: 'HVAC',
87
+ counts: {countAlarm: 1, countCaution: 2},
88
+ });
89
+ const item = el.shadowRoot!.querySelector(
90
+ 'obc-alert-counter-item'
91
+ ) as ObcAlertCounterItem;
92
+
93
+ expect(item.counts).toEqual({countAlarm: 1, countCaution: 2});
94
+ expect(counterButton.getAttribute('aria-label')).toBe(
95
+ 'HVAC, 1 Alarm, 2 Caution'
96
+ );
97
+
98
+ const empty = await setup({label: 'HVAC', hasAlert: false});
99
+ expect(empty.counterButton.getAttribute('aria-label')).toBe(
100
+ 'HVAC, No alerts'
101
+ );
102
+ });
103
+
104
+ it('falls back to the empty state when hasAlert comes without counts', async () => {
105
+ const {el, counterButton} = await setup({
106
+ label: 'HVAC',
107
+ hasAlert: true,
108
+ counts: {},
109
+ });
110
+ const counter = el.shadowRoot!.querySelector(
111
+ 'obc-alert-subsystem-counter'
112
+ ) as ObcAlertSubsystemCounter;
113
+
114
+ expect(counterButton.getAttribute('aria-label')).toBe('HVAC, No alerts');
115
+ expect(counter.hasAlert).toBe(false);
116
+ });
117
+
118
+ it('names the counter half "Alerts" when it has neither label nor empty text', async () => {
119
+ const {counterButton} = await setup({hasAlert: false, emptyText: ''});
120
+
121
+ expect(counterButton.getAttribute('aria-label')).toBe('Alerts');
122
+ });
123
+
124
+ it('is two tab stops', async () => {
125
+ const screen = render(
126
+ html`<button id="before">b</button>
127
+ <obc-alert-subsystem-button></obc-alert-subsystem-button>`
128
+ );
129
+ await (
130
+ screen.container.querySelector(
131
+ 'obc-alert-subsystem-button'
132
+ ) as ObcAlertSubsystemButton
133
+ ).updateComplete;
134
+ (document.getElementById('before') as HTMLElement).focus();
135
+
136
+ const stops = await tabStops(2);
137
+
138
+ expect(
139
+ stops.map((e) => e?.getAttribute('data-testid') ?? e?.tagName)
140
+ ).toEqual(['counter-button', 'BUTTON']);
141
+ });
142
+ });
@@ -0,0 +1,69 @@
1
+ import type {Meta, StoryObj} from '@storybook/web-components-vite';
2
+ import {html} from 'lit';
3
+ import {ObcAlertSubsystemButton} from './alert-subsystem-button.js';
4
+ import './alert-subsystem-button.js';
5
+ import '../../icons/icon-placeholder.js';
6
+
7
+ const meta: Meta<ObcAlertSubsystemButton> = {
8
+ title: 'Application Components/Alerts/Alert Subsystem Button',
9
+ tags: ['autodocs', '6.1', 'experimental'],
10
+ component: 'obc-alert-subsystem-button',
11
+ args: {
12
+ counts: {countCaution: 2},
13
+ hasAlert: true,
14
+ label: '',
15
+ emptyText: 'No alerts',
16
+ },
17
+ argTypes: {
18
+ counts: {control: {type: 'object'}},
19
+ },
20
+ } satisfies Meta<ObcAlertSubsystemButton>;
21
+
22
+ export default meta;
23
+ type Story = StoryObj<ObcAlertSubsystemButton>;
24
+
25
+ export const Default: Story = {};
26
+
27
+ export const WithLabel: Story = {
28
+ args: {label: 'HVAC', counts: {countAlarm: 1, countCaution: 2}},
29
+ // A hand-written render for the slotted icon, so it binds every arg itself.
30
+ render: (args) =>
31
+ html`<obc-alert-subsystem-button
32
+ .counts=${args.counts ?? {}}
33
+ ?hasAlert=${args.hasAlert}
34
+ .label=${args.label}
35
+ .emptyText=${args.emptyText}
36
+ ?disabled=${args.disabled}
37
+ ?counterDisabled=${args.counterDisabled}
38
+ ?listDisabled=${args.listDisabled}
39
+ ><obi-placeholder slot="icon"></obi-placeholder
40
+ ></obc-alert-subsystem-button>`,
41
+ };
42
+
43
+ export const NoAlerts: Story = {
44
+ args: {hasAlert: false},
45
+ };
46
+
47
+ export const LevelSeverities: Story = {
48
+ args: {
49
+ counts: {
50
+ countLevelCritical: 1,
51
+ countLevelHigh: 9,
52
+ countLevelMedium: 4,
53
+ countLevelLow: 2,
54
+ countLevelDiagnostic: 7,
55
+ },
56
+ },
57
+ };
58
+
59
+ export const Disabled: Story = {
60
+ args: {disabled: true},
61
+ };
62
+
63
+ export const CounterDisabled: Story = {
64
+ args: {counterDisabled: true},
65
+ };
66
+
67
+ export const ListDisabled: Story = {
68
+ args: {listDisabled: true},
69
+ };
@@ -0,0 +1,168 @@
1
+ import {LitElement, html, unsafeCSS} from 'lit';
2
+ import {property} from 'lit/decorators.js';
3
+ import {localized, msg} from '@lit/localize';
4
+ import componentStyle from './alert-subsystem-button.css?inline';
5
+ import {customElement} from '../../decorator.js';
6
+ import '../alert-subsystem-counter/alert-subsystem-counter.js';
7
+ import '../alert-counter-item/alert-counter-item.js';
8
+ import '../icon-button/icon-button.js';
9
+ import '../../icons/icon-alert-list.js';
10
+ import type {AlertCounts} from '../../types.js';
11
+ import {alertCountsLabel, rankAlertCounts} from '../../alert-severity.js';
12
+
13
+ /**
14
+ * `<obc-alert-subsystem-button>` – A subsystem's alert counts as a split
15
+ * control: the counts open the alert menu, the list icon goes to the alert
16
+ * list page.
17
+ *
18
+ * The left half is `obc-alert-subsystem-counter` with the per-severity
19
+ * `counts` drawn by `obc-alert-counter-item`, inside a button of the normal
20
+ * style; the right half is an icon button with the alert list icon. The two
21
+ * share one edge, as the halves of `obc-split-button` do.
22
+ *
23
+ * ---
24
+ *
25
+ * ### Features
26
+ * - **Counts:** `counts` per severity, drawn as badges; `hasAlert` off, or
27
+ * on with nothing counted, shows `emptyText` instead.
28
+ * - **Label and icon:** `label` and the `icon` slot, as on the counter.
29
+ * - **Two halves:** `counter-click` from the counts, `alert-list-click` from
30
+ * the list icon; `counterDisabled` and `listDisabled` disable one half,
31
+ * `disabled` both.
32
+ * - **List icon:** the `list-icon` slot, the alert list icon when empty.
33
+ *
34
+ * ---
35
+ *
36
+ * ### Usage Guidelines
37
+ * - Show `obc-alert-menu` on `counter-click` and navigate on
38
+ * `alert-list-click`; the button reports the clicks and nothing more.
39
+ * - Two native buttons, each a tab stop, activated by Enter and Space
40
+ * ([APG button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/)).
41
+ * Left out: nothing.
42
+ * - **TODO(designer):** the design draws an empty placeholder badge for each
43
+ * zero count; no counter in the library does, so only non-zero counts are
44
+ * drawn (#1396).
45
+ * - **TODO(designer):** a disabled counter half dims its frame, while the
46
+ * severity badges keep their colour and the label its active colour; the
47
+ * design has no disabled variant.
48
+ *
49
+ * ---
50
+ *
51
+ * ### Example
52
+ *
53
+ * ```html
54
+ * <obc-alert-subsystem-button label="HVAC" hasAlert .counts=${{countCaution: 2}}>
55
+ * <obi-placeholder slot="icon"></obi-placeholder>
56
+ * </obc-alert-subsystem-button>
57
+ * ```
58
+ *
59
+ * @property counts - Alert count per severity, drawn as badges in the counter half.
60
+ * @availableWhen counts hasAlert==true
61
+ * @property hasAlert - Whether the subsystem has active alerts: `true` draws the badges, `false` the `emptyText`; `true` with nothing counted shows the `emptyText` as well.
62
+ * @property label - The subsystem label, before the badges.
63
+ * @property emptyText - Text shown instead of the badges when `hasAlert` is `false` or nothing is counted.
64
+ * @property disabled - Disables both halves.
65
+ * @property counterDisabled - Disables the counter half alone.
66
+ * @property listDisabled - Disables the list half alone.
67
+ * @property listButtonLabel - Accessible name of the list half; "Alert list" when left empty.
68
+ * @property ariaLabel - Accessible name of the counter half, mapped to the `aria-label` attribute; replaces the generated "HVAC, 2 Caution", or "Alerts" when the half has neither a label nor text. `aria-labelledby` is not supported: ID references cannot cross the shadow boundary.
69
+ * @slot icon - Leading icon of the counter half.
70
+ * @slot list-icon - Icon of the list half; the alert list icon when empty.
71
+ * @fires {CustomEvent<void>} counter-click - Fired when the counter half is clicked.
72
+ * @fires {CustomEvent<void>} alert-list-click - Fired when the list half is clicked.
73
+ * @experimental
74
+ */
75
+ @customElement('obc-alert-subsystem-button')
76
+ @localized()
77
+ export class ObcAlertSubsystemButton extends LitElement {
78
+ @property({type: Object, attribute: false}) counts: AlertCounts = {};
79
+ @property({type: Boolean}) hasAlert = false;
80
+ @property({type: String}) label = '';
81
+ @property({type: String}) emptyText = 'No alerts';
82
+ @property({type: Boolean}) disabled = false;
83
+ @property({type: Boolean}) counterDisabled = false;
84
+ @property({type: Boolean}) listDisabled = false;
85
+ @property({type: String}) listButtonLabel = '';
86
+
87
+ // Reactive so a consumer changing the name re-renders the inner button.
88
+ @property({type: String, attribute: 'aria-label'})
89
+ override ariaLabel: string | null = null;
90
+
91
+ /** The flag the counter gets: `hasAlert` with nothing to draw reads as none. */
92
+ private get showsCounts(): boolean {
93
+ return this.hasAlert && rankAlertCounts(this.counts).length > 0;
94
+ }
95
+
96
+ private get counterName(): string {
97
+ if (this.ariaLabel) {
98
+ return this.ariaLabel;
99
+ }
100
+ const state = this.showsCounts
101
+ ? alertCountsLabel(this.counts)
102
+ : this.emptyText;
103
+ return (
104
+ [this.label, state].filter((part) => part !== '').join(', ') ||
105
+ msg('Alerts')
106
+ );
107
+ }
108
+
109
+ private handleCounterClick = (e: Event) => {
110
+ e.stopPropagation();
111
+ this.dispatchEvent(new CustomEvent('counter-click'));
112
+ };
113
+
114
+ private handleListClick = (e: Event) => {
115
+ e.stopPropagation();
116
+ this.dispatchEvent(new CustomEvent('alert-list-click'));
117
+ };
118
+
119
+ override render() {
120
+ return html`
121
+ <div class="wrapper">
122
+ <button
123
+ class="counter-button"
124
+ data-testid="counter-button"
125
+ ?disabled=${this.disabled || this.counterDisabled}
126
+ aria-label=${this.counterName}
127
+ @click=${this.handleCounterClick}
128
+ >
129
+ <div class="visible-wrapper">
130
+ <obc-alert-subsystem-counter
131
+ class="counter"
132
+ .label=${this.label}
133
+ .hasAlert=${this.showsCounts}
134
+ .emptyText=${this.emptyText}
135
+ >
136
+ <slot name="icon" slot="icon"></slot>
137
+ <obc-alert-counter-item
138
+ slot="badges"
139
+ .counts=${this.counts}
140
+ ></obc-alert-counter-item>
141
+ </obc-alert-subsystem-counter>
142
+ </div>
143
+ </button>
144
+ <obc-icon-button
145
+ class="list-button"
146
+ data-testid="list-button"
147
+ variant="normal"
148
+ cornerRight
149
+ ?disabled=${this.disabled || this.listDisabled}
150
+ aria-label=${this.listButtonLabel || msg('Alert list')}
151
+ @click=${this.handleListClick}
152
+ >
153
+ <slot name="list-icon"
154
+ ><obi-alert-list aria-hidden="true"></obi-alert-list
155
+ ></slot>
156
+ </obc-icon-button>
157
+ </div>
158
+ `;
159
+ }
160
+
161
+ static override styles = unsafeCSS(componentStyle);
162
+ }
163
+
164
+ declare global {
165
+ interface HTMLElementTagNameMap {
166
+ 'obc-alert-subsystem-button': ObcAlertSubsystemButton;
167
+ }
168
+ }
@@ -26,6 +26,10 @@
26
26
  min-width: 0; /* lets the label shrink below its text width */
27
27
  }
28
28
 
29
+ .leading-container.no-leading {
30
+ display: none; /* no label and no icon: the badges take the whole frame, with no leading hole */
31
+ }
32
+
29
33
  .icon {
30
34
  flex-shrink: 0;
31
35
  width: var(--global-size-spacing-icon-icon-size-regular);