@oicl/openbridge-webcomponents 0.0.20260326144449 → 0.0.20260327071335
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.
- package/dist/components/toggle-switch/toggle-switch.css.js +1 -1
- package/dist/components/toggle-switch/toggle-switch.d.ts +9 -1
- package/dist/components/toggle-switch/toggle-switch.d.ts.map +1 -1
- package/dist/components/toggle-switch/toggle-switch.js +18 -2
- package/dist/components/toggle-switch/toggle-switch.js.map +1 -1
- package/dist/components/toggle-switch/toggle-switch.spec.d.ts +2 -0
- package/dist/components/toggle-switch/toggle-switch.spec.d.ts.map +1 -0
- package/dist/components/toggle-switch/toggle-switch.spec.js +115 -0
- package/dist/components/toggle-switch/toggle-switch.spec.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import '../icon-button/icon-button.js';
|
|
3
|
+
export type ObcToggleSwitchInputEvent = CustomEvent<{
|
|
4
|
+
checked: boolean;
|
|
5
|
+
}>;
|
|
3
6
|
/**
|
|
4
7
|
* `<obc-toggle-switch>` – A toggle switch component for binary on/off selection (also known as a switch, toggle, or enable/disable control).
|
|
5
8
|
*
|
|
@@ -75,7 +78,7 @@ import '../icon-button/icon-button.js';
|
|
|
75
78
|
* In this example, the toggle switch displays a label, an icon, and a description, and is in the checked state.
|
|
76
79
|
*
|
|
77
80
|
* @slot icon - Leading icon slot (shown when `hasIcon` is true)
|
|
78
|
-
* @fires input - Dispatched when the value of the input changes
|
|
81
|
+
* @fires input - {ObcToggleSwitchInputEvent} Dispatched when the value of the input changes
|
|
79
82
|
*/
|
|
80
83
|
export declare class ObcToggleSwitch extends LitElement {
|
|
81
84
|
/**
|
|
@@ -110,6 +113,11 @@ export declare class ObcToggleSwitch extends LitElement {
|
|
|
110
113
|
* Provide icon content via the `icon` slot.
|
|
111
114
|
*/
|
|
112
115
|
hasIcon: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* If true, the toggle is controlled externally.
|
|
118
|
+
* Use to control the toggle state from outside the component.
|
|
119
|
+
*/
|
|
120
|
+
externalControl: boolean;
|
|
113
121
|
/**
|
|
114
122
|
* Handles input events to change the toggle state.
|
|
115
123
|
* Prevents changes if the toggle is disabled.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-switch.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-switch/toggle-switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAA2B,MAAM,KAAK,CAAC;AAGzD,OAAO,+BAA+B,CAAC;AAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,qBACa,eAAgB,SAAQ,UAAU;IAC7C;;OAEG;IACuB,KAAK,SAAW;IAE1C;;;OAGG;IACwB,OAAO,UAAS;IAE3C;;OAEG;IACwB,QAAQ,UAAS;IAE5C;;OAEG;IACwB,cAAc,UAAS;IAElD;;;OAGG;IACuB,WAAW,SAAM;IAE3C;;;OAGG;IACwB,gBAAgB,UAAS;IAEpD;;;OAGG;IACwB,OAAO,UAAS;IAE3C;;;;;OAKG;IACH,OAAO,CAAC,UAAU;
|
|
1
|
+
{"version":3,"file":"toggle-switch.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-switch/toggle-switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAA2B,MAAM,KAAK,CAAC;AAGzD,OAAO,+BAA+B,CAAC;AAIvC,MAAM,MAAM,yBAAyB,GAAG,WAAW,CAAC;IAClD,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,qBACa,eAAgB,SAAQ,UAAU;IAC7C;;OAEG;IACuB,KAAK,SAAW;IAE1C;;;OAGG;IACwB,OAAO,UAAS;IAE3C;;OAEG;IACwB,QAAQ,UAAS;IAE5C;;OAEG;IACwB,cAAc,UAAS;IAElD;;;OAGG;IACuB,WAAW,SAAM;IAE3C;;;OAGG;IACwB,gBAAgB,UAAS;IAEpD;;;OAGG;IACwB,OAAO,UAAS;IAE3C;;;OAGG;IACwB,eAAe,UAAS;IAEnD;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAsBT,MAAM;IAsCf,OAAgB,MAAM,0BAA6B;CACpD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,mBAAmB,EAAE,eAAe,CAAC;KACtC;CACF"}
|
|
@@ -24,6 +24,7 @@ let ObcToggleSwitch = class extends LitElement {
|
|
|
24
24
|
this.description = "";
|
|
25
25
|
this.hasBottomDivider = false;
|
|
26
26
|
this.hasIcon = false;
|
|
27
|
+
this.externalControl = false;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Handles input events to change the toggle state.
|
|
@@ -36,7 +37,19 @@ let ObcToggleSwitch = class extends LitElement {
|
|
|
36
37
|
e.preventDefault();
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
const nextChecked = !this.checked;
|
|
41
|
+
if (!this.externalControl) {
|
|
42
|
+
this.checked = nextChecked;
|
|
43
|
+
}
|
|
44
|
+
e.stopPropagation();
|
|
45
|
+
this.dispatchEvent(
|
|
46
|
+
new CustomEvent("input", {
|
|
47
|
+
detail: { checked: nextChecked }
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
if (this.externalControl) {
|
|
51
|
+
e.target.checked = this.checked;
|
|
52
|
+
}
|
|
40
53
|
}
|
|
41
54
|
render() {
|
|
42
55
|
return html`
|
|
@@ -59,7 +72,7 @@ let ObcToggleSwitch = class extends LitElement {
|
|
|
59
72
|
<div class="knob"></div>
|
|
60
73
|
<input
|
|
61
74
|
type="checkbox"
|
|
62
|
-
|
|
75
|
+
.checked=${this.checked}
|
|
63
76
|
?disabled=${this.disabled}
|
|
64
77
|
@input=${this._tryChange}
|
|
65
78
|
/>
|
|
@@ -92,6 +105,9 @@ __decorateClass([
|
|
|
92
105
|
__decorateClass([
|
|
93
106
|
property({ type: Boolean })
|
|
94
107
|
], ObcToggleSwitch.prototype, "hasIcon", 2);
|
|
108
|
+
__decorateClass([
|
|
109
|
+
property({ type: Boolean })
|
|
110
|
+
], ObcToggleSwitch.prototype, "externalControl", 2);
|
|
95
111
|
ObcToggleSwitch = __decorateClass([
|
|
96
112
|
customElement("obc-toggle-switch")
|
|
97
113
|
], ObcToggleSwitch);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-switch.js","sources":["../../../src/components/toggle-switch/toggle-switch.ts"],"sourcesContent":["import {LitElement, html, nothing, unsafeCSS} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport '../icon-button/icon-button.js';\nimport componentStyle from './toggle-switch.css?inline';\nimport {customElement} from '../../decorator.js';\n\n/**\n * `<obc-toggle-switch>` – A toggle switch component for binary on/off selection (also known as a switch, toggle, or enable/disable control).\n *\n * Provides a visual switch control for toggling between two states (checked/unchecked), commonly used for enabling or disabling a setting or feature. The component supports an optional label, description, icon, and divider for flexible presentation in lists or forms.\n *\n * ---\n *\n * ### Features\n * - **Binary toggle:** Allows users to switch between checked (on) and unchecked (off) states.\n * - **Label and Description:** Displays a primary label and an optional secondary description for context.\n * - **Icon Support:** Can display a leading icon via the `icon` slot for visual emphasis.\n * - **Disabled State:** Can be set to disabled, preventing user interaction and visually indicating inactivity.\n * - **Bottom Divider:** Optional divider for use in lists or grouped settings.\n * - **Responsive Layout:** Adapts label/description layout based on content; long descriptions are truncated with ellipsis.\n *\n * ---\n *\n * ### Usage Guidelines\n * Use `obc-toggle-switch` for settings or preferences that require a simple on/off or enable/disable control. Ideal for scenarios where the user needs to quickly toggle a feature, such as activating notifications, enabling dark mode, or switching connectivity options. Avoid using for mutually exclusive choices—use radio buttons for those cases.\n *\n * - Place in forms, settings panels, or lists where binary choices are needed.\n * - Use the description property to clarify the effect of the toggle if the label alone is not sufficient.\n * - If an icon is relevant, provide it via the `icon` slot to reinforce the meaning.\n * - For accessibility, ensure the label clearly describes the toggle's function.\n *\n * ---\n *\n * ### Slots\n * | Slot Name | Renders When... | Purpose |\n * |-----------|---------------------|-------------------------------------------|\n * | icon | `hasIcon` is true | Leading icon to visually represent toggle |\n *\n * ---\n *\n * ### Properties and Attributes\n * - `label` (string): Main label for the toggle (required for clarity).\n * - `checked` (boolean): Whether the toggle is in the \"on\" state. Defaults to `false`.\n * - `disabled` (boolean): Disables interaction and applies a disabled style.\n * - `hasDescription` (boolean): If true, shows the description text below the label.\n * - `description` (string): Supplementary text shown when `hasDescription` is true.\n * - `hasBottomDivider` (boolean): If true, renders a divider below the toggle (useful in lists).\n * - `hasIcon` (boolean): If true, displays the `icon` slot before the label.\n *\n * ---\n *\n * ### Events\n * - `input` – Fired when the toggle state changes (checked/unchecked).\n *\n * ---\n *\n * ### Best Practices\n * - Use concise labels and keep descriptions brief; long descriptions are truncated.\n * - Only use the divider when presenting multiple toggles in a list for visual separation.\n * - For accessibility, ensure the label is descriptive and unique within the context.\n * - Avoid using toggle switches for actions that require confirmation or have destructive effects.\n * - For mutually exclusive options, use radio buttons instead.\n *\n * ---\n *\n * **Example:**\n * ```html\n * <obc-toggle-switch\n * label=\"Enable notifications\"\n * ?checked=${true}\n * ?hasDescription=${true}\n * description=\"Receive updates and alerts\"\n * ?hasIcon=${true}\n * >\n * <obi-placeholder slot=\"icon\"></obi-placeholder>\n * </obc-toggle-switch>\n * ```\n *\n * In this example, the toggle switch displays a label, an icon, and a description, and is in the checked state.\n *\n * @slot icon - Leading icon slot (shown when `hasIcon` is true)\n * @fires input - Dispatched when the value of the input changes\n */\n@customElement('obc-toggle-switch')\nexport class ObcToggleSwitch extends LitElement {\n /**\n * Main label for the toggle switch. Should clearly describe the setting being toggled.\n */\n @property({type: String}) label = 'Label';\n\n /**\n * Whether the toggle is in the \"on\" (checked) state.\n * Set to true to display as active/on.\n */\n @property({type: Boolean}) checked = false;\n\n /**\n * Disables the toggle, preventing user interaction and applying a disabled style.\n */\n @property({type: Boolean}) disabled = false;\n\n /**\n * If true, displays the description text below the label.\n */\n @property({type: Boolean}) hasDescription = false;\n\n /**\n * Supplementary description text shown when `hasDescription` is true.\n * Use to clarify the effect or details of the toggle.\n */\n @property({type: String}) description = '';\n\n /**\n * If true, renders a divider below the toggle switch.\n * Useful for visually separating items in a list.\n */\n @property({type: Boolean}) hasBottomDivider = false;\n\n /**\n * If true, displays a leading icon before the label.\n * Provide icon content via the `icon` slot.\n */\n @property({type: Boolean}) hasIcon = false;\n\n /**\n * Handles input events to change the toggle state.\n * Prevents changes if the toggle is disabled.\n * @param e {InputEvent}\n * @fires input - Dispatched when the value of the input changes\n */\n private _tryChange(e: InputEvent) {\n if (this.disabled) {\n e.preventDefault();\n return;\n }\n this.checked = (e.target as HTMLInputElement).checked;\n }\n\n override render() {\n return html`\n <label\n class=${classMap({\n checked: this.checked,\n disabled: this.disabled,\n 'has-description': this.hasDescription,\n })}\n >\n <div class=\"icon-label-container\">\n ${this.hasIcon\n ? html`<div class=\"icon-container\"><slot name=\"icon\"></slot></div>`\n : nothing}\n <div class=\"label-container\">\n <span class=\"label\">${this.label}</span>\n ${this.hasDescription\n ? html`<span class=\"description\">${this.description}</span>`\n : nothing}\n </div>\n </div>\n <div class=\"switch\">\n <div class=\"presenter ${classMap({checked: this.checked})}\">\n <div class=\"knob\"></div>\n <input\n type=\"checkbox\"\n
|
|
1
|
+
{"version":3,"file":"toggle-switch.js","sources":["../../../src/components/toggle-switch/toggle-switch.ts"],"sourcesContent":["import {LitElement, html, nothing, unsafeCSS} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport '../icon-button/icon-button.js';\nimport componentStyle from './toggle-switch.css?inline';\nimport {customElement} from '../../decorator.js';\n\nexport type ObcToggleSwitchInputEvent = CustomEvent<{\n checked: boolean;\n}>;\n\n/**\n * `<obc-toggle-switch>` – A toggle switch component for binary on/off selection (also known as a switch, toggle, or enable/disable control).\n *\n * Provides a visual switch control for toggling between two states (checked/unchecked), commonly used for enabling or disabling a setting or feature. The component supports an optional label, description, icon, and divider for flexible presentation in lists or forms.\n *\n * ---\n *\n * ### Features\n * - **Binary toggle:** Allows users to switch between checked (on) and unchecked (off) states.\n * - **Label and Description:** Displays a primary label and an optional secondary description for context.\n * - **Icon Support:** Can display a leading icon via the `icon` slot for visual emphasis.\n * - **Disabled State:** Can be set to disabled, preventing user interaction and visually indicating inactivity.\n * - **Bottom Divider:** Optional divider for use in lists or grouped settings.\n * - **Responsive Layout:** Adapts label/description layout based on content; long descriptions are truncated with ellipsis.\n *\n * ---\n *\n * ### Usage Guidelines\n * Use `obc-toggle-switch` for settings or preferences that require a simple on/off or enable/disable control. Ideal for scenarios where the user needs to quickly toggle a feature, such as activating notifications, enabling dark mode, or switching connectivity options. Avoid using for mutually exclusive choices—use radio buttons for those cases.\n *\n * - Place in forms, settings panels, or lists where binary choices are needed.\n * - Use the description property to clarify the effect of the toggle if the label alone is not sufficient.\n * - If an icon is relevant, provide it via the `icon` slot to reinforce the meaning.\n * - For accessibility, ensure the label clearly describes the toggle's function.\n *\n * ---\n *\n * ### Slots\n * | Slot Name | Renders When... | Purpose |\n * |-----------|---------------------|-------------------------------------------|\n * | icon | `hasIcon` is true | Leading icon to visually represent toggle |\n *\n * ---\n *\n * ### Properties and Attributes\n * - `label` (string): Main label for the toggle (required for clarity).\n * - `checked` (boolean): Whether the toggle is in the \"on\" state. Defaults to `false`.\n * - `disabled` (boolean): Disables interaction and applies a disabled style.\n * - `hasDescription` (boolean): If true, shows the description text below the label.\n * - `description` (string): Supplementary text shown when `hasDescription` is true.\n * - `hasBottomDivider` (boolean): If true, renders a divider below the toggle (useful in lists).\n * - `hasIcon` (boolean): If true, displays the `icon` slot before the label.\n *\n * ---\n *\n * ### Events\n * - `input` – Fired when the toggle state changes (checked/unchecked).\n *\n * ---\n *\n * ### Best Practices\n * - Use concise labels and keep descriptions brief; long descriptions are truncated.\n * - Only use the divider when presenting multiple toggles in a list for visual separation.\n * - For accessibility, ensure the label is descriptive and unique within the context.\n * - Avoid using toggle switches for actions that require confirmation or have destructive effects.\n * - For mutually exclusive options, use radio buttons instead.\n *\n * ---\n *\n * **Example:**\n * ```html\n * <obc-toggle-switch\n * label=\"Enable notifications\"\n * ?checked=${true}\n * ?hasDescription=${true}\n * description=\"Receive updates and alerts\"\n * ?hasIcon=${true}\n * >\n * <obi-placeholder slot=\"icon\"></obi-placeholder>\n * </obc-toggle-switch>\n * ```\n *\n * In this example, the toggle switch displays a label, an icon, and a description, and is in the checked state.\n *\n * @slot icon - Leading icon slot (shown when `hasIcon` is true)\n * @fires input - {ObcToggleSwitchInputEvent} Dispatched when the value of the input changes\n */\n@customElement('obc-toggle-switch')\nexport class ObcToggleSwitch extends LitElement {\n /**\n * Main label for the toggle switch. Should clearly describe the setting being toggled.\n */\n @property({type: String}) label = 'Label';\n\n /**\n * Whether the toggle is in the \"on\" (checked) state.\n * Set to true to display as active/on.\n */\n @property({type: Boolean}) checked = false;\n\n /**\n * Disables the toggle, preventing user interaction and applying a disabled style.\n */\n @property({type: Boolean}) disabled = false;\n\n /**\n * If true, displays the description text below the label.\n */\n @property({type: Boolean}) hasDescription = false;\n\n /**\n * Supplementary description text shown when `hasDescription` is true.\n * Use to clarify the effect or details of the toggle.\n */\n @property({type: String}) description = '';\n\n /**\n * If true, renders a divider below the toggle switch.\n * Useful for visually separating items in a list.\n */\n @property({type: Boolean}) hasBottomDivider = false;\n\n /**\n * If true, displays a leading icon before the label.\n * Provide icon content via the `icon` slot.\n */\n @property({type: Boolean}) hasIcon = false;\n\n /**\n * If true, the toggle is controlled externally.\n * Use to control the toggle state from outside the component.\n */\n @property({type: Boolean}) externalControl = false;\n\n /**\n * Handles input events to change the toggle state.\n * Prevents changes if the toggle is disabled.\n * @param e {InputEvent}\n * @fires input - Dispatched when the value of the input changes\n */\n private _tryChange(e: InputEvent) {\n if (this.disabled) {\n e.preventDefault();\n return;\n }\n\n const nextChecked = !this.checked;\n if (!this.externalControl) {\n this.checked = nextChecked;\n }\n e.stopPropagation();\n this.dispatchEvent(\n new CustomEvent('input', {\n detail: {checked: nextChecked},\n })\n );\n\n if (this.externalControl) {\n (e.target as HTMLInputElement).checked = this.checked;\n }\n }\n\n override render() {\n return html`\n <label\n class=${classMap({\n checked: this.checked,\n disabled: this.disabled,\n 'has-description': this.hasDescription,\n })}\n >\n <div class=\"icon-label-container\">\n ${this.hasIcon\n ? html`<div class=\"icon-container\"><slot name=\"icon\"></slot></div>`\n : nothing}\n <div class=\"label-container\">\n <span class=\"label\">${this.label}</span>\n ${this.hasDescription\n ? html`<span class=\"description\">${this.description}</span>`\n : nothing}\n </div>\n </div>\n <div class=\"switch\">\n <div class=\"presenter ${classMap({checked: this.checked})}\">\n <div class=\"knob\"></div>\n <input\n type=\"checkbox\"\n .checked=${this.checked}\n ?disabled=${this.disabled}\n @input=${this._tryChange}\n />\n </div>\n </div>\n ${this.hasBottomDivider\n ? html`<div class=\"bottom-divider\"></div>`\n : nothing}\n </label>\n `;\n }\n\n static override styles = unsafeCSS(componentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-toggle-switch': ObcToggleSwitch;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAyFO,IAAM,kBAAN,cAA8B,WAAW;AAAA,EAAzC,cAAA;AAAA,UAAA,GAAA,SAAA;AAIqB,SAAA,QAAQ;AAMP,SAAA,UAAU;AAKV,SAAA,WAAW;AAKX,SAAA,iBAAiB;AAMlB,SAAA,cAAc;AAMb,SAAA,mBAAmB;AAMnB,SAAA,UAAU;AAMV,SAAA,kBAAkB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQrC,WAAW,GAAe;AA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AAAA,EAA1B,SAAS,EAAC,MAAM,QAAA,CAAQ;AAAA,GApBd,gBAoBgB,WAAA,kBAAA,CAAA;AAMD,gBAAA;AAAA,EAAzB,SAAS,EAAC,MAAM,OAAA,CAAO;AAAA,GA1Bb,gBA0Be,WAAA,eAAA,CAAA;AAMC,gBAAA;AAAA,EAA1B,SAAS,EAAC,MAAM,QAAA,CAAQ;AAAA,GAhCd,gBAgCgB,WAAA,oBAAA,CAAA;AAMA,gBAAA;AAAA,EAA1B,SAAS,EAAC,MAAM,QAAA,CAAQ;AAAA,GAtCd,gBAsCgB,WAAA,WAAA,CAAA;AAMA,gBAAA;AAAA,EAA1B,SAAS,EAAC,MAAM,QAAA,CAAQ;AAAA,GA5Cd,gBA4CgB,WAAA,mBAAA,CAAA;AA5ChB,kBAAN,gBAAA;AAAA,EADN,cAAc,mBAAmB;AAAA,GACrB,eAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-switch.spec.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-switch/toggle-switch.spec.ts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import "./toggle-switch.js";
|
|
2
|
+
import "../../node_modules/vitest-browser-lit/dist/index.js";
|
|
3
|
+
import { html } from "lit";
|
|
4
|
+
import { describe, beforeEach, it } from "../../node_modules/@vitest/runner/dist/index.js";
|
|
5
|
+
import { g as globalExpect, v as vi } from "../../node_modules/vitest/dist/chunks/test.CTcmp4Su.js";
|
|
6
|
+
import { render as render$1 } from "../../node_modules/vitest-browser-lit/dist/pure-D9bcvh0k.js";
|
|
7
|
+
describe("obc-toggle-switch", () => {
|
|
8
|
+
let el;
|
|
9
|
+
let input;
|
|
10
|
+
async function setup(markup = html`<obc-toggle-switch></obc-toggle-switch>`) {
|
|
11
|
+
const screen = render$1(markup);
|
|
12
|
+
el = screen.baseElement.querySelector(
|
|
13
|
+
"obc-toggle-switch"
|
|
14
|
+
);
|
|
15
|
+
await el.updateComplete;
|
|
16
|
+
if (!el.shadowRoot) {
|
|
17
|
+
console.error("Shadow root not found", el);
|
|
18
|
+
throw new Error("Shadow root not found");
|
|
19
|
+
}
|
|
20
|
+
input = el.shadowRoot.querySelector(
|
|
21
|
+
'input[type="checkbox"]'
|
|
22
|
+
);
|
|
23
|
+
if (!input) {
|
|
24
|
+
console.error("Input not found", el.shadowRoot);
|
|
25
|
+
throw new Error("Input not found");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
beforeEach(async () => {
|
|
29
|
+
await setup();
|
|
30
|
+
});
|
|
31
|
+
it("defaults to unchecked", async () => {
|
|
32
|
+
globalExpect(el.checked).toBe(false);
|
|
33
|
+
globalExpect(input.checked).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
describe("toggling (internal control)", () => {
|
|
36
|
+
it("dispatches input event with next checked value", async () => {
|
|
37
|
+
const handler = vi.fn();
|
|
38
|
+
el.addEventListener("input", handler);
|
|
39
|
+
input.click();
|
|
40
|
+
await el.updateComplete;
|
|
41
|
+
globalExpect(handler).toHaveBeenCalledTimes(1);
|
|
42
|
+
const event = handler.mock.calls[0]?.[0];
|
|
43
|
+
globalExpect(event.detail).toEqual({ checked: true });
|
|
44
|
+
});
|
|
45
|
+
it("combination of click and js control", async () => {
|
|
46
|
+
el.checked = true;
|
|
47
|
+
await el.updateComplete;
|
|
48
|
+
globalExpect(el.checked).toBe(true);
|
|
49
|
+
globalExpect(input.checked).toBe(true);
|
|
50
|
+
input.click();
|
|
51
|
+
await el.updateComplete;
|
|
52
|
+
globalExpect(el.checked).toBe(false);
|
|
53
|
+
globalExpect(input.checked).toBe(false);
|
|
54
|
+
input.click();
|
|
55
|
+
await el.updateComplete;
|
|
56
|
+
globalExpect(el.checked).toBe(true);
|
|
57
|
+
globalExpect(input.checked).toBe(true);
|
|
58
|
+
el.checked = false;
|
|
59
|
+
await el.updateComplete;
|
|
60
|
+
globalExpect(el.checked).toBe(false);
|
|
61
|
+
globalExpect(input.checked).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
it("updates checked when user toggles", async () => {
|
|
64
|
+
input.click();
|
|
65
|
+
await el.updateComplete;
|
|
66
|
+
globalExpect(el.checked).toBe(true);
|
|
67
|
+
globalExpect(input.checked).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe("externalControl", () => {
|
|
71
|
+
beforeEach(async () => {
|
|
72
|
+
el.externalControl = true;
|
|
73
|
+
await el.updateComplete;
|
|
74
|
+
});
|
|
75
|
+
it("does not change checked when user toggles", async () => {
|
|
76
|
+
globalExpect(el.checked).toBe(false);
|
|
77
|
+
globalExpect(input.checked).toBe(false);
|
|
78
|
+
input.click();
|
|
79
|
+
await el.updateComplete;
|
|
80
|
+
globalExpect(el.checked).toBe(false);
|
|
81
|
+
globalExpect(input.checked).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
it("still dispatches input event with suggested next state", async () => {
|
|
84
|
+
const handler = vi.fn();
|
|
85
|
+
el.addEventListener("input", handler);
|
|
86
|
+
input.click();
|
|
87
|
+
await el.updateComplete;
|
|
88
|
+
globalExpect(handler).toHaveBeenCalledTimes(1);
|
|
89
|
+
const event = handler.mock.calls[0]?.[0];
|
|
90
|
+
globalExpect(event.detail).toEqual({ checked: true });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe("disabled", () => {
|
|
94
|
+
beforeEach(async () => {
|
|
95
|
+
el.disabled = true;
|
|
96
|
+
await el.updateComplete;
|
|
97
|
+
});
|
|
98
|
+
it("prevents toggling", async () => {
|
|
99
|
+
globalExpect(el.checked).toBe(false);
|
|
100
|
+
globalExpect(input.disabled).toBe(true);
|
|
101
|
+
input.click();
|
|
102
|
+
await el.updateComplete;
|
|
103
|
+
globalExpect(el.checked).toBe(false);
|
|
104
|
+
globalExpect(input.checked).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
it("does not dispatch input event", async () => {
|
|
107
|
+
const handler = vi.fn();
|
|
108
|
+
el.addEventListener("input", handler);
|
|
109
|
+
input.click();
|
|
110
|
+
await el.updateComplete;
|
|
111
|
+
globalExpect(handler).not.toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=toggle-switch.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-switch.spec.js","sources":["../../../src/components/toggle-switch/toggle-switch.spec.ts"],"sourcesContent":["import {beforeEach, describe, expect, it, vi} from 'vitest';\nimport './toggle-switch.js';\nimport {ObcToggleSwitch} from './toggle-switch.js';\nimport {render} from 'vitest-browser-lit';\nimport {html} from 'lit';\n\ndescribe('obc-toggle-switch', () => {\n let el: ObcToggleSwitch;\n let input: HTMLInputElement;\n\n async function setup(markup = html`<obc-toggle-switch></obc-toggle-switch>`) {\n const screen = render(markup);\n el = screen.baseElement.querySelector(\n 'obc-toggle-switch'\n ) as ObcToggleSwitch;\n await el.updateComplete;\n\n if (!el.shadowRoot) {\n console.error('Shadow root not found', el);\n throw new Error('Shadow root not found');\n }\n\n input = el.shadowRoot.querySelector(\n 'input[type=\"checkbox\"]'\n ) as HTMLInputElement;\n if (!input) {\n console.error('Input not found', el.shadowRoot);\n throw new Error('Input not found');\n }\n }\n\n beforeEach(async () => {\n await setup();\n });\n\n it('defaults to unchecked', async () => {\n expect(el.checked).toBe(false);\n expect(input.checked).toBe(false);\n });\n\n describe('toggling (internal control)', () => {\n it('dispatches input event with next checked value', async () => {\n const handler = vi.fn();\n el.addEventListener('input', handler);\n\n input.click();\n await el.updateComplete;\n\n expect(handler).toHaveBeenCalledTimes(1);\n const event = handler.mock.calls[0]?.[0] as CustomEvent<{\n checked: boolean;\n }>;\n expect(event.detail).toEqual({checked: true});\n });\n\n it('combination of click and js control', async () => {\n el.checked = true;\n await el.updateComplete;\n expect(el.checked).toBe(true);\n expect(input.checked).toBe(true);\n\n input.click();\n await el.updateComplete;\n\n expect(el.checked).toBe(false);\n expect(input.checked).toBe(false);\n\n input.click();\n await el.updateComplete;\n\n expect(el.checked).toBe(true);\n expect(input.checked).toBe(true);\n\n el.checked = false;\n await el.updateComplete;\n expect(el.checked).toBe(false);\n expect(input.checked).toBe(false);\n });\n\n it('updates checked when user toggles', async () => {\n input.click();\n await el.updateComplete;\n\n expect(el.checked).toBe(true);\n expect(input.checked).toBe(true);\n });\n });\n\n describe('externalControl', () => {\n beforeEach(async () => {\n el.externalControl = true;\n await el.updateComplete;\n });\n\n it('does not change checked when user toggles', async () => {\n expect(el.checked).toBe(false);\n expect(input.checked).toBe(false);\n\n input.click();\n await el.updateComplete;\n\n expect(el.checked).toBe(false);\n expect(input.checked).toBe(false);\n });\n\n it('still dispatches input event with suggested next state', async () => {\n const handler = vi.fn();\n el.addEventListener('input', handler);\n\n input.click();\n await el.updateComplete;\n\n expect(handler).toHaveBeenCalledTimes(1);\n const event = handler.mock.calls[0]?.[0] as CustomEvent<{\n checked: boolean;\n }>;\n expect(event.detail).toEqual({checked: true});\n });\n });\n\n describe('disabled', () => {\n beforeEach(async () => {\n el.disabled = true;\n await el.updateComplete;\n });\n\n it('prevents toggling', async () => {\n expect(el.checked).toBe(false);\n expect(input.disabled).toBe(true);\n\n input.click();\n await el.updateComplete;\n\n expect(el.checked).toBe(false);\n expect(input.checked).toBe(false);\n });\n\n it('does not dispatch input event', async () => {\n const handler = vi.fn();\n el.addEventListener('input', handler);\n\n input.click();\n await el.updateComplete;\n\n expect(handler).not.toHaveBeenCalled();\n });\n });\n});\n"],"names":["render","expect"],"mappings":";;;;;;AAMA,SAAS,qBAAqB,MAAM;AAClC,MAAI;AACJ,MAAI;AAEJ,iBAAe,MAAM,SAAS,+CAA+C;AAC3E,UAAM,SAASA,SAAO,MAAM;AAC5B,SAAK,OAAO,YAAY;AAAA,MACtB;AAAA,IAAA;AAEF,UAAM,GAAG;AAET,QAAI,CAAC,GAAG,YAAY;AAClB,cAAQ,MAAM,yBAAyB,EAAE;AACzC,Y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