@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.4 → 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 (77) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +548 -6
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +543 -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 +6 -0
  37. package/dist/components/top-bar/top-bar.css.js.map +1 -1
  38. package/dist/components/top-bar/top-bar.d.ts +9 -1
  39. package/dist/components/top-bar/top-bar.d.ts.map +1 -1
  40. package/dist/components/top-bar/top-bar.js +2 -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-asset-picker.spec.ts +54 -0
  72. package/src/components/top-bar/top-bar-diagnostics.spec.ts +59 -0
  73. package/src/components/top-bar/top-bar.css +6 -0
  74. package/src/components/top-bar/top-bar.stories.ts +188 -78
  75. package/src/components/top-bar/top-bar.ts +11 -1
  76. package/src/generated/locales/es-419.ts +6 -0
  77. package/src/generated/locales/fi-FI.ts +6 -0
@@ -36,7 +36,8 @@ export enum ObcAlertSubsystemCounterOrientation {
36
36
  * - **Configurable empty text:** Customize the message shown when there are no
37
37
  * alerts via `emptyText`.
38
38
  * - **Optional leading icon:** Provide an icon through the `icon` slot; omit it
39
- * and the leading box collapses with no empty gap.
39
+ * and the leading box collapses with no empty gap; with no label either, the
40
+ * whole leading column goes and the badges take the frame.
40
41
  *
41
42
  * ---
42
43
  *
@@ -85,6 +86,7 @@ export enum ObcAlertSubsystemCounterOrientation {
85
86
  * @property emptyText - Text shown in the trailing area when `hasAlert` is `false`.
86
87
  * @availableWhen emptyText hasAlert==false
87
88
  * @slot icon - Optional leading 24px icon.
89
+ * @csspart frame - The framed box, for a host that draws its own frame around the counter.
88
90
  * @slot badges - Count badges shown when `hasAlert` is true.
89
91
  * @beta
90
92
  */
@@ -106,13 +108,19 @@ export class ObcAlertSubsystemCounter extends LitElement {
106
108
  override render() {
107
109
  return html`
108
110
  <div
111
+ part="frame"
109
112
  class=${classMap({
110
113
  frame: true,
111
114
  ['orientation-' + this.orientation]: true,
112
115
  'has-alert': this.hasAlert,
113
116
  })}
114
117
  >
115
- <div class="leading-container">
118
+ <div
119
+ class=${classMap({
120
+ 'leading-container': true,
121
+ 'no-leading': !this.hasIcon && this.label === '',
122
+ })}
123
+ >
116
124
  <div class=${classMap({icon: true, 'no-icon': !this.hasIcon})}>
117
125
  <slot name="icon" @slotchange=${this.handleIconSlotChange}></slot>
118
126
  </div>
@@ -0,0 +1,7 @@
1
+ :host {
2
+ display: inline-flex;
3
+ }
4
+
5
+ .item {
6
+ flex-grow: 1; /* fills the width a parent gives the host, as the item does inside the alert button */
7
+ }
@@ -0,0 +1,80 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html, nothing} from 'lit';
4
+ import './diagnostic-button.js';
5
+ import type {ObcDiagnosticButton} from './diagnostic-button.js';
6
+ import type {ObcAlertButtonItem} from '../alert-button-item/alert-button-item.js';
7
+
8
+ async function setup(nAlerts = 3, activated = false, ariaLabel?: string) {
9
+ const screen = render(
10
+ html`<obc-diagnostic-button
11
+ .nAlerts=${nAlerts}
12
+ .activated=${activated}
13
+ aria-label=${ariaLabel ?? nothing}
14
+ ></obc-diagnostic-button>`
15
+ );
16
+ const el = screen.container.querySelector(
17
+ 'obc-diagnostic-button'
18
+ ) as ObcDiagnosticButton;
19
+ await el.updateComplete;
20
+ const item = el.shadowRoot!.querySelector(
21
+ 'obc-alert-button-item'
22
+ ) as ObcAlertButtonItem;
23
+ await item.updateComplete;
24
+ return {el, item, button: item.shadowRoot!.querySelector('button')!};
25
+ }
26
+
27
+ describe('obc-diagnostic-button', () => {
28
+ it('forwards the count and the activated state to its item', async () => {
29
+ const {item} = await setup(3, true);
30
+
31
+ expect([item.nAlerts, item.counter, item.activated]).toEqual([
32
+ 3,
33
+ true,
34
+ true,
35
+ ]);
36
+ });
37
+
38
+ it('draws the asterisk in the icon slot', async () => {
39
+ const {item} = await setup();
40
+ const slot =
41
+ item.shadowRoot!.querySelector<HTMLSlotElement>('slot[name="icon"]')!;
42
+
43
+ expect(slot.assignedElements().map((e) => e.tagName)).toEqual([
44
+ 'OBI-DIAGNOSTIC-BADGE',
45
+ ]);
46
+ });
47
+
48
+ it('names itself after the count', async () => {
49
+ expect((await setup(3)).button.getAttribute('aria-label')).toBe(
50
+ 'Diagnostics, 3'
51
+ );
52
+ expect((await setup(0)).button.getAttribute('aria-label')).toBe(
53
+ 'Diagnostics'
54
+ );
55
+ expect(
56
+ (await setup(3, false, 'Health')).button.getAttribute('aria-label')
57
+ ).toBe('Health');
58
+ });
59
+
60
+ it('forwards aria-expanded to its button, absent until set', async () => {
61
+ const {el, item, button} = await setup();
62
+ expect(button.hasAttribute('aria-expanded')).toBe(false);
63
+
64
+ el.setAttribute('aria-expanded', 'true');
65
+ await el.updateComplete;
66
+ await item.updateComplete;
67
+
68
+ expect(button.getAttribute('aria-expanded')).toBe('true');
69
+ });
70
+
71
+ it('reports a click', async () => {
72
+ const {el, button} = await setup();
73
+ let clicks = 0;
74
+ el.addEventListener('click', () => clicks++);
75
+
76
+ button.click();
77
+
78
+ expect(clicks).toBe(1);
79
+ });
80
+ });
@@ -0,0 +1,30 @@
1
+ import type {Meta, StoryObj} from '@storybook/web-components-vite';
2
+ import {ObcDiagnosticButton} from './diagnostic-button.js';
3
+ import './diagnostic-button.js';
4
+
5
+ const meta: Meta<ObcDiagnosticButton> = {
6
+ title: 'Application Components/Alerts/Diagnostic Button',
7
+ tags: ['autodocs', '6.1', 'experimental'],
8
+ component: 'obc-diagnostic-button',
9
+ args: {
10
+ nAlerts: 3,
11
+ activated: false,
12
+ },
13
+ argTypes: {
14
+ nAlerts: {control: {type: 'number', min: 0}},
15
+ },
16
+ } satisfies Meta<ObcDiagnosticButton>;
17
+
18
+ export default meta;
19
+ type Story = StoryObj<ObcDiagnosticButton>;
20
+
21
+ export const Default: Story = {};
22
+
23
+ /** The selected style, for the button whose menu is showing. */
24
+ export const Activated: Story = {
25
+ args: {activated: true},
26
+ };
27
+
28
+ export const NoDiagnostics: Story = {
29
+ args: {nAlerts: 0},
30
+ };
@@ -0,0 +1,100 @@
1
+ import {LitElement, html, unsafeCSS} from 'lit';
2
+ import {property} from 'lit/decorators.js';
3
+ import {ifDefined} from 'lit/directives/if-defined.js';
4
+ import {localized, msg} from '@lit/localize';
5
+ import componentStyle from './diagnostic-button.css?inline';
6
+ import {customElement} from '../../decorator.js';
7
+ import '../alert-button-item/alert-button-item.js';
8
+ import '../alert-frame/diagnostic-badge.js';
9
+
10
+ /**
11
+ * `<obc-diagnostic-button>` – The top bar's diagnostic button: the asterisk
12
+ * and the number of diagnostics, selected while its menu is showing.
13
+ *
14
+ * The diagnostic counterpart of `obc-alert-button`: `obc-alert-button-item`
15
+ * with the diagnostic asterisk in its icon slot and a name of its own. It
16
+ * opens `obc-diagnostic-menu`, as the alert button opens the alert menu.
17
+ *
18
+ * ---
19
+ *
20
+ * ### Features
21
+ * - **Counter:** `nAlerts` is drawn next to the asterisk; 0 shows the
22
+ * asterisk alone.
23
+ * - **Activated:** `activated` draws the selected style while the diagnostic
24
+ * menu is showing.
25
+ * - **Name:** "Diagnostics, 3" is announced, and repeated when the count
26
+ * changes; `aria-label` replaces it.
27
+ *
28
+ * ---
29
+ *
30
+ * ### Usage Guidelines
31
+ * - Slot it into `obc-top-bar`'s `diagnostics` slot, after the alert button,
32
+ * or place it in a toolbar on its own.
33
+ * - Open the menu from `click` the way a bar button opens a menu: flip a
34
+ * flag of your own, bind it to the menu's `open`, to `activated` and to
35
+ * `aria-expanded`, and reset it on the menu's `close`.
36
+ * - A native button, so Enter and Space activate it
37
+ * ([APG button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/)).
38
+ * Left out: nothing.
39
+ * - **TODO(designer):** the design draws a six-armed asterisk with rounded
40
+ * arms that is not in the icon library; the button draws
41
+ * `obi-diagnostic-badge`, the sharp asterisk of the diagnostic alert icon,
42
+ * until the icon is added (#1396).
43
+ *
44
+ * ---
45
+ *
46
+ * ### Example
47
+ *
48
+ * ```html
49
+ * <obc-diagnostic-button nAlerts="3" activated></obc-diagnostic-button>
50
+ * ```
51
+ *
52
+ * @property nAlerts - Number of diagnostics, drawn as the counter; 0 shows the asterisk alone.
53
+ * @property activated - Draws the selected style while the diagnostic menu is showing; bind it to the flag that drives the menu's `open`.
54
+ * @property ariaLabel - Accessible name forwarded to the inner `<button>`, mapped to the `aria-label` attribute; replaces the generated "Diagnostics, 3". `aria-labelledby` is not supported: ID references cannot cross the shadow boundary.
55
+ * @property ariaExpanded - Whether the diagnostic menu is showing, forwarded to the inner `<button>` as `aria-expanded`; mapped to the `aria-expanded` attribute. Bind it with `activated`; left unset, the button announces no menu.
56
+ * @fires click - Fired when the button is clicked.
57
+ * @experimental
58
+ */
59
+ @customElement('obc-diagnostic-button')
60
+ @localized()
61
+ export class ObcDiagnosticButton extends LitElement {
62
+ @property({type: Number}) nAlerts = 0;
63
+ @property({type: Boolean}) activated = false;
64
+
65
+ // Reactive so a consumer changing the name re-renders the inner button.
66
+ @property({type: String, attribute: 'aria-label'})
67
+ override ariaLabel: string | null = null;
68
+
69
+ @property({type: String, attribute: 'aria-expanded'})
70
+ override ariaExpanded: string | null = null;
71
+
72
+ private get accessibleName(): string {
73
+ if (this.ariaLabel) {
74
+ return this.ariaLabel;
75
+ }
76
+ return this.nAlerts > 0
77
+ ? `${msg('Diagnostics')}, ${this.nAlerts}`
78
+ : msg('Diagnostics');
79
+ }
80
+
81
+ override render() {
82
+ return html`<obc-alert-button-item
83
+ class="item"
84
+ .nAlerts=${this.nAlerts}
85
+ counter
86
+ .activated=${this.activated}
87
+ aria-label=${this.accessibleName}
88
+ aria-expanded=${ifDefined(this.ariaExpanded ?? undefined)}
89
+ ><obi-diagnostic-badge slot="icon"></obi-diagnostic-badge
90
+ ></obc-alert-button-item>`;
91
+ }
92
+
93
+ static override styles = unsafeCSS(componentStyle);
94
+ }
95
+
96
+ declare global {
97
+ interface HTMLElementTagNameMap {
98
+ 'obc-diagnostic-button': ObcDiagnosticButton;
99
+ }
100
+ }
@@ -0,0 +1,69 @@
1
+ @mixin soft-dismiss;
2
+
3
+ * {
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ :host {
8
+ display: block;
9
+ }
10
+
11
+ .wrapper {
12
+ @mixin card;
13
+ border-radius: var(--app-components-app-menu-border-radius);
14
+ width: var(
15
+ --app-components-alert-menu-width
16
+ ); /* beside the alert menu under one bar; the design's 696 px binds no token */
17
+ height: 560px; /* the alert menu's box, so the two line up; the design hugs its rows */
18
+ max-width: 100vw;
19
+ display: flex;
20
+ flex-direction: column;
21
+ overflow: hidden; /* the card radius clips the rows and the footer */
22
+ }
23
+
24
+ .title-container {
25
+ display: flex;
26
+ align-items: center;
27
+ padding: var(--app-components-user-menu-margin-vertical)
28
+ var(--app-components-user-menu-margin-horizontal)
29
+ var(--app-components-user-menu-padding-vertical);
30
+ }
31
+
32
+ .title {
33
+ @mixin font-overline;
34
+ margin: 0;
35
+ padding-inline: var(--app-components-system-menu-padding-horizontal);
36
+ color: var(--element-neutral-color);
37
+ }
38
+
39
+ .list {
40
+ flex: 1 1 0;
41
+ min-height: 0; /* the list scrolls instead of growing the card */
42
+ overflow: hidden;
43
+ position: relative;
44
+ padding: 4px; /* the design's row column inset */
45
+ }
46
+
47
+ .empty-badge {
48
+ display: block;
49
+ width: 100%;
50
+ height: 100%;
51
+ color: var(--element-neutral-color);
52
+ }
53
+
54
+ .action {
55
+ display: flex;
56
+ flex-shrink: 0;
57
+ flex-wrap: wrap;
58
+ align-items: center;
59
+ gap: var(--app-components-alert-menu-button-spacing);
60
+ padding: var(--app-components-user-menu-padding-vertical)
61
+ var(--app-components-alert-menu-footer-padding-horizontal);
62
+ border-top: 1px solid var(--border-divider-color);
63
+ background: var(--container-global-color);
64
+ }
65
+
66
+ ::slotted(*) {
67
+ display: block;
68
+ will-change: transform;
69
+ }
@@ -0,0 +1,114 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html} from 'lit';
4
+ import './diagnostic-menu.js';
5
+ import {
6
+ ObcDiagnosticMenu,
7
+ ObcDiagnosticMenuAckAllVisibleClickEvent,
8
+ } from './diagnostic-menu.js';
9
+ import '../message-menu-item/message-menu-item.js';
10
+ import type {ObcButton} from '../button/button.js';
11
+
12
+ const nextTask = () => new Promise((resolve) => setTimeout(resolve, 0));
13
+
14
+ async function setup(rows = ['a', 'b', 'c'], canAckAll = true) {
15
+ const screen = render(
16
+ html`<obc-diagnostic-menu .canAckAll=${canAckAll}>
17
+ ${rows.map(
18
+ (id) =>
19
+ html`<obc-message-menu-item
20
+ id=${id}
21
+ title=${id}
22
+ ></obc-message-menu-item>`
23
+ )}
24
+ </obc-diagnostic-menu>`
25
+ );
26
+ const el = screen.container.querySelector(
27
+ 'obc-diagnostic-menu'
28
+ ) as ObcDiagnosticMenu;
29
+ await el.updateComplete;
30
+ return el;
31
+ }
32
+
33
+ function shadowButton(el: ObcDiagnosticMenu, testId: string) {
34
+ return (
35
+ el.shadowRoot!.querySelector(`[data-testid="${testId}"]`) as ObcButton
36
+ ).shadowRoot!.querySelector('button')!;
37
+ }
38
+
39
+ describe('obc-diagnostic-menu', () => {
40
+ it('ack-all-visible-click carries every row', async () => {
41
+ const el = await setup();
42
+ let ids: string[] | undefined;
43
+ el.addEventListener('ack-all-visible-click', (e) => {
44
+ ids = (
45
+ e as ObcDiagnosticMenuAckAllVisibleClickEvent
46
+ ).detail.visibleElements.map(({element}) => element.id);
47
+ });
48
+
49
+ shadowButton(el, 'ack-all-visible-button').click();
50
+
51
+ expect(ids).toEqual(['a', 'b', 'c']);
52
+ });
53
+
54
+ it('disables ACK all visible until canAckAll', async () => {
55
+ const el = await setup(['a'], false);
56
+
57
+ expect(shadowButton(el, 'ack-all-visible-button').disabled).toBe(true);
58
+ });
59
+
60
+ it('go-to-diagnostic-list-click fires from the list button, which showDiagnosticListButton hides', async () => {
61
+ const el = await setup();
62
+ let fired = 0;
63
+ el.addEventListener('go-to-diagnostic-list-click', () => fired++);
64
+
65
+ shadowButton(el, 'diagnostic-list-button').click();
66
+ expect(fired).toBe(1);
67
+
68
+ el.showDiagnosticListButton = false;
69
+ await el.updateComplete;
70
+ expect(
71
+ el.shadowRoot!.querySelector('[data-testid="diagnostic-list-button"]')
72
+ ).toBeNull();
73
+ });
74
+
75
+ it('titles itself Diagnostics unless menuTitle is set', async () => {
76
+ const el = await setup();
77
+ const title = () => el.shadowRoot!.querySelector('h3')!.textContent!.trim();
78
+
79
+ expect(title()).toBe('Diagnostics');
80
+
81
+ el.menuTitle = 'Health';
82
+ await el.updateComplete;
83
+ expect(title()).toBe('Health');
84
+ });
85
+
86
+ it('shows the empty state without rows', async () => {
87
+ const el = await setup([]);
88
+ const list = el.shadowRoot!.querySelector('obc-alert-list')!;
89
+ await list.updateComplete;
90
+ const titleSlot = list.shadowRoot!.querySelector<HTMLSlotElement>(
91
+ 'slot[name="empty-title"]'
92
+ )!;
93
+
94
+ expect(titleSlot.assignedElements()[0].textContent!.trim()).toBe(
95
+ 'No diagnostics'
96
+ );
97
+ });
98
+
99
+ it('writes open back and fires close when it closes itself', async () => {
100
+ const el = await setup();
101
+ el.softDismiss = true;
102
+ el.open = true;
103
+ await el.updateComplete;
104
+ await nextTask();
105
+ let closed = 0;
106
+ el.addEventListener('close', () => closed++);
107
+
108
+ el.hidePopover();
109
+ await el.updateComplete;
110
+ await nextTask();
111
+
112
+ expect([el.open, closed]).toEqual([false, 1]);
113
+ });
114
+ });
@@ -0,0 +1,135 @@
1
+ import type {Meta, StoryObj} from '@storybook/web-components-vite';
2
+ import {html, nothing, render, type TemplateResult} from 'lit';
3
+ import {ObcDiagnosticMenu} from './diagnostic-menu.js';
4
+ import './diagnostic-menu.js';
5
+ import '../message-menu-item/message-menu-item.js';
6
+ import '../top-bar/top-bar.js';
7
+ import '../diagnostic-button/diagnostic-button.js';
8
+ import '../../icons/icon-placeholder.js';
9
+ import '../../icons/icon-simulate.js';
10
+
11
+ type MenuArgs = Pick<
12
+ ObcDiagnosticMenu,
13
+ 'canAckAll' | 'menuTitle' | 'showAckAllButton' | 'showDiagnosticListButton'
14
+ >;
15
+
16
+ const DESCRIPTION =
17
+ 'A long notification message of more than one line of text and meaningful content. Sometimes it might be quite long and that is ok.';
18
+
19
+ const row = (
20
+ title: string,
21
+ open = false,
22
+ icon = html`<obi-placeholder></obi-placeholder>`
23
+ ) =>
24
+ html`<obc-message-menu-item
25
+ title=${title}
26
+ description=${DESCRIPTION}
27
+ day="Yesterday"
28
+ time="09:12:34"
29
+ primaryActionLabel="Action"
30
+ hasPrimaryIcon
31
+ ?open=${open}
32
+ ><span slot="primary-icon">${icon}</span></obc-message-menu-item
33
+ >`;
34
+
35
+ /** The five rows of the design, the third expanded. */
36
+ const diagnosticRows = (): TemplateResult =>
37
+ html`${row('Simulate', false, html`<obi-simulate></obi-simulate>`)}
38
+ ${row('Title')} ${row('Title', true)} ${row('Title')} ${row('Title')}`;
39
+
40
+ const renderMenu = (
41
+ args: Partial<MenuArgs>,
42
+ rows: TemplateResult | typeof nothing = diagnosticRows()
43
+ ) =>
44
+ html`<obc-diagnostic-menu
45
+ .canAckAll=${args.canAckAll ?? false}
46
+ .menuTitle=${args.menuTitle ?? ''}
47
+ .showAckAllButton=${args.showAckAllButton ?? true}
48
+ .showDiagnosticListButton=${args.showDiagnosticListButton ?? true}
49
+ >${rows}</obc-diagnostic-menu
50
+ >`;
51
+
52
+ const meta: Meta<MenuArgs> = {
53
+ title: 'Application Components/Alerts/Diagnostic Menu',
54
+ tags: ['autodocs', '6.1', 'experimental'],
55
+ component: 'obc-diagnostic-menu',
56
+ args: {
57
+ canAckAll: true,
58
+ menuTitle: '',
59
+ showAckAllButton: true,
60
+ showDiagnosticListButton: true,
61
+ },
62
+ render: (args) => renderMenu(args),
63
+ } satisfies Meta<MenuArgs>;
64
+
65
+ export default meta;
66
+ type Story = StoryObj<MenuArgs>;
67
+
68
+ export const Regular: Story = {};
69
+
70
+ export const Empty: Story = {
71
+ render: (args) => renderMenu(args, nothing),
72
+ };
73
+
74
+ export const NoDiagnosticListButton: Story = {
75
+ args: {showDiagnosticListButton: false},
76
+ };
77
+
78
+ /**
79
+ * The menu opened from the top bar's diagnostic button, with the three
80
+ * bindings every soft-dismiss menu needs: a flag the app keeps, bound to
81
+ * `open` and to the button's `activated` and `aria-expanded`, flipped on
82
+ * the button's `click` and reset on `close`. A click outside closes the
83
+ * menu and reaches nothing else; the bar stays clickable.
84
+ */
85
+ export const SoftDismissFromATopBarButton: Story = {
86
+ // Nothing to snapshot: the story is about what the clicks do.
87
+ tags: ['skip-test'],
88
+ parameters: {layout: 'fullscreen'},
89
+ render: (args) => {
90
+ const bar = document.createElement('obc-top-bar');
91
+ bar.appTitle = 'App';
92
+ bar.pageName = 'Page';
93
+ bar.showDimmingButton = true;
94
+ bar.showUserButton = true;
95
+
96
+ const button = document.createElement('obc-diagnostic-button');
97
+ button.slot = 'diagnostics';
98
+ button.nAlerts = 3;
99
+ bar.append(button);
100
+
101
+ const menu = document.createElement('obc-diagnostic-menu');
102
+ Object.assign(menu, args, {softDismiss: true});
103
+ render(diagnosticRows(), menu);
104
+ // Under the bar's right end, where its diagnostic button sits.
105
+ menu.style.cssText =
106
+ 'position: fixed; right: 4px;' +
107
+ 'top: calc(var(--app-components-topbar-touch-target-size) + 4px);';
108
+
109
+ let open = false;
110
+ const apply = () => {
111
+ menu.open = open;
112
+ button.activated = open;
113
+ button.ariaExpanded = String(open);
114
+ };
115
+ button.addEventListener('click', () => {
116
+ open = !open;
117
+ apply();
118
+ });
119
+ menu.addEventListener('close', () => {
120
+ open = false;
121
+ apply();
122
+ });
123
+ apply();
124
+
125
+ let hits = 0;
126
+ const behind = document.createElement('button');
127
+ behind.textContent = 'a button behind the menu';
128
+ behind.style.cssText = 'display: block; margin: 240px 16px 0 auto;';
129
+ behind.addEventListener('click', () => {
130
+ behind.textContent = `clicked ${++hits} time${hits === 1 ? '' : 's'}`;
131
+ });
132
+
133
+ return html`${bar}${menu}${behind}`;
134
+ },
135
+ };