@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.19 → 2.2.0-next.20

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 (29) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +43 -35
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +108 -7
  4. package/dist/components/button/button.d.ts +8 -0
  5. package/dist/components/button/button.d.ts.map +1 -1
  6. package/dist/components/button/button.js +6 -0
  7. package/dist/components/button/button.js.map +1 -1
  8. package/dist/components/command-menu/command-menu.d.ts +42 -14
  9. package/dist/components/command-menu/command-menu.d.ts.map +1 -1
  10. package/dist/components/command-menu/command-menu.js +25 -6
  11. package/dist/components/command-menu/command-menu.js.map +1 -1
  12. package/dist/components/start-stop-switch/start-stop-switch.css_inline.js +3 -22
  13. package/dist/components/start-stop-switch/start-stop-switch.d.ts +3 -2
  14. package/dist/components/start-stop-switch/start-stop-switch.d.ts.map +1 -1
  15. package/dist/components/start-stop-switch/start-stop-switch.js +9 -7
  16. package/dist/components/start-stop-switch/start-stop-switch.js.map +1 -1
  17. package/docs/MigrationGuide22.mdx +10 -2
  18. package/docs/migration-guide-2-2/renamed-slots.md +7 -0
  19. package/package.json +1 -1
  20. package/src/components/button/button.spec.ts +75 -0
  21. package/src/components/button/button.stories.ts +2 -0
  22. package/src/components/button/button.ts +10 -0
  23. package/src/components/command-menu/command-menu.spec.ts +125 -0
  24. package/src/components/command-menu/command-menu.stories.ts +41 -4
  25. package/src/components/command-menu/command-menu.ts +57 -20
  26. package/src/components/start-stop-switch/start-stop-switch.css +2 -20
  27. package/src/components/start-stop-switch/start-stop-switch.spec.ts +59 -0
  28. package/src/components/start-stop-switch/start-stop-switch.ts +19 -9
  29. package/src/components/tabbed-card/tabbed-card.stories.ts +1 -1
@@ -241,10 +241,6 @@ var start_stop_switch_default = css`* {
241
241
  width: fit-content;
242
242
  justify-content: center;
243
243
  align-items: center;
244
-
245
- padding: 0;
246
- background: transparent;
247
- border: none;
248
244
  min-width: var(--ui-components-start-stop-switch-touch-target-size);
249
245
  cursor: grab;
250
246
 
@@ -253,16 +249,9 @@ var start_stop_switch_default = css`* {
253
249
  right 0.1s ease-in-out,
254
250
  width 0.2s ease-in-out;
255
251
 
256
- /* Remove focus styling from button - focus is shown on wrapper instead */
252
+ /* Prevent any visual changes on active/pressed state */
257
253
  }
258
254
 
259
- .button:focus-visible {
260
- outline: none;
261
- box-shadow: none;
262
- }
263
-
264
- /* Prevent any visual changes on active/pressed state */
265
-
266
255
  .button:active {
267
256
  cursor: grabbing;
268
257
  }
@@ -337,17 +326,9 @@ var start_stop_switch_default = css`* {
337
326
  border-color: var(--indent-disabled-border-color);
338
327
  }
339
328
 
340
- /* Hide the button visually when disabled, but keep it in DOM for accessibility */
329
+ /* A disabled switch has nothing to drag: the state label stands alone */
341
330
  .wrapper.disabled .button {
342
- position: absolute;
343
- width: 1px;
344
- height: 1px;
345
- padding: 0;
346
- margin: -1px;
347
- overflow: hidden;
348
- clip: rect(0, 0, 0, 0);
349
- white-space: nowrap;
350
- border: 0;
331
+ display: none;
351
332
  }
352
333
 
353
334
  .wrapper.disabled .state {
@@ -85,8 +85,9 @@ export type ObcStartStopSwitchChangeEvent = CustomEvent<{
85
85
  *
86
86
  * ### Keyboard
87
87
  * [APG Switch](https://www.w3.org/WAI/ARIA/apg/patterns/switch/): `Space` and
88
- * `Enter` toggle it. The knob inside is a drag handle for pointers and stays
89
- * out of the tab sequence.
88
+ * `Enter` toggle it. The knob inside is a drag handle for pointers, not a
89
+ * control of its own: a switch announces its content as one name, so nothing
90
+ * inside it may take focus. The description, when shown, describes the switch.
90
91
  *
91
92
  * Left out: nothing.
92
93
  *
@@ -1 +1 @@
1
- {"version":3,"file":"start-stop-switch.d.ts","sourceRoot":"","sources":["../../../src/components/start-stop-switch/start-stop-switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAkB,MA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oBAAoB;IASpB,MAAM;IA+Ff,OAAgB,MAAM,0BAA6B;CACpD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,uBAAuB,EAAE,kBAAkB,CAAC;KAC7C;CACF"}
1
+ {"version":3,"file":"start-stop-switch.d.ts","sourceRoot":"","sources":["../../../src/components/start-stop-switch/start-stop-switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAkB,MAAM,KAAK,CAAC;AAKhD,OAAO,wCAAwC,CAAC;AAIhD;;;;;GAKG;AACH,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED;;;;GAIG;AACH,oBAAY,mBAAmB;IAC7B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,6BAA6B,GAAG,WAAW,CAAC;IACtD,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AAQH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AACH,qBACa,kBAAmB,SAAQ,UAAU;IACN,OAAO,UAAS;IAEjB,OAAO,EAAE,sBAAsB,CACxC;IAES,IAAI,EAAE,mBAAmB,CACpC;IAEY,QAAQ,UAAS;IAEhC,QAAQ,UAAS;IAEjB,cAAc,UAAS;IAExB,WAAW,SAAwB;IAEpD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAEpC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,cAAc,CAAC,CAAiB;IAGxC,OAAO,CAAC,SAAS,CAAC,CAAc;IAGhC,OAAO,CAAC,QAAQ,CAAC,CAAc;IAE/B,OAAO,CAAC,WAAW,CAejB;IAEF,OAAO,CAAC,UAAU,CAmBhB;IAEF,OAAO,CAAC,SAAS,CA8Bf;IAEF,OAAO,CAAC,aAAa,CAOnB;IAEF,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,cAAc;IAiBb,YAAY;IASZ,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAiC/C,oBAAoB;IASpB,MAAM;IAkGf,OAAgB,MAAM,0BAA6B;CACpD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,uBAAuB,EAAE,kBAAkB,CAAC;KAC7C;CACF"}
@@ -83,10 +83,11 @@ var ObcStartStopSwitch = class ObcStartStopSwitch extends LitElement {
83
83
  this.dragging = false;
84
84
  const maxOffset = this.trackWidth - this.buttonWidth;
85
85
  const percent = ((this.checked ? maxOffset : 0) + this.dragOffset) / maxOffset;
86
- if (!this.checked && percent > DRAG_COMPLETE_THRESHOLD) {
86
+ const canCommit = !this.disabled;
87
+ if (canCommit && !this.checked && percent > DRAG_COMPLETE_THRESHOLD) {
87
88
  this.checked = true;
88
89
  this.dispatchChangeEvent();
89
- } else if (this.checked && percent < .09999999999999998) {
90
+ } else if (canCommit && this.checked && percent < .09999999999999998) {
90
91
  this.checked = false;
91
92
  this.dispatchChangeEvent();
92
93
  }
@@ -189,16 +190,15 @@ var ObcStartStopSwitch = class ObcStartStopSwitch extends LitElement {
189
190
  aria-checked=${isChecked ? "true" : "false"}
190
191
  aria-disabled=${this.disabled ? "true" : "false"}
191
192
  aria-label=${ifDefined(forwardedAriaLabel)}
193
+ aria-describedby=${ifDefined(this.hasDescription ? "description" : void 0)}
192
194
  @keydown=${this.handleKeydown}
193
195
  >
194
196
  <div class="button-track">
195
- <button
197
+ <div
196
198
  class="button"
197
199
  style=${this.getButtonStyle()}
198
200
  @mousedown=${this.disabled ? void 0 : this.onDragStart}
199
201
  @touchstart=${this.disabled ? void 0 : this.onDragStart}
200
- ?disabled=${this.disabled}
201
- tabindex="-1"
202
202
  >
203
203
  ${!this.disabled ? html`
204
204
  <div class="button-visible">
@@ -213,7 +213,7 @@ var ObcStartStopSwitch = class ObcStartStopSwitch extends LitElement {
213
213
  </div>
214
214
  </div>
215
215
  ` : ""}
216
- </button>
216
+ </div>
217
217
  ${!this.disabled ? html`<div class="button-track-checked"></div>` : ""}
218
218
  <div class="checked state">
219
219
  <slot name="checked-state-icon"></slot>
@@ -230,7 +230,9 @@ var ObcStartStopSwitch = class ObcStartStopSwitch extends LitElement {
230
230
  </div>
231
231
  ${this.hasAlert ? html`<div class="alert-frame"></div>` : ""}
232
232
  </div>
233
- ${this.hasDescription ? html`<div class="description">${this.description}</div>` : ""}
233
+ ${this.hasDescription ? html`<div class="description" id="description">
234
+ ${this.description}
235
+ </div>` : ""}
234
236
  </div>
235
237
  </div>
236
238
  </div>
@@ -1 +1 @@
1
- {"version":3,"file":"start-stop-switch.js","names":["componentStyle","_decorate"],"sources":["../../../src/components/start-stop-switch/start-stop-switch.ts"],"sourcesContent":["import {LitElement, html, unsafeCSS} from 'lit';\nimport {property, query, state} from 'lit/decorators.js';\nimport componentStyle from './start-stop-switch.css?inline';\nimport {classMap} from 'lit/directives/class-map.js';\nimport {ifDefined} from 'lit/directives/if-defined.js';\nimport '../../icons/icon-arrow-right-google.js';\nimport {customElement} from '../../decorator.js';\nimport {clamp} from '../../svghelpers/math.js';\n\n/**\n * The visual variant for the start-stop switch when checked.\n * - `normal`: Standard blue appearance (default)\n * - `running`: Green appearance indicating motor/process is running\n * - `loading`: Light blue appearance indicating a pending/loading state\n */\nexport enum StartStopSwitchVariant {\n normal = 'normal',\n running = 'running',\n loading = 'loading',\n}\n\n/**\n * The possible sizes for the start-stop switch.\n * - `regular`: Standard size with 32px track height\n * - `large`: Larger size with 48px track height\n */\nexport enum StartStopSwitchSize {\n regular = 'regular',\n large = 'large',\n}\n\nexport type ObcStartStopSwitchChangeEvent = CustomEvent<{\n checked: boolean;\n}>;\n\n/**\n * Threshold for completing a drag gesture (90% of track width).\n * User must drag past this threshold to toggle the switch state.\n */\nconst DRAG_COMPLETE_THRESHOLD = 0.9;\n\n/**\n * `<obc-start-stop-switch>` – A two-state draggable toggle switch for significant binary actions like start/stop or enable/disable.\n *\n * This switch provides a visually distinct, draggable toggle for binary actions where both states need to be explicitly labeled and reinforced. Unlike a simple on/off toggle, it displays both the current state label and an action label on the draggable thumb, making it ideal for consequential actions where user awareness is critical.\n *\n * ### Features\n * - **Drag-to-toggle interaction:** Users must drag the thumb across the track to change state (90% threshold required). This deliberate interaction prevents accidental toggles.\n * - **Dual state labels:** Displays both a state label (e.g., \"Running\", \"Stopped\") and an action label on the thumb (e.g., \"Start\", \"Stop\").\n * - **Visual variants:**\n * - `normal`: Standard blue appearance when checked (default)\n * - `running`: Green appearance indicating an active process (e.g., motor running)\n * - `loading`: Light blue appearance indicating a pending/transitional state\n * - **Size options:** `regular` (32px track height) or `large` (48px track height, matching touch target).\n * - **Alert frame:** Optional red border to indicate alarm or critical state.\n * - **Description text:** Optional text below the switch for additional context.\n * - **Animated transitions:** Smooth CSS transitions for thumb movement and state changes.\n * - **Keyboard accessible:** The switch is focusable and follows the ARIA switch pattern — `Enter` or `Space` toggles the state and fires the same `change` event as a completed drag.\n *\n * ### Usage Guidelines\n * Use `<obc-start-stop-switch>` when you need a prominent control for toggling between two mutually exclusive states where:\n * - Both states should be explicitly labeled (not just \"on/off\")\n * - The action has significant consequences (starting a motor, enabling a system)\n * - Accidental activation should be prevented through deliberate drag interaction\n *\n * Avoid using this component for simple preferences or settings where a standard `<obc-switch>` or checkbox would suffice. This component is best suited for operational controls where the user must be aware of both the current state and the action they're about to take.\n *\n * **Related components:** For simple binary toggles without labels, use `<obc-switch>`. For grouped selections, use `<obc-radio>` or `<obc-checkbox>`.\n *\n * ### Slots\n * | Slot Name | Renders When... | Purpose |\n * |---------------------------|----------------------|------------------------------------------------------------|\n * | checked-state-icon | Always (if provided) | Icon displayed in the checked state area. |\n * | unchecked-state-icon | Always (if provided) | Icon displayed in the unchecked state area. |\n * | checked-state-label | Always | Label shown when switch is in checked position. |\n * | unchecked-state-label | Always | Label shown when switch is in unchecked position. |\n * | to-checked-action-label | When unchecked | Action label on thumb prompting user to activate. |\n * | to-unchecked-action-label | When checked | Action label on thumb prompting user to deactivate. |\n *\n * ### Events\n * - `change` – Fired when the switch state changes after a successful drag. The event detail contains `{checked: boolean}` indicating the new state.\n *\n * ### Best Practices\n * - Keep labels concise (1-2 words) to fit within the track width.\n * - Use meaningful action verbs: \"Start/Stop\", \"Enable/Disable\", \"Request/Release\".\n * - Use the `running` variant to indicate an actively running process.\n * - Use the `loading` variant during async operations before transitioning to `running` or `normal`.\n * - Consider using `hasAlert` when the switch controls a critical system in alarm state.\n * - The accessible name is computed from the slotted labels; provide `aria-label` on the host when those labels alone are not descriptive (`aria-labelledby` is not supported — ID references cannot cross the shadow boundary).\n *\n * ### Example\n * ```html\n * <obc-start-stop-switch checked variant=\"running\">\n * <div slot=\"checked-state-icon\"><obi-placeholder></obi-placeholder></div>\n * <div slot=\"checked-state-label\">Running</div>\n * <div slot=\"unchecked-state-label\">Stopped</div>\n * <div slot=\"to-checked-action-label\">Start</div>\n * <div slot=\"to-unchecked-action-label\">Stop</div>\n * </obc-start-stop-switch>\n * ```\n *\n * ### Keyboard\n * [APG Switch](https://www.w3.org/WAI/ARIA/apg/patterns/switch/): `Space` and\n * `Enter` toggle it. The knob inside is a drag handle for pointers and stays\n * out of the tab sequence.\n *\n * Left out: nothing.\n *\n * @property checked - Whether the switch is in the checked (active) state.\n * When checked, the thumb is on the right side.\n * When unchecked, the thumb is on the left side.\n * Defaults to `false`.\n * @property variant - Visual style of the checked side: `normal` (default) is\n * blue, `running` green for the running state and `loading` light blue for a\n * pending one. It does not move the thumb.\n * @property disabled - Whether the switch is disabled.\n * When disabled, the switch cannot be interacted with and displays a muted appearance.\n * In the disabled state, the thumb is hidden and only the state label is shown.\n * Defaults to `false`.\n * @property hasAlert - Whether to show an alert frame around the switch.\n * When true, displays a red alert border around the switch to indicate\n * an alarm or critical state.\n * Defaults to `false`.\n * @property hasDescription - Whether to show the description below the switch.\n * When true, displays the description text below the switch track.\n * The component's minimum height is maintained at the touch target size.\n * Defaults to `false`.\n * @property description - Description text displayed below the switch when `hasDescription` is true.\n * Use this to provide additional context about the switch's purpose or current state.\n * Defaults to `'Action description'`.\n * @availableWhen description hasDescription==true\n * @property size - Switch size: `regular` (default) has a 32px track height, `large` a 48px\n * one.\n * @slot checked-state-icon - Icon displayed in the checked (active) state area.\n * @slot unchecked-state-icon - Icon displayed in the unchecked (inactive) state area.\n * @slot checked-state-label - Label for the checked state (e.g., \"Running\", \"Enabled\").\n * @slot unchecked-state-label - Label for the unchecked state (e.g., \"Stopped\", \"Disabled\").\n * @slot to-checked-action-label - Action label on thumb when unchecked (e.g., \"Start\", \"Enable\").\n * @slot to-unchecked-action-label - Action label on thumb when checked (e.g., \"Stop\", \"Disable\").\n * @fires {ObcStartStopSwitchChangeEvent} change - Emitted when the switch is toggled via drag interaction.\n * @stable\n */\n@customElement('obc-start-stop-switch')\nexport class ObcStartStopSwitch extends LitElement {\n @property({type: Boolean, reflect: true}) checked = false;\n\n @property({type: String, reflect: true}) variant: StartStopSwitchVariant =\n StartStopSwitchVariant.normal;\n\n @property({type: String, reflect: true}) size: StartStopSwitchSize =\n StartStopSwitchSize.regular;\n\n @property({type: Boolean, reflect: true}) disabled = false;\n\n @property({type: Boolean}) hasAlert = false;\n\n @property({type: Boolean}) hasDescription = false;\n\n @property({type: String}) description = 'Action description';\n\n @state() private dragging = false;\n @state() private tmpChecked = false;\n\n private dragStartX = 0;\n private dragCurrentX = 0;\n private dragOffset = 0;\n private trackWidth = 0;\n private buttonWidth = 0;\n private resizeObserver?: ResizeObserver;\n\n @query('.button')\n private buttonRef?: HTMLElement;\n\n @query('.button-track')\n private trackRef?: HTMLElement;\n\n private onDragStart = (e: MouseEvent | TouchEvent) => {\n this.dragging = true;\n if (e instanceof MouseEvent) {\n this.dragStartX = e.clientX;\n } else {\n this.dragStartX = e.touches[0].clientX;\n }\n this.dragCurrentX = this.dragStartX;\n this.trackWidth = this.trackRef?.offsetWidth || 0;\n this.buttonWidth = this.buttonRef?.offsetWidth || 0;\n\n window.addEventListener('mousemove', this.onDragMove);\n window.addEventListener('touchmove', this.onDragMove, {passive: false});\n window.addEventListener('mouseup', this.onDragEnd);\n window.addEventListener('touchend', this.onDragEnd);\n };\n\n private onDragMove = (e: MouseEvent | TouchEvent) => {\n if (!this.dragging) return;\n let clientX;\n if (e instanceof MouseEvent) {\n clientX = e.clientX;\n } else {\n clientX = e.touches[0].clientX;\n e.preventDefault();\n }\n this.dragCurrentX = clientX;\n // clientX is viewport px; the thumb's `left`/`right` are CSS px, which an\n // ancestor `zoom` scales again, so the delta is divided by that zoom.\n this.dragOffset =\n (this.dragCurrentX - this.dragStartX) / (this.currentCSSZoom ?? 1);\n const percent = Math.abs(\n this.dragOffset / (this.trackWidth - this.buttonWidth)\n );\n this.tmpChecked = this.checked ? percent < 0.5 : percent > 0.5;\n this.requestUpdate();\n };\n\n private onDragEnd = () => {\n if (!this.dragging) return;\n this.dragging = false;\n\n const maxOffset = this.trackWidth - this.buttonWidth;\n const startPosition = this.checked ? maxOffset : 0;\n const newPosition = startPosition + this.dragOffset;\n const percent = newPosition / maxOffset;\n\n if (!this.checked && percent > DRAG_COMPLETE_THRESHOLD) {\n this.checked = true;\n this.dispatchChangeEvent();\n } else if (this.checked && percent < 1 - DRAG_COMPLETE_THRESHOLD) {\n this.checked = false;\n this.dispatchChangeEvent();\n }\n\n this.tmpChecked = this.checked;\n this.dragOffset = 0;\n window.removeEventListener('mousemove', this.onDragMove);\n window.removeEventListener('touchmove', this.onDragMove);\n window.removeEventListener('mouseup', this.onDragEnd);\n window.removeEventListener('touchend', this.onDragEnd);\n this.requestUpdate();\n };\n\n private handleKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Enter' && e.key !== ' ') return;\n e.preventDefault();\n if (this.disabled) return;\n this.checked = !this.checked;\n this.tmpChecked = this.checked;\n this.dispatchChangeEvent();\n };\n\n private dispatchChangeEvent() {\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: {checked: this.checked},\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private getButtonStyle() {\n if (!this.dragging) return '';\n\n // Keep same positioning mode as CSS to avoid subpixel issues when switching modes\n if (this.checked) {\n let right = -1 - this.dragOffset;\n const maxRight = this.trackWidth - this.buttonWidth + 1;\n right = clamp(right, -1, Math.max(-1, maxRight));\n return `right: ${right}px; left: auto; transition: none;`;\n } else {\n let left = -1 + this.dragOffset;\n const maxLeft = this.trackWidth - this.buttonWidth + 1;\n left = clamp(left, -1, Math.max(-1, maxLeft));\n return `left: ${left}px; right: auto; transition: none;`;\n }\n }\n\n override firstUpdated() {\n this.resizeObserver = new ResizeObserver(() => {\n this.trackWidth = this.trackRef?.offsetWidth || 0;\n this.buttonWidth = this.buttonRef?.offsetWidth || 0;\n });\n if (this.trackRef) this.resizeObserver.observe(this.trackRef);\n if (this.buttonRef) this.resizeObserver.observe(this.buttonRef);\n }\n\n override updated(changedProperties: Map<string, unknown>) {\n super.updated(changedProperties);\n // CSS Anchor Positioning (`right: anchor(center)`) on .button-track-checked\n // may not repaint when the thumb moves via a CSS transition (checked property change).\n // Force the browser to recalculate anchor positions after the transition completes.\n if (changedProperties.has('checked') && !this.dragging) {\n const trackChecked = this.renderRoot.querySelector(\n '.button-track-checked'\n ) as HTMLElement | null;\n const button = this.buttonRef;\n if (trackChecked && button) {\n const nudgeRepaint = () => {\n trackChecked.style.display = 'none';\n // Force a synchronous layout recalculation\n void trackChecked.offsetHeight;\n trackChecked.style.display = '';\n };\n // Wait one frame for the browser to start any CSS transitions,\n // then wait for all animations on the thumb to finish before nudging.\n requestAnimationFrame(() => {\n const animations = button.getAnimations();\n if (animations.length > 0) {\n Promise.allSettled(animations.map((a) => a.finished)).then(\n nudgeRepaint\n );\n } else {\n nudgeRepaint();\n }\n });\n }\n }\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.resizeObserver?.disconnect();\n window.removeEventListener('mousemove', this.onDragMove);\n window.removeEventListener('touchmove', this.onDragMove);\n window.removeEventListener('mouseup', this.onDragEnd);\n window.removeEventListener('touchend', this.onDragEnd);\n }\n\n override render() {\n const isChecked = this.checked;\n const forwardedAriaLabel = this.getAttribute('aria-label') ?? undefined;\n\n return html`\n <div class=\"outer-container\">\n <div\n class=${classMap({\n wrapper: true,\n checked: isChecked,\n unchecked: !isChecked,\n dragging: this.dragging,\n 'tmp-checked': this.tmpChecked && this.dragging,\n 'tmp-unchecked': !this.tmpChecked && this.dragging,\n disabled: this.disabled,\n 'has-alert': this.hasAlert,\n 'size-regular': this.size === 'regular',\n 'size-large': this.size === 'large',\n 'variant-normal': this.variant === 'normal',\n 'variant-running': this.variant === 'running',\n 'variant-loading': this.variant === 'loading',\n })}\n tabindex=${this.disabled ? -1 : 0}\n role=\"switch\"\n aria-checked=${isChecked ? 'true' : 'false'}\n aria-disabled=${this.disabled ? 'true' : 'false'}\n aria-label=${ifDefined(forwardedAriaLabel)}\n @keydown=${this.handleKeydown}\n >\n <div class=\"button-track\">\n <button\n class=\"button\"\n style=${this.getButtonStyle()}\n @mousedown=${this.disabled ? undefined : this.onDragStart}\n @touchstart=${\n this.disabled ? undefined : this.onDragStart\n }\n ?disabled=${this.disabled}\n tabindex=\"-1\"\n >\n ${\n !this.disabled\n ? html`\n <div class=\"button-visible\">\n <obi-arrow-right-google\n class=\"button-icon\"\n aria-hidden=\"true\"\n ></obi-arrow-right-google>\n <div class=\"button-label\">\n <slot\n name=${\n isChecked\n ? 'to-unchecked-action-label'\n : 'to-checked-action-label'\n }\n ></slot>\n </div>\n </div>\n `\n : ''\n }\n </button>\n ${\n !this.disabled\n ? html`<div class=\"button-track-checked\"></div>`\n : ''\n }\n <div class=\"checked state\">\n <slot name=\"checked-state-icon\"></slot>\n <div class=\"state-label\">\n <slot name=\"checked-state-label\"></slot>\n </div>\n </div>\n <div class=\"unchecked state\">\n <slot name=\"unchecked-state-icon\"></slot>\n <div class=\"state-label\">\n <slot name=\"unchecked-state-label\"></slot>\n </div>\n </div>\n </div>\n ${this.hasAlert ? html`<div class=\"alert-frame\"></div>` : ''}\n </div>\n ${\n this.hasDescription\n ? html`<div class=\"description\">${this.description}</div>`\n : ''\n }\n </div>\n </div>\n </div>\n </div>\n </div>\n `;\n }\n\n static override styles = unsafeCSS(componentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-start-stop-switch': ObcStartStopSwitch;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAY,yBAAL,yBAAA,wBAAA;CACL,uBAAA,YAAA;CACA,uBAAA,aAAA;CACA,uBAAA,aAAA;;AACF,EAAA,CAAA,CAAA;;;;;;AAOA,IAAY,sBAAL,yBAAA,qBAAA;CACL,oBAAA,aAAA;CACA,oBAAA,WAAA;;AACF,EAAA,CAAA,CAAA;;;;;AAUA,IAAM,0BAA0B;AAwGzB,IAAM,qBAAN,MAAM,2BAA2B,WAAW;;;EACG,KAAA,UAAA;;;EAQC,KAAA,WAAA;EAEf,KAAA,WAAA;EAEM,KAAA,iBAAA;EAEJ,KAAA,cAAA;EAEZ,KAAA,WAAA;EACE,KAAA,aAAA;EAET,KAAA,aAAA;EACE,KAAA,eAAA;EACF,KAAA,aAAA;EACA,KAAA,aAAA;EACC,KAAA,cAAA;EASC,KAAA,eAAA,MAA+B;GACpD,KAAK,WAAW;GAChB,IAAI,aAAa,YACf,KAAK,aAAa,EAAE;QAEpB,KAAK,aAAa,EAAE,QAAQ,EAAE,CAAC;GAEjC,KAAK,eAAe,KAAK;GACzB,KAAK,aAAa,KAAK,UAAU,eAAe;GAChD,KAAK,cAAc,KAAK,WAAW,eAAe;GAElD,OAAO,iBAAiB,aAAa,KAAK,UAAU;GACpD,OAAO,iBAAiB,aAAa,KAAK,YA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D,GACL;;;;;;;CAOf;;EAEyB,KAAA,SAAA,UAAUA,yBAAc;;AACnD;AAvRGC,WAAA,CAAA,SAAS;CAAC,MAAM;CAAS,SAAS;AAAI,CAAC,CAAA,GAAA,mBAAA,WAAA,WAAA,KAAA,CAAA;AAEvCA,WAAA,CAAA,SAAS;CAAC,MAAM;CAAQ,SAAS;AAAI,CAAC,CAAA,GAAA,mBAAA,WAAA,WAAA,KAAA,CAAA;AAGtCA,WAAA,CAAA,SAAS;CAAC,MAAM;CAAQ,SAAS;AAAI,CAAC,CAAA,GAAA,mBAAA,WAAA,QAAA,KAAA,CAAA;AAGtCA,WAAA,CAAA,SAAS;CAAC,MAAM;CAAS,SAAS;AAAI,CAAC,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AAEvCA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AAExBA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,mBAAA,WAAA,kBAAA,KAAA,CAAA;AAExBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,mBAAA,WAAA,eAAA,KAAA,CAAA;AAEvBA,WAAA,CAAA,MAAM,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AACNA,WAAA,CAAA,MAAM,CAAA,GAAA,mBAAA,WAAA,cAAA,KAAA,CAAA;AASNA,WAAA,CAAA,MAAM,SAAS,CAAA,GAAA,mBAAA,WAAA,aAAA,KAAA,CAAA;AAGfA,WAAA,CAAA,MAAM,eAAe,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AA/BvB,qBAAAA,WAAA,CAAA,cAAc,uBAAuB,CAAA,GAAA,kBAAA"}
1
+ {"version":3,"file":"start-stop-switch.js","names":["componentStyle","_decorate"],"sources":["../../../src/components/start-stop-switch/start-stop-switch.ts"],"sourcesContent":["import {LitElement, html, unsafeCSS} from 'lit';\nimport {property, query, state} from 'lit/decorators.js';\nimport componentStyle from './start-stop-switch.css?inline';\nimport {classMap} from 'lit/directives/class-map.js';\nimport {ifDefined} from 'lit/directives/if-defined.js';\nimport '../../icons/icon-arrow-right-google.js';\nimport {customElement} from '../../decorator.js';\nimport {clamp} from '../../svghelpers/math.js';\n\n/**\n * The visual variant for the start-stop switch when checked.\n * - `normal`: Standard blue appearance (default)\n * - `running`: Green appearance indicating motor/process is running\n * - `loading`: Light blue appearance indicating a pending/loading state\n */\nexport enum StartStopSwitchVariant {\n normal = 'normal',\n running = 'running',\n loading = 'loading',\n}\n\n/**\n * The possible sizes for the start-stop switch.\n * - `regular`: Standard size with 32px track height\n * - `large`: Larger size with 48px track height\n */\nexport enum StartStopSwitchSize {\n regular = 'regular',\n large = 'large',\n}\n\nexport type ObcStartStopSwitchChangeEvent = CustomEvent<{\n checked: boolean;\n}>;\n\n/**\n * Threshold for completing a drag gesture (90% of track width).\n * User must drag past this threshold to toggle the switch state.\n */\nconst DRAG_COMPLETE_THRESHOLD = 0.9;\n\n/**\n * `<obc-start-stop-switch>` – A two-state draggable toggle switch for significant binary actions like start/stop or enable/disable.\n *\n * This switch provides a visually distinct, draggable toggle for binary actions where both states need to be explicitly labeled and reinforced. Unlike a simple on/off toggle, it displays both the current state label and an action label on the draggable thumb, making it ideal for consequential actions where user awareness is critical.\n *\n * ### Features\n * - **Drag-to-toggle interaction:** Users must drag the thumb across the track to change state (90% threshold required). This deliberate interaction prevents accidental toggles.\n * - **Dual state labels:** Displays both a state label (e.g., \"Running\", \"Stopped\") and an action label on the thumb (e.g., \"Start\", \"Stop\").\n * - **Visual variants:**\n * - `normal`: Standard blue appearance when checked (default)\n * - `running`: Green appearance indicating an active process (e.g., motor running)\n * - `loading`: Light blue appearance indicating a pending/transitional state\n * - **Size options:** `regular` (32px track height) or `large` (48px track height, matching touch target).\n * - **Alert frame:** Optional red border to indicate alarm or critical state.\n * - **Description text:** Optional text below the switch for additional context.\n * - **Animated transitions:** Smooth CSS transitions for thumb movement and state changes.\n * - **Keyboard accessible:** The switch is focusable and follows the ARIA switch pattern — `Enter` or `Space` toggles the state and fires the same `change` event as a completed drag.\n *\n * ### Usage Guidelines\n * Use `<obc-start-stop-switch>` when you need a prominent control for toggling between two mutually exclusive states where:\n * - Both states should be explicitly labeled (not just \"on/off\")\n * - The action has significant consequences (starting a motor, enabling a system)\n * - Accidental activation should be prevented through deliberate drag interaction\n *\n * Avoid using this component for simple preferences or settings where a standard `<obc-switch>` or checkbox would suffice. This component is best suited for operational controls where the user must be aware of both the current state and the action they're about to take.\n *\n * **Related components:** For simple binary toggles without labels, use `<obc-switch>`. For grouped selections, use `<obc-radio>` or `<obc-checkbox>`.\n *\n * ### Slots\n * | Slot Name | Renders When... | Purpose |\n * |---------------------------|----------------------|------------------------------------------------------------|\n * | checked-state-icon | Always (if provided) | Icon displayed in the checked state area. |\n * | unchecked-state-icon | Always (if provided) | Icon displayed in the unchecked state area. |\n * | checked-state-label | Always | Label shown when switch is in checked position. |\n * | unchecked-state-label | Always | Label shown when switch is in unchecked position. |\n * | to-checked-action-label | When unchecked | Action label on thumb prompting user to activate. |\n * | to-unchecked-action-label | When checked | Action label on thumb prompting user to deactivate. |\n *\n * ### Events\n * - `change` – Fired when the switch state changes after a successful drag. The event detail contains `{checked: boolean}` indicating the new state.\n *\n * ### Best Practices\n * - Keep labels concise (1-2 words) to fit within the track width.\n * - Use meaningful action verbs: \"Start/Stop\", \"Enable/Disable\", \"Request/Release\".\n * - Use the `running` variant to indicate an actively running process.\n * - Use the `loading` variant during async operations before transitioning to `running` or `normal`.\n * - Consider using `hasAlert` when the switch controls a critical system in alarm state.\n * - The accessible name is computed from the slotted labels; provide `aria-label` on the host when those labels alone are not descriptive (`aria-labelledby` is not supported — ID references cannot cross the shadow boundary).\n *\n * ### Example\n * ```html\n * <obc-start-stop-switch checked variant=\"running\">\n * <div slot=\"checked-state-icon\"><obi-placeholder></obi-placeholder></div>\n * <div slot=\"checked-state-label\">Running</div>\n * <div slot=\"unchecked-state-label\">Stopped</div>\n * <div slot=\"to-checked-action-label\">Start</div>\n * <div slot=\"to-unchecked-action-label\">Stop</div>\n * </obc-start-stop-switch>\n * ```\n *\n * ### Keyboard\n * [APG Switch](https://www.w3.org/WAI/ARIA/apg/patterns/switch/): `Space` and\n * `Enter` toggle it. The knob inside is a drag handle for pointers, not a\n * control of its own: a switch announces its content as one name, so nothing\n * inside it may take focus. The description, when shown, describes the switch.\n *\n * Left out: nothing.\n *\n * @property checked - Whether the switch is in the checked (active) state.\n * When checked, the thumb is on the right side.\n * When unchecked, the thumb is on the left side.\n * Defaults to `false`.\n * @property variant - Visual style of the checked side: `normal` (default) is\n * blue, `running` green for the running state and `loading` light blue for a\n * pending one. It does not move the thumb.\n * @property disabled - Whether the switch is disabled.\n * When disabled, the switch cannot be interacted with and displays a muted appearance.\n * In the disabled state, the thumb is hidden and only the state label is shown.\n * Defaults to `false`.\n * @property hasAlert - Whether to show an alert frame around the switch.\n * When true, displays a red alert border around the switch to indicate\n * an alarm or critical state.\n * Defaults to `false`.\n * @property hasDescription - Whether to show the description below the switch.\n * When true, displays the description text below the switch track.\n * The component's minimum height is maintained at the touch target size.\n * Defaults to `false`.\n * @property description - Description text displayed below the switch when `hasDescription` is true.\n * Use this to provide additional context about the switch's purpose or current state.\n * Defaults to `'Action description'`.\n * @availableWhen description hasDescription==true\n * @property size - Switch size: `regular` (default) has a 32px track height, `large` a 48px\n * one.\n * @slot checked-state-icon - Icon displayed in the checked (active) state area.\n * @slot unchecked-state-icon - Icon displayed in the unchecked (inactive) state area.\n * @slot checked-state-label - Label for the checked state (e.g., \"Running\", \"Enabled\").\n * @slot unchecked-state-label - Label for the unchecked state (e.g., \"Stopped\", \"Disabled\").\n * @slot to-checked-action-label - Action label on thumb when unchecked (e.g., \"Start\", \"Enable\").\n * @slot to-unchecked-action-label - Action label on thumb when checked (e.g., \"Stop\", \"Disable\").\n * @fires {ObcStartStopSwitchChangeEvent} change - Emitted when the switch is toggled via drag interaction.\n * @stable\n */\n@customElement('obc-start-stop-switch')\nexport class ObcStartStopSwitch extends LitElement {\n @property({type: Boolean, reflect: true}) checked = false;\n\n @property({type: String, reflect: true}) variant: StartStopSwitchVariant =\n StartStopSwitchVariant.normal;\n\n @property({type: String, reflect: true}) size: StartStopSwitchSize =\n StartStopSwitchSize.regular;\n\n @property({type: Boolean, reflect: true}) disabled = false;\n\n @property({type: Boolean}) hasAlert = false;\n\n @property({type: Boolean}) hasDescription = false;\n\n @property({type: String}) description = 'Action description';\n\n @state() private dragging = false;\n @state() private tmpChecked = false;\n\n private dragStartX = 0;\n private dragCurrentX = 0;\n private dragOffset = 0;\n private trackWidth = 0;\n private buttonWidth = 0;\n private resizeObserver?: ResizeObserver;\n\n @query('.button')\n private buttonRef?: HTMLElement;\n\n @query('.button-track')\n private trackRef?: HTMLElement;\n\n private onDragStart = (e: MouseEvent | TouchEvent) => {\n this.dragging = true;\n if (e instanceof MouseEvent) {\n this.dragStartX = e.clientX;\n } else {\n this.dragStartX = e.touches[0].clientX;\n }\n this.dragCurrentX = this.dragStartX;\n this.trackWidth = this.trackRef?.offsetWidth || 0;\n this.buttonWidth = this.buttonRef?.offsetWidth || 0;\n\n window.addEventListener('mousemove', this.onDragMove);\n window.addEventListener('touchmove', this.onDragMove, {passive: false});\n window.addEventListener('mouseup', this.onDragEnd);\n window.addEventListener('touchend', this.onDragEnd);\n };\n\n private onDragMove = (e: MouseEvent | TouchEvent) => {\n if (!this.dragging) return;\n let clientX;\n if (e instanceof MouseEvent) {\n clientX = e.clientX;\n } else {\n clientX = e.touches[0].clientX;\n e.preventDefault();\n }\n this.dragCurrentX = clientX;\n // clientX is viewport px; the thumb's `left`/`right` are CSS px, which an\n // ancestor `zoom` scales again, so the delta is divided by that zoom.\n this.dragOffset =\n (this.dragCurrentX - this.dragStartX) / (this.currentCSSZoom ?? 1);\n const percent = Math.abs(\n this.dragOffset / (this.trackWidth - this.buttonWidth)\n );\n this.tmpChecked = this.checked ? percent < 0.5 : percent > 0.5;\n this.requestUpdate();\n };\n\n private onDragEnd = () => {\n if (!this.dragging) return;\n this.dragging = false;\n\n const maxOffset = this.trackWidth - this.buttonWidth;\n const startPosition = this.checked ? maxOffset : 0;\n const newPosition = startPosition + this.dragOffset;\n const percent = newPosition / maxOffset;\n\n // A switch disabled mid-drag ends the drag without a change, as a key press would.\n const canCommit = !this.disabled;\n if (canCommit && !this.checked && percent > DRAG_COMPLETE_THRESHOLD) {\n this.checked = true;\n this.dispatchChangeEvent();\n } else if (\n canCommit &&\n this.checked &&\n percent < 1 - DRAG_COMPLETE_THRESHOLD\n ) {\n this.checked = false;\n this.dispatchChangeEvent();\n }\n\n this.tmpChecked = this.checked;\n this.dragOffset = 0;\n window.removeEventListener('mousemove', this.onDragMove);\n window.removeEventListener('touchmove', this.onDragMove);\n window.removeEventListener('mouseup', this.onDragEnd);\n window.removeEventListener('touchend', this.onDragEnd);\n this.requestUpdate();\n };\n\n private handleKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Enter' && e.key !== ' ') return;\n e.preventDefault();\n if (this.disabled) return;\n this.checked = !this.checked;\n this.tmpChecked = this.checked;\n this.dispatchChangeEvent();\n };\n\n private dispatchChangeEvent() {\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: {checked: this.checked},\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private getButtonStyle() {\n if (!this.dragging) return '';\n\n // Keep same positioning mode as CSS to avoid subpixel issues when switching modes\n if (this.checked) {\n let right = -1 - this.dragOffset;\n const maxRight = this.trackWidth - this.buttonWidth + 1;\n right = clamp(right, -1, Math.max(-1, maxRight));\n return `right: ${right}px; left: auto; transition: none;`;\n } else {\n let left = -1 + this.dragOffset;\n const maxLeft = this.trackWidth - this.buttonWidth + 1;\n left = clamp(left, -1, Math.max(-1, maxLeft));\n return `left: ${left}px; right: auto; transition: none;`;\n }\n }\n\n override firstUpdated() {\n this.resizeObserver = new ResizeObserver(() => {\n this.trackWidth = this.trackRef?.offsetWidth || 0;\n this.buttonWidth = this.buttonRef?.offsetWidth || 0;\n });\n if (this.trackRef) this.resizeObserver.observe(this.trackRef);\n if (this.buttonRef) this.resizeObserver.observe(this.buttonRef);\n }\n\n override updated(changedProperties: Map<string, unknown>) {\n super.updated(changedProperties);\n // CSS Anchor Positioning (`right: anchor(center)`) on .button-track-checked\n // may not repaint when the thumb moves via a CSS transition (checked property change).\n // Force the browser to recalculate anchor positions after the transition completes.\n if (changedProperties.has('checked') && !this.dragging) {\n const trackChecked = this.renderRoot.querySelector(\n '.button-track-checked'\n ) as HTMLElement | null;\n const button = this.buttonRef;\n if (trackChecked && button) {\n const nudgeRepaint = () => {\n trackChecked.style.display = 'none';\n // Force a synchronous layout recalculation\n void trackChecked.offsetHeight;\n trackChecked.style.display = '';\n };\n // Wait one frame for the browser to start any CSS transitions,\n // then wait for all animations on the thumb to finish before nudging.\n requestAnimationFrame(() => {\n const animations = button.getAnimations();\n if (animations.length > 0) {\n Promise.allSettled(animations.map((a) => a.finished)).then(\n nudgeRepaint\n );\n } else {\n nudgeRepaint();\n }\n });\n }\n }\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.resizeObserver?.disconnect();\n window.removeEventListener('mousemove', this.onDragMove);\n window.removeEventListener('touchmove', this.onDragMove);\n window.removeEventListener('mouseup', this.onDragEnd);\n window.removeEventListener('touchend', this.onDragEnd);\n }\n\n override render() {\n const isChecked = this.checked;\n const forwardedAriaLabel = this.getAttribute('aria-label') ?? undefined;\n\n return html`\n <div class=\"outer-container\">\n <div\n class=${classMap({\n wrapper: true,\n checked: isChecked,\n unchecked: !isChecked,\n dragging: this.dragging,\n 'tmp-checked': this.tmpChecked && this.dragging,\n 'tmp-unchecked': !this.tmpChecked && this.dragging,\n disabled: this.disabled,\n 'has-alert': this.hasAlert,\n 'size-regular': this.size === 'regular',\n 'size-large': this.size === 'large',\n 'variant-normal': this.variant === 'normal',\n 'variant-running': this.variant === 'running',\n 'variant-loading': this.variant === 'loading',\n })}\n tabindex=${this.disabled ? -1 : 0}\n role=\"switch\"\n aria-checked=${isChecked ? 'true' : 'false'}\n aria-disabled=${this.disabled ? 'true' : 'false'}\n aria-label=${ifDefined(forwardedAriaLabel)}\n aria-describedby=${ifDefined(\n this.hasDescription ? 'description' : undefined\n )}\n @keydown=${this.handleKeydown}\n >\n <div class=\"button-track\">\n <div\n class=\"button\"\n style=${this.getButtonStyle()}\n @mousedown=${this.disabled ? undefined : this.onDragStart}\n @touchstart=${\n this.disabled ? undefined : this.onDragStart\n }\n >\n ${\n !this.disabled\n ? html`\n <div class=\"button-visible\">\n <obi-arrow-right-google\n class=\"button-icon\"\n aria-hidden=\"true\"\n ></obi-arrow-right-google>\n <div class=\"button-label\">\n <slot\n name=${\n isChecked\n ? 'to-unchecked-action-label'\n : 'to-checked-action-label'\n }\n ></slot>\n </div>\n </div>\n `\n : ''\n }\n </div>\n ${\n !this.disabled\n ? html`<div class=\"button-track-checked\"></div>`\n : ''\n }\n <div class=\"checked state\">\n <slot name=\"checked-state-icon\"></slot>\n <div class=\"state-label\">\n <slot name=\"checked-state-label\"></slot>\n </div>\n </div>\n <div class=\"unchecked state\">\n <slot name=\"unchecked-state-icon\"></slot>\n <div class=\"state-label\">\n <slot name=\"unchecked-state-label\"></slot>\n </div>\n </div>\n </div>\n ${this.hasAlert ? html`<div class=\"alert-frame\"></div>` : ''}\n </div>\n ${\n this.hasDescription\n ? html`<div class=\"description\" id=\"description\">\n ${this.description}\n </div>`\n : ''\n }\n </div>\n </div>\n </div>\n </div>\n </div>\n `;\n }\n\n static override styles = unsafeCSS(componentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-start-stop-switch': ObcStartStopSwitch;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAY,yBAAL,yBAAA,wBAAA;CACL,uBAAA,YAAA;CACA,uBAAA,aAAA;CACA,uBAAA,aAAA;;AACF,EAAA,CAAA,CAAA;;;;;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AAEvCA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AAExBA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,mBAAA,WAAA,kBAAA,KAAA,CAAA;AAExBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,mBAAA,WAAA,eAAA,KAAA,CAAA;AAEvBA,WAAA,CAAA,MAAM,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AACNA,WAAA,CAAA,MAAM,CAAA,GAAA,mBAAA,WAAA,cAAA,KAAA,CAAA;AASNA,WAAA,CAAA,MAAM,SAAS,CAAA,GAAA,mBAAA,WAAA,aAAA,KAAA,CAAA;AAGfA,WAAA,CAAA,MAAM,eAAe,CAAA,GAAA,mBAAA,WAAA,YAAA,KAAA,CAAA;AA/BvB,qBAAAA,WAAA,CAAA,cAAc,uBAAuB,CAAA,GAAA,kBAAA"}
@@ -1,6 +1,7 @@
1
1
  import {Meta, Markdown} from '@storybook/addon-docs/blocks';
2
2
  import adviceInput from './migration-guide-2-2/advice-input.md?raw';
3
3
  import renamedProperties from './migration-guide-2-2/renamed-properties.md?raw';
4
+ import renamedSlots from './migration-guide-2-2/renamed-slots.md?raw';
4
5
  import renamedTypes from './migration-guide-2-2/renamed-types.md?raw';
5
6
 
6
7
  <Meta title="Introduction/Migration Guide 2.1 to 2.2" />
@@ -16,8 +17,9 @@ Coming from 2.0? Read [Migrating from 2.0 to 2.1](?path=/docs/introduction-migra
16
17
  1. [Advice Input](#advice-input)
17
18
  2. [Renamed Properties](#renamed-properties)
18
19
  3. [Renamed Types](#renamed-types)
19
- 4. [Behaviour Changes](#behaviour-changes)
20
- 5. [What Moved on Screen](#what-moved-on-screen)
20
+ 4. [Renamed Slots](#renamed-slots)
21
+ 5. [Behaviour Changes](#behaviour-changes)
22
+ 6. [What Moved on Screen](#what-moved-on-screen)
21
23
 
22
24
  ## Advice Input
23
25
 
@@ -51,6 +53,12 @@ The instrument-specific types are aliases of the two shared ones and are depreca
51
53
 
52
54
  <Markdown>{renamedTypes}</Markdown>
53
55
 
56
+ ## Renamed Slots
57
+
58
+ Five slots of `obc-command-menu` were spelled `toogle-…`. The `toggle-…` names replace them; an old name still renders while its new slot is empty, and goes in the next major release ([#1370](https://github.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents/issues/1370)).
59
+
60
+ <Markdown>{renamedSlots}</Markdown>
61
+
54
62
  ## Behaviour Changes
55
63
 
56
64
  These need no code change, but an instrument shows something different for the same input.
@@ -0,0 +1,7 @@
1
+ | Element | 2.1 | 2.2 |
2
+ | ------------------ | ----------------------------------- | ----------------------------------- |
3
+ | `obc-command-menu` | `toogle-action-to-in-command-label` | `toggle-action-to-in-command-label` |
4
+ | `obc-command-menu` | `toogle-action-to-no-command-label` | `toggle-action-to-no-command-label` |
5
+ | `obc-command-menu` | `toogle-state-in-command-label` | `toggle-state-in-command-label` |
6
+ | `obc-command-menu` | `toogle-state-no-command-label` | `toggle-state-no-command-label` |
7
+ | `obc-command-menu` | `toogle-state-in-command-icon` | `toggle-state-in-command-icon` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oicl/openbridge-webcomponents-full-bundle",
3
- "version": "2.2.0-next.19",
3
+ "version": "2.2.0-next.20",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,75 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import './button.js';
3
+ import {ObcButton} from './button.js';
4
+ import {render} from 'vitest-browser-lit';
5
+ import {html} from 'lit';
6
+
7
+ describe('obc-button accessible name', () => {
8
+ async function setup(template: ReturnType<typeof html>) {
9
+ const screen = render(template);
10
+ const el = screen.baseElement.querySelector('obc-button') as ObcButton;
11
+ await el.updateComplete;
12
+ return el;
13
+ }
14
+
15
+ function control(el: ObcButton) {
16
+ return el.shadowRoot!.querySelector<HTMLElement>('.wrapper')!;
17
+ }
18
+
19
+ it('forwards the host aria-label to the shadow button', async () => {
20
+ const el = await setup(
21
+ html`<obc-button aria-label="Cancel the pending request"
22
+ >Pending</obc-button
23
+ >`
24
+ );
25
+
26
+ expect(control(el).tagName).toBe('BUTTON');
27
+ expect(control(el).getAttribute('aria-label')).toBe(
28
+ 'Cancel the pending request'
29
+ );
30
+ });
31
+
32
+ it('forwards it to the anchor when href is set', async () => {
33
+ const el = await setup(
34
+ html`<obc-button href="#settings" aria-label="Open the settings"
35
+ >Settings</obc-button
36
+ >`
37
+ );
38
+
39
+ expect(control(el).tagName).toBe('A');
40
+ expect(control(el).getAttribute('aria-label')).toBe('Open the settings');
41
+ });
42
+
43
+ it('follows later changes to the host aria-label', async () => {
44
+ const el = await setup(
45
+ html`<obc-button aria-label="Pending, press to cancel"
46
+ >Pending</obc-button
47
+ >`
48
+ );
49
+
50
+ el.setAttribute('aria-label', 'Confirmed');
51
+ await el.updateComplete;
52
+ expect(control(el).getAttribute('aria-label')).toBe('Confirmed');
53
+
54
+ el.removeAttribute('aria-label');
55
+ await el.updateComplete;
56
+ expect(control(el).hasAttribute('aria-label')).toBe(false);
57
+ });
58
+
59
+ it('leaves the name to the slotted text when no aria-label is set', async () => {
60
+ const el = await setup(html`<obc-button>Save</obc-button>`);
61
+
62
+ expect(control(el).hasAttribute('aria-label')).toBe(false);
63
+ });
64
+
65
+ it('does not forward aria-labelledby, which cannot resolve across the shadow boundary', async () => {
66
+ const el = await setup(
67
+ html`<obc-button aria-label="Save" aria-labelledby="external-label"
68
+ >Save</obc-button
69
+ >`
70
+ );
71
+
72
+ expect(control(el).hasAttribute('aria-labelledby')).toBe(false);
73
+ expect(control(el).getAttribute('aria-label')).toBe('Save');
74
+ });
75
+ });
@@ -3,6 +3,7 @@ import {ButtonVariant, ObcButton, segmentPosition} from './button.js';
3
3
  import './button.js';
4
4
  import {iconIds, iconIdToIconHtml} from '../../storybook-util.js';
5
5
  import {html} from 'lit';
6
+ import {ifDefined} from 'lit/directives/if-defined.js';
6
7
 
7
8
  const meta: Meta<typeof ObcButton> = {
8
9
  title: 'UI Components/Buttons/Button',
@@ -70,6 +71,7 @@ const meta: Meta<typeof ObcButton> = {
70
71
  .showTrailingIcon=${args.showTrailingIcon}
71
72
  .disabled=${args.disabled}
72
73
  .segmentPosition=${args.segmentPosition}
74
+ aria-label=${ifDefined(args.ariaLabel ?? undefined)}
73
75
  >
74
76
  ${
75
77
  args.showLeadingIcon
@@ -79,6 +79,7 @@ export enum segmentPosition {
79
79
  * - `href` (string): If set, renders as an anchor link.
80
80
  * - `target` (string): Link target (only applies when `href` is set).
81
81
  * - `segmentPosition` (segmentPosition): Visual grouping for segmented button layouts.
82
+ * - `ariaLabel` (string): Accessible name of the button, in place of its slotted text.
82
83
  *
83
84
  * ### Best Practices
84
85
  * - Always provide a clear label for accessibility, even if using only icons.
@@ -110,6 +111,11 @@ export enum segmentPosition {
110
111
  * @property segmentPosition - Position within a segmented button group: `single` stands alone, `start`,
111
112
  * `middle` and `end` shape the button for the first, an inner and the last
112
113
  * segment.
114
+ * @property ariaLabel - Accessible name forwarded to the inner `<button>` or `<a>`, mapped to the
115
+ * `aria-label` attribute. It replaces the slotted text as the name, for a button whose text
116
+ * describes a state rather than the action it takes. Start it with the visible text, so a user
117
+ * who speaks the label they see still reaches the button. `aria-labelledby` is not supported:
118
+ * ID references cannot cross the shadow boundary.
113
119
  * @fires click - Fired when the button is clicked (if not disabled).
114
120
  *
115
121
  * @slot - Default slot for button label text (required for accessibility)
@@ -136,6 +142,9 @@ export class ObcButton extends LitElement {
136
142
  @property({type: String}) segmentPosition: segmentPosition =
137
143
  segmentPosition.single;
138
144
 
145
+ @property({type: String, attribute: 'aria-label'})
146
+ override ariaLabel: string | null = null;
147
+
139
148
  private renderLeadingIcon() {
140
149
  if (this.showLeadingIcon) {
141
150
  return html`
@@ -174,6 +183,7 @@ export class ObcButton extends LitElement {
174
183
  ?disabled=${this.disabled}
175
184
  href=${ifDefined(this.href)}
176
185
  target=${ifDefined(this.target)}
186
+ aria-label=${ifDefined(this.ariaLabel ?? undefined)}
177
187
  part="wrapper"
178
188
  >
179
189
  <div class="visible-wrapper" part="visible-wrapper">
@@ -0,0 +1,125 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import './command-menu.js';
3
+ import {ObcCommandMenu} from './command-menu.js';
4
+ import type {ObcStartStopSwitch} from '../start-stop-switch/start-stop-switch.js';
5
+ import {render} from 'vitest-browser-lit';
6
+ import {html} from 'lit';
7
+
8
+ async function setup(template: ReturnType<typeof html>) {
9
+ const screen = render(template);
10
+ const el = screen.baseElement.querySelector(
11
+ 'obc-command-menu'
12
+ ) as ObcCommandMenu;
13
+ await el.updateComplete;
14
+ const toggle = el.shadowRoot!.querySelector(
15
+ 'obc-start-stop-switch'
16
+ ) as ObcStartStopSwitch;
17
+ await toggle.updateComplete;
18
+ return {el, toggle};
19
+ }
20
+
21
+ /** What the switch slot named `name` shows, through the menu's nested slots. */
22
+ function shown(el: ObcCommandMenu, name: string) {
23
+ const slot = el.shadowRoot!.querySelector<HTMLSlotElement>(
24
+ `slot[name="${name}"]`
25
+ )!;
26
+ return slot
27
+ .assignedElements({flatten: true})
28
+ .map((node) => node.textContent?.trim() || node.localName);
29
+ }
30
+
31
+ describe('obc-command-menu toggle slots', () => {
32
+ it('renders the toggle-… slots in the switch', async () => {
33
+ const {el} = await setup(html`
34
+ <obc-command-menu>
35
+ <div slot="toggle-action-to-in-command-label">Take</div>
36
+ <div slot="toggle-action-to-no-command-label">Release</div>
37
+ <div slot="toggle-state-in-command-label">In CMD</div>
38
+ <div slot="toggle-state-no-command-label">Aft</div>
39
+ <span slot="toggle-state-in-command-icon">icon</span>
40
+ </obc-command-menu>
41
+ `);
42
+
43
+ expect(shown(el, 'toggle-action-to-in-command-label')).toEqual(['Take']);
44
+ expect(shown(el, 'toggle-action-to-no-command-label')).toEqual(['Release']);
45
+ expect(shown(el, 'toggle-state-in-command-label')).toEqual(['In CMD']);
46
+ expect(shown(el, 'toggle-state-no-command-label')).toEqual(['Aft']);
47
+ expect(shown(el, 'toggle-state-in-command-icon')).toEqual(['icon']);
48
+ });
49
+
50
+ it('still renders the deprecated toogle-… names while the new slot is empty', async () => {
51
+ const {el} = await setup(html`
52
+ <obc-command-menu>
53
+ <div slot="toogle-action-to-in-command-label">Take</div>
54
+ <div slot="toogle-action-to-no-command-label">Release</div>
55
+ <div slot="toogle-state-in-command-label">In CMD</div>
56
+ <div slot="toogle-state-no-command-label">Aft</div>
57
+ <span slot="toogle-state-in-command-icon">icon</span>
58
+ </obc-command-menu>
59
+ `);
60
+
61
+ expect(shown(el, 'toggle-action-to-in-command-label')).toEqual(['Take']);
62
+ expect(shown(el, 'toggle-action-to-no-command-label')).toEqual(['Release']);
63
+ expect(shown(el, 'toggle-state-in-command-label')).toEqual(['In CMD']);
64
+ expect(shown(el, 'toggle-state-no-command-label')).toEqual(['Aft']);
65
+ expect(shown(el, 'toggle-state-in-command-icon')).toEqual(['icon']);
66
+ });
67
+
68
+ it('prefers the toggle-… slot when both spellings are filled', async () => {
69
+ const {el} = await setup(html`
70
+ <obc-command-menu>
71
+ <div slot="toogle-action-to-in-command-label">Old</div>
72
+ <div slot="toggle-action-to-in-command-label">New</div>
73
+ </obc-command-menu>
74
+ `);
75
+
76
+ expect(shown(el, 'toggle-action-to-in-command-label')).toEqual(['New']);
77
+ });
78
+
79
+ it('falls back to the command-in icon when neither icon slot is filled', async () => {
80
+ const {el} = await setup(html`<obc-command-menu></obc-command-menu>`);
81
+
82
+ expect(shown(el, 'toggle-state-in-command-icon')).toEqual([
83
+ 'obi-command-in',
84
+ ]);
85
+ });
86
+ });
87
+
88
+ describe('obc-command-menu switch state', () => {
89
+ it('leaves the switch enabled and without a caption by default', async () => {
90
+ const {toggle} = await setup(html`<obc-command-menu></obc-command-menu>`);
91
+
92
+ expect(toggle.disabled).toBe(false);
93
+ expect(toggle.shadowRoot!.querySelector('.description')).toBeNull();
94
+ });
95
+
96
+ it('forwards disabled to the switch', async () => {
97
+ const {el, toggle} = await setup(
98
+ html`<obc-command-menu disabled></obc-command-menu>`
99
+ );
100
+
101
+ expect(toggle.disabled).toBe(true);
102
+
103
+ el.disabled = false;
104
+ await el.updateComplete;
105
+ expect(toggle.disabled).toBe(false);
106
+ });
107
+
108
+ it('shows the action description under the switch', async () => {
109
+ const {el, toggle} = await setup(
110
+ html`<obc-command-menu
111
+ hasActionDescription
112
+ actionDescription="Take command of the DP system"
113
+ ></obc-command-menu>`
114
+ );
115
+
116
+ expect(
117
+ toggle.shadowRoot!.querySelector('.description')?.textContent?.trim()
118
+ ).toBe('Take command of the DP system');
119
+
120
+ el.hasActionDescription = false;
121
+ await el.updateComplete;
122
+ await toggle.updateComplete;
123
+ expect(toggle.shadowRoot!.querySelector('.description')).toBeNull();
124
+ });
125
+ });
@@ -20,6 +20,9 @@ import '../../icons/icon-joystick.js';
20
20
  * Default: `false`.
21
21
  * @property showLocation - Forwarded to `<obc-command-menu>` to
22
22
  * hide or show the command location slot. Default: `true`.
23
+ * @property disabled - Forwarded to `<obc-command-menu>`.
24
+ * @property hasActionDescription - Forwarded to `<obc-command-menu>`.
25
+ * @property actionDescription - Forwarded to `<obc-command-menu>`.
23
26
  *
24
27
  * @example
25
28
  * ```html
@@ -32,6 +35,9 @@ import '../../icons/icon-joystick.js';
32
35
  class CommandMenuStoryWrapper extends LitElement {
33
36
  @property({type: Boolean}) inCommand = false;
34
37
  @property({type: Boolean, attribute: false}) showLocation: boolean = true;
38
+ @property({type: Boolean}) disabled = false;
39
+ @property({type: Boolean}) hasActionDescription = false;
40
+ @property({type: String}) actionDescription = 'Action description';
35
41
 
36
42
  override createRenderRoot() {
37
43
  return this;
@@ -46,6 +52,9 @@ class CommandMenuStoryWrapper extends LitElement {
46
52
  <obc-command-menu
47
53
  .inCommand=${this.inCommand}
48
54
  .showLocation=${this.showLocation}
55
+ .disabled=${this.disabled}
56
+ .hasActionDescription=${this.hasActionDescription}
57
+ .actionDescription=${this.actionDescription}
49
58
  @change=${this.onCommandChange}
50
59
  >
51
60
  <div slot="command-icon">
@@ -62,10 +71,10 @@ class CommandMenuStoryWrapper extends LitElement {
62
71
  ${this.inCommand ? 'DP' : 'CMD at DP'}
63
72
  </div>
64
73
  <div slot="command-location">Aft Bridge</div>
65
- <div slot="toogle-action-to-in-command-label">Take</div>
66
- <div slot="toogle-action-to-no-command-label">Release</div>
67
- <div slot="toogle-state-in-command-label">In CMD</div>
68
- <div slot="toogle-state-no-command-label">DP Aft Bridge</div>
74
+ <div slot="toggle-action-to-in-command-label">Take</div>
75
+ <div slot="toggle-action-to-no-command-label">Release</div>
76
+ <div slot="toggle-state-in-command-label">In CMD</div>
77
+ <div slot="toggle-state-no-command-label">DP Aft Bridge</div>
69
78
  </obc-command-menu>
70
79
  `;
71
80
  }
@@ -78,6 +87,9 @@ const meta: Meta<typeof ObcCommandMenu> = {
78
87
  component: 'obc-command-menu',
79
88
  args: {
80
89
  showLocation: true,
90
+ disabled: false,
91
+ hasActionDescription: false,
92
+ actionDescription: 'Action description',
81
93
  },
82
94
 
83
95
  render: (args) => {
@@ -85,6 +97,9 @@ const meta: Meta<typeof ObcCommandMenu> = {
85
97
  <command-menu-story-wrapper
86
98
  .inCommand=${args.inCommand}
87
99
  .showLocation=${args.showLocation}
100
+ .disabled=${args.disabled}
101
+ .hasActionDescription=${args.hasActionDescription}
102
+ .actionDescription=${args.actionDescription}
88
103
  ></command-menu-story-wrapper>
89
104
  `;
90
105
  },
@@ -105,6 +120,28 @@ export const NoCommand: Story = {
105
120
  },
106
121
  };
107
122
 
123
+ export const WithActionDescription: Story = {
124
+ args: {
125
+ inCommand: false,
126
+ hasActionDescription: true,
127
+ actionDescription: 'Take command of the DP system',
128
+ },
129
+ };
130
+
131
+ export const Disabled: Story = {
132
+ args: {
133
+ inCommand: false,
134
+ disabled: true,
135
+ },
136
+ };
137
+
138
+ export const DisabledInCommand: Story = {
139
+ args: {
140
+ inCommand: true,
141
+ disabled: true,
142
+ },
143
+ };
144
+
108
145
  export const KeyboardToggle: Story = {
109
146
  args: {
110
147
  inCommand: false,