@c2n/switch 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nguyen Thai Vinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @c2n/switch
2
+
3
+ Switch built with Lit: an on/off toggle on a native `<input type="checkbox" role="switch">`, with label, description and optional icons inside the thumb.
4
+
5
+ ```bash
6
+ npm install @c2n/switch
7
+ ```
8
+
9
+ ```html
10
+ <script type="module">
11
+ import '@c2n/switch'
12
+ </script>
13
+
14
+ <c2-switch checked>Notifications</c2-switch>
15
+ <c2-switch name="digest" value="daily">Email digest<span slot="description">Every morning at 8:00.</span></c2-switch>
16
+ <c2-switch checked>
17
+ <svg slot="checked-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3.5"><polyline points="20 6 9 17 4 12"></polyline></svg>
18
+ Two-factor authentication
19
+ </c2-switch>
20
+ ```
21
+
22
+ - **State**: `checked` reflects the state, `change` fires on every user toggle (click, Space or dragging the thumb past the middle of the track), `toggle(force?)` flips it from code and fires `change`; setting `checked` is silent. `disabled` dims the row and blocks toggling.
23
+ - **Label**: the whole row is the label (slotted text or the `label` attribute, plus a `description` slot). `--c2-switch__container--flex-direction: row-reverse` with `justify-content: space-between` gives the settings-row layout with the track at the far edge.
24
+ - **Icons**: `checked-icon` and `unchecked-icon` slots show inside the thumb, cross-faded, sized by `--c2-switch__icon--size`.
25
+ - **Forms**: the input carries `name` and `value` but sits in a shadow root, so read `checked` on submit or mirror it into a hidden input.
26
+ - **Motion**: the thumb slides over `--c2-switch--transition-duration` and stretches slightly while pressed (`--c2-switch__thumb__active--stretch`); both respect reduced motion. Right-to-left layouts slide the other way.
27
+
28
+ Theme the track (`--c2-switch__track--*`: size, radius, border, off/on/hover colours, focus ring), the thumb (`--c2-switch__thumb--*`) and the text (`--c2-switch__label--*`, `--c2-switch__description--*`). The full list is in `custom-elements.json` and on the docs site.
package/dist/switch.js ADDED
@@ -0,0 +1,199 @@
1
+ import { LitElement, html, unsafeCSS } from "lit";
2
+ import { customElement, property, query, state } from "lit/decorators.js";
3
+ import { classMap } from "lit/directives/class-map.js";
4
+ import { ifDefined } from "lit/directives/if-defined.js";
5
+ import { redispatchEvent } from "@c2n/core/dom-helper.js";
6
+ //#region src/switch.scss?inline
7
+ var switch_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: inline-flex;\n vertical-align: middle;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.c2-switch {\n display: inline-flex;\n align-items: center;\n flex: 1;\n min-width: 0;\n flex-direction: var(--c2-switch__container--flex-direction,row);\n justify-content: var(--c2-switch__container--justify-content,flex-start);\n gap: var(--c2-switch__container--gap,8px);\n cursor: pointer;\n}\n.c2-switch.has-description {\n align-items: flex-start;\n}\n.c2-switch:has(.c2-switch-input:disabled) {\n cursor: default;\n opacity: var(--c2-switch__container__disabled--opacity,0.38);\n}\n\n.c2-switch-control {\n position: relative;\n display: inline-flex;\n flex: none;\n line-height: 0;\n}\n\n.c2-switch-input {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n margin: 0;\n padding: 0;\n opacity: 0;\n cursor: inherit;\n z-index: 1;\n touch-action: pan-y;\n}\n\n.c2-switch-track {\n position: relative;\n display: inline-flex;\n align-items: center;\n box-sizing: border-box;\n width: var(--c2-switch__track--width,36px);\n height: var(--c2-switch__track--height,20px);\n padding: var(--c2-switch__thumb--offset,2px);\n border-radius: var(--c2-switch__track--border-radius,999px);\n border: var(--c2-switch__track--border,1px solid transparent);\n background-color: var(--c2-switch__track--color,#e4e4e7);\n transition: background-color var(--c2-switch--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1), border-color var(--c2-switch--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1);\n}\n\n.c2-switch-thumb {\n position: relative;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: var(--c2-switch__thumb--size,16px);\n height: var(--c2-switch__thumb--size,16px);\n border-radius: var(--c2-switch__thumb--border-radius,999px);\n background-color: var(--c2-switch__thumb--color,#ffffff);\n box-shadow: var(--c2-switch__thumb--box-shadow,0 1px 2px rgba(0, 0, 0, 0.2));\n transform: translateX(0);\n transition: transform var(--c2-switch--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1), width var(--c2-switch--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1), background-color var(--c2-switch--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1);\n}\n\n.c2-switch-icon {\n position: absolute;\n inset: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n line-height: 0;\n color: var(--c2-switch__icon--color,#71717a);\n opacity: 1;\n transition: opacity var(--c2-switch--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1);\n --c2-feather-icon--size: var(--c2-switch__icon--size,10px);\n --c2-mat-icon--font-size: var(--c2-switch__icon--size,10px);\n}\n.c2-switch-icon ::slotted(*) {\n width: var(--c2-switch__icon--size,10px);\n height: var(--c2-switch__icon--size,10px);\n}\n\n.c2-switch-icon--checked {\n color: var(--c2-switch__icon__checked--color,#0265dc);\n opacity: 0;\n}\n\n.c2-switch-input:checked ~ .c2-switch-track {\n background-color: var(--c2-switch__track__checked--color,#0265dc);\n border: var(--c2-switch__track__checked--border,var(--c2-switch__track--border,1px solid transparent));\n}\n.c2-switch-input:checked ~ .c2-switch-track .c2-switch-thumb {\n transform: translateX(calc(var(--c2-switch__track--width,36px) - var(--c2-switch__thumb--size,16px) - 2 * var(--c2-switch__thumb--offset,2px)));\n background-color: var(--c2-switch__thumb__checked--color,var(--c2-switch__thumb--color,#ffffff));\n}\n.c2-switch-input:checked ~ .c2-switch-track .c2-switch-icon--unchecked {\n opacity: 0;\n}\n.c2-switch-input:checked ~ .c2-switch-track .c2-switch-icon--checked {\n opacity: 1;\n}\n\n.c2-switch-input:enabled:hover ~ .c2-switch-track {\n background-color: var(--c2-switch__track__hover--color,var(--c2-switch__track--color,#d4d4d8));\n}\n\n.c2-switch-input:enabled:checked:hover ~ .c2-switch-track {\n background-color: var(--c2-switch__track__checked__hover--color,var(--c2-switch__track__checked--color,#0154b8));\n}\n\n.c2-switch:not(.is-dragging) .c2-switch-input:enabled:active ~ .c2-switch-track .c2-switch-thumb {\n width: calc(var(--c2-switch__thumb--size,16px) + var(--c2-switch__thumb__active--stretch,4px));\n}\n\n.c2-switch:not(.is-dragging) .c2-switch-input:enabled:active:checked ~ .c2-switch-track .c2-switch-thumb {\n transform: translateX(calc(calc(var(--c2-switch__track--width,36px) - var(--c2-switch__thumb--size,16px) - 2 * var(--c2-switch__thumb--offset,2px)) - var(--c2-switch__thumb__active--stretch,4px)));\n}\n\n.c2-switch.is-dragging .c2-switch-input ~ .c2-switch-track .c2-switch-thumb {\n transition: none;\n width: var(--c2-switch__thumb--size,16px);\n transform: translateX(var(--_drag, 0px));\n}\n\n.c2-switch-input:focus-visible ~ .c2-switch-track {\n outline: var(--c2-switch__track__focus--outline,2px solid rgba(2, 101, 220, 0.4));\n outline-offset: var(--c2-switch__track__focus--outline-offset,2px);\n}\n\n.c2-switch-text {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n min-width: 0;\n}\n\n.c2-switch-label {\n color: var(--c2-switch__label--color,inherit);\n font-size: var(--c2-switch__label--font-size,inherit);\n font-weight: var(--c2-switch__label--font-weight,inherit);\n line-height: var(--c2-switch__label--line-height,inherit);\n}\n\n.has-description .c2-switch-label {\n display: flex;\n align-items: center;\n min-height: var(--c2-switch__track--height,20px);\n}\n\n.c2-switch-description {\n color: var(--c2-switch__description--color,#71717a);\n font-size: var(--c2-switch__description--font-size,12px);\n margin-top: var(--c2-switch__description--margin-top,2px);\n line-height: 1.4;\n}\n.c2-switch-description[hidden] {\n display: none;\n}\n\n:host(:dir(rtl)) .c2-switch-input:checked ~ .c2-switch-track .c2-switch-thumb {\n transform: translateX(calc(-1 * calc(var(--c2-switch__track--width,36px) - var(--c2-switch__thumb--size,16px) - 2 * var(--c2-switch__thumb--offset,2px))));\n}\n\n:host(:dir(rtl)) .c2-switch:not(.is-dragging) .c2-switch-input:enabled:active:checked ~ .c2-switch-track .c2-switch-thumb {\n transform: translateX(calc(-1 * (calc(var(--c2-switch__track--width,36px) - var(--c2-switch__thumb--size,16px) - 2 * var(--c2-switch__thumb--offset,2px)) - var(--c2-switch__thumb__active--stretch,4px))));\n}\n\n@media (prefers-reduced-motion: reduce) {\n .c2-switch-track,\n .c2-switch-thumb,\n .c2-switch-icon {\n transition: none;\n }\n}";
8
+ //#endregion
9
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
10
+ function __decorate(decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ }
16
+ //#endregion
17
+ //#region src/switch.ts
18
+ var Switch = class Switch extends LitElement {
19
+ constructor(..._args) {
20
+ super(..._args);
21
+ this.checked = false;
22
+ this.disabled = false;
23
+ this.name = "";
24
+ this.value = "on";
25
+ this.label = "";
26
+ this.hasDescription = false;
27
+ this.dragging = false;
28
+ this.suppressClick = false;
29
+ }
30
+ static {
31
+ this.styles = unsafeCSS(switch_default);
32
+ }
33
+ focus(options) {
34
+ this.formElement?.focus(options);
35
+ }
36
+ /** Flips the state (or forces it) and fires `change`, as a click would. */
37
+ toggle(force) {
38
+ if (this.disabled) return;
39
+ const next = force ?? !this.checked;
40
+ if (next === this.checked) return;
41
+ this.checked = next;
42
+ this.dispatchEvent(new Event("change", {
43
+ bubbles: true,
44
+ composed: true
45
+ }));
46
+ }
47
+ /** `slotchange` does not fire for server-rendered slots, so read the description once after the first render. */
48
+ firstUpdated() {
49
+ const slot = this.renderRoot.querySelector("slot[name=\"description\"]");
50
+ if (slot) this.updateDescription(slot);
51
+ }
52
+ update(changed) {
53
+ if (changed.has("checked") && this.formElement) this.formElement.checked = this.checked;
54
+ super.update(changed);
55
+ }
56
+ handleDescriptionChange(event) {
57
+ this.updateDescription(event.target);
58
+ }
59
+ updateDescription(slot) {
60
+ this.hasDescription = slot.assignedNodes({ flatten: true }).some((node) => node.nodeType === Node.ELEMENT_NODE || (node.textContent ?? "").trim() !== "");
61
+ }
62
+ handleChange(event) {
63
+ this.checked = this.formElement.checked;
64
+ redispatchEvent(this, event);
65
+ }
66
+ get rtl() {
67
+ return getComputedStyle(this).direction === "rtl";
68
+ }
69
+ handlePointerDown(event) {
70
+ if (this.disabled || event.button !== 0) return;
71
+ const track = this.trackElement;
72
+ const padding = parseFloat(getComputedStyle(track).paddingLeft) || 0;
73
+ const travel = Math.max(0, track.clientWidth - 2 * padding - this.thumbElement.getBoundingClientRect().height);
74
+ const startPosition = this.checked ? travel : 0;
75
+ this.drag = {
76
+ pointerId: event.pointerId,
77
+ startX: event.clientX,
78
+ startPosition,
79
+ travel,
80
+ position: startPosition,
81
+ moved: false
82
+ };
83
+ this.formElement.setPointerCapture(event.pointerId);
84
+ }
85
+ handlePointerMove(event) {
86
+ const drag = this.drag;
87
+ if (!drag || event.pointerId !== drag.pointerId) return;
88
+ const rtl = this.rtl;
89
+ const delta = (event.clientX - drag.startX) * (rtl ? -1 : 1);
90
+ if (!drag.moved && Math.abs(delta) < 4) return;
91
+ drag.moved = true;
92
+ drag.position = Math.min(drag.travel, Math.max(0, drag.startPosition + delta));
93
+ this.dragging = true;
94
+ this.thumbElement.style.setProperty("--_drag", `${rtl ? -drag.position : drag.position}px`);
95
+ }
96
+ handlePointerUp(event) {
97
+ const drag = this.drag;
98
+ if (!drag || event.pointerId !== drag.pointerId) return;
99
+ this.drag = void 0;
100
+ if (!drag.moved) return;
101
+ this.endDrag();
102
+ this.suppressClick = true;
103
+ const next = drag.position > drag.travel / 2;
104
+ if (next !== this.checked) {
105
+ this.checked = next;
106
+ this.dispatchEvent(new Event("change", {
107
+ bubbles: true,
108
+ composed: true
109
+ }));
110
+ }
111
+ }
112
+ handlePointerCancel(event) {
113
+ if (!this.drag || event.pointerId !== this.drag.pointerId) return;
114
+ this.drag = void 0;
115
+ this.endDrag();
116
+ }
117
+ endDrag() {
118
+ this.dragging = false;
119
+ this.thumbElement.style.removeProperty("--_drag");
120
+ }
121
+ handleClick(event) {
122
+ if (!this.suppressClick) return;
123
+ this.suppressClick = false;
124
+ event.preventDefault();
125
+ }
126
+ render() {
127
+ return html`
128
+ <label class=${classMap({
129
+ "c2-switch": true,
130
+ "has-description": this.hasDescription,
131
+ "is-dragging": this.dragging
132
+ })}>
133
+ <span class="c2-switch-control" part="control">
134
+ <input
135
+ class="c2-switch-input"
136
+ type="checkbox"
137
+ role="switch"
138
+ name=${ifDefined(this.name || void 0)}
139
+ .value=${this.value}
140
+ aria-label=${ifDefined(this.ariaLabel)}
141
+ aria-labelledby=${ifDefined(this.ariaLabelledBy)}
142
+ aria-describedby=${ifDefined(this.ariaDescribedBy)}
143
+ ?checked=${this.checked}
144
+ ?disabled=${this.disabled}
145
+ @change=${this.handleChange}
146
+ @click=${this.handleClick}
147
+ @pointerdown=${this.handlePointerDown}
148
+ @pointermove=${this.handlePointerMove}
149
+ @pointerup=${this.handlePointerUp}
150
+ @pointercancel=${this.handlePointerCancel}
151
+ />
152
+ <span class="c2-switch-track" part="track">
153
+ <span class="c2-switch-thumb" part="thumb">
154
+ <span class="c2-switch-icon c2-switch-icon--unchecked" part="unchecked-icon"><slot name="unchecked-icon"></slot></span>
155
+ <span class="c2-switch-icon c2-switch-icon--checked" part="checked-icon"><slot name="checked-icon"></slot></span>
156
+ </span>
157
+ </span>
158
+ </span>
159
+ <span class="c2-switch-text">
160
+ <span class="c2-switch-label" part="label"><slot>${this.label}</slot></span>
161
+ <span class="c2-switch-description" part="description" ?hidden=${!this.hasDescription}>
162
+ <slot name="description" @slotchange=${this.handleDescriptionChange}></slot>
163
+ </span>
164
+ </span>
165
+ </label>
166
+ `;
167
+ }
168
+ };
169
+ __decorate([query("input")], Switch.prototype, "formElement", void 0);
170
+ __decorate([query(".c2-switch-track")], Switch.prototype, "trackElement", void 0);
171
+ __decorate([query(".c2-switch-thumb")], Switch.prototype, "thumbElement", void 0);
172
+ __decorate([property({
173
+ type: Boolean,
174
+ reflect: true
175
+ })], Switch.prototype, "checked", void 0);
176
+ __decorate([property({
177
+ type: Boolean,
178
+ reflect: true
179
+ })], Switch.prototype, "disabled", void 0);
180
+ __decorate([property()], Switch.prototype, "name", void 0);
181
+ __decorate([property()], Switch.prototype, "value", void 0);
182
+ __decorate([property()], Switch.prototype, "label", void 0);
183
+ __decorate([property({
184
+ type: String,
185
+ attribute: "aria-label"
186
+ })], Switch.prototype, "ariaLabel", void 0);
187
+ __decorate([property({
188
+ type: String,
189
+ attribute: "aria-labelledby"
190
+ })], Switch.prototype, "ariaLabelledBy", void 0);
191
+ __decorate([property({
192
+ type: String,
193
+ attribute: "aria-describedby"
194
+ })], Switch.prototype, "ariaDescribedBy", void 0);
195
+ __decorate([state()], Switch.prototype, "hasDescription", void 0);
196
+ __decorate([state()], Switch.prototype, "dragging", void 0);
197
+ Switch = __decorate([customElement("c2-switch")], Switch);
198
+ //#endregion
199
+ export { Switch };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@c2n/switch",
3
+ "version": "0.0.6",
4
+ "type": "module",
5
+ "main": "dist/switch.js",
6
+ "exports": {
7
+ ".": {
8
+ "default": "./dist/switch.js",
9
+ "types": "./types/src/switch.d.ts"
10
+ },
11
+ "./custom-elements.json": "./custom-elements.json"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "types"
16
+ ],
17
+ "keywords": [
18
+ "switch",
19
+ "web component",
20
+ "lit"
21
+ ],
22
+ "license": "MIT",
23
+ "author": "code2nguyen@gmail.com",
24
+ "publishConfig": {
25
+ "registry": "https://registry.npmjs.org",
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/code2nguyen/web-components.git"
31
+ },
32
+ "scripts": {
33
+ "dev": "vite",
34
+ "build": "wireit",
35
+ "build:only": "vite build",
36
+ "type-check": "wireit"
37
+ },
38
+ "wireit": {
39
+ "type-check": {
40
+ "dependencies": [
41
+ "../../core:build"
42
+ ],
43
+ "command": "tsc -p tsconfig.lib.json --composite false"
44
+ },
45
+ "build": {
46
+ "dependencies": [
47
+ "type-check"
48
+ ],
49
+ "command": "vite build"
50
+ }
51
+ },
52
+ "dependencies": {
53
+ "@c2n/core": "0.0.6",
54
+ "lit": "3.3.3"
55
+ },
56
+ "devDependencies": {
57
+ "@c2n/config": "*"
58
+ },
59
+ "customElements": "custom-elements.json",
60
+ "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
61
+ }
@@ -0,0 +1,103 @@
1
+ import { LitElement, type PropertyValues } from 'lit';
2
+ /**
3
+ * On/off toggle built on a native `<input type="checkbox" role="switch">`, so keyboard activation (Space), form value
4
+ * and the `switch` role come from the browser. The thumb can also be dragged: it follows the pointer and the side it is
5
+ * released on decides the state. The whole row is the label: text in the default slot and an optional `description`
6
+ * sit beside the track, and clicking them toggles it. Icons for either state can ride inside the thumb.
7
+ *
8
+ * @tag c2-switch
9
+ *
10
+ * @slot - Label text. Falls back to the `label` attribute.
11
+ * @slot description - Supporting text shown under the label.
12
+ * @slot checked-icon - Small icon shown inside the thumb while on (an inline SVG, a `c2-feather-*` icon or a `c2-mat-icon`).
13
+ * @slot unchecked-icon - Small icon shown inside the thumb while off.
14
+ *
15
+ * @event {Event} change - Re-dispatched from the inner input when the state changes.
16
+ *
17
+ * @cssproperty {pixel} [--c2-switch__container--gap=8px] - Space between the track and the text.
18
+ * @cssproperty {flex-direction-row} [--c2-switch__container--flex-direction=row] - `row-reverse` puts the text before the track.
19
+ * @cssproperty {justify-content} [--c2-switch__container--justify-content=flex-start] - `space-between` with a fixed width pushes the track to the far edge.
20
+ * @cssproperty {opacity} [--c2-switch__container__disabled--opacity=0.38]
21
+ *
22
+ * @cssproperty {pixel} [--c2-switch__track--width=36px]
23
+ * @cssproperty {pixel} [--c2-switch__track--height=20px]
24
+ * @cssproperty {border-radius} [--c2-switch__track--border-radius=999px]
25
+ * @cssproperty {border} [--c2-switch__track--border=1px solid transparent] - Set a colour for an outlined switch.
26
+ * @cssproperty {color} [--c2-switch__track--color=#e4e4e7] - Track fill while off.
27
+ * @cssproperty {color} [--c2-switch__track__hover--color=#d4d4d8]
28
+ * @cssproperty {color} [--c2-switch__track__checked--color=#0265dc] - Track fill while on.
29
+ * @cssproperty {color} [--c2-switch__track__checked__hover--color=#0154b8]
30
+ * @cssproperty {border} --c2-switch__track__checked--border
31
+ * @cssproperty {outline} [--c2-switch__track__focus--outline=2px solid rgba(2, 101, 220, 0.4)]
32
+ * @cssproperty {pixel} [--c2-switch__track__focus--outline-offset=2px]
33
+ *
34
+ * @cssproperty {pixel} [--c2-switch__thumb--size=16px]
35
+ * @cssproperty {pixel} [--c2-switch__thumb--offset=2px] - Gap between the thumb and the track edge.
36
+ * @cssproperty {border-radius} [--c2-switch__thumb--border-radius=999px]
37
+ * @cssproperty {color} [--c2-switch__thumb--color=#ffffff]
38
+ * @cssproperty {color} --c2-switch__thumb__checked--color - Thumb fill while on; falls back to the off colour.
39
+ * @cssproperty {box-shadow} [--c2-switch__thumb--box-shadow=0 1px 2px rgba(0, 0, 0, 0.2)]
40
+ * @cssproperty {pixel} [--c2-switch__thumb__active--stretch=4px] - Extra thumb width while pressed, for a squishy feel; `0px` disables it.
41
+ *
42
+ * @cssproperty {pixel} [--c2-switch__icon--size=10px]
43
+ * @cssproperty {color} [--c2-switch__icon--color=#71717a] - Colour of the `unchecked-icon`.
44
+ * @cssproperty {color} [--c2-switch__icon__checked--color=#0265dc] - Colour of the `checked-icon`.
45
+ *
46
+ * @cssproperty {color} [--c2-switch__label--color=inherit]
47
+ * @cssproperty {font-size} [--c2-switch__label--font-size=inherit]
48
+ * @cssproperty {font-weight} [--c2-switch__label--font-weight=inherit]
49
+ * @cssproperty {line-height} [--c2-switch__label--line-height=inherit]
50
+ * @cssproperty {color} [--c2-switch__description--color=#71717a]
51
+ * @cssproperty {font-size} [--c2-switch__description--font-size=12px]
52
+ * @cssproperty {pixel} [--c2-switch__description--margin-top=2px]
53
+ *
54
+ * @cssproperty {time} [--c2-switch--transition-duration=200ms] - Thumb slide and colour change.
55
+ */
56
+ export declare class Switch extends LitElement {
57
+ static styles: import("lit").CSSResult;
58
+ protected formElement: HTMLInputElement;
59
+ private trackElement;
60
+ private thumbElement;
61
+ /** Whether the switch is on. */
62
+ checked: boolean;
63
+ /** Disables the control: it no longer toggles and is rendered dimmed. */
64
+ disabled: boolean;
65
+ /** Form field name forwarded to the inner input. */
66
+ name: string;
67
+ /** Form value submitted while on. Defaults to `on`, like a native checkbox. */
68
+ value: string;
69
+ /** Label text when the default slot is empty. */
70
+ label: string;
71
+ ariaLabel: string;
72
+ ariaLabelledBy: undefined | string;
73
+ ariaDescribedBy: undefined | string;
74
+ private hasDescription;
75
+ /** True while the thumb follows the pointer; disables the slide transition. */
76
+ private dragging;
77
+ private drag?;
78
+ /** The click that follows a drag must not toggle the input again. */
79
+ private suppressClick;
80
+ focus(options?: FocusOptions): void;
81
+ /** Flips the state (or forces it) and fires `change`, as a click would. */
82
+ toggle(force?: boolean): void;
83
+ /** `slotchange` does not fire for server-rendered slots, so read the description once after the first render. */
84
+ firstUpdated(): void;
85
+ protected update(changed: PropertyValues<this>): void;
86
+ private handleDescriptionChange;
87
+ private updateDescription;
88
+ private handleChange;
89
+ private get rtl();
90
+ private handlePointerDown;
91
+ private handlePointerMove;
92
+ private handlePointerUp;
93
+ private handlePointerCancel;
94
+ private endDrag;
95
+ private handleClick;
96
+ render(): import("lit-html").TemplateResult<1>;
97
+ }
98
+ declare global {
99
+ interface HTMLElementTagNameMap {
100
+ 'c2-switch': Switch;
101
+ }
102
+ }
103
+ //# sourceMappingURL=switch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAOtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,qBACa,MAAO,SAAQ,UAAU;IACpC,OAAgB,MAAM,0BAAoB;IAE1B,SAAS,CAAC,WAAW,EAAG,gBAAgB,CAAA;IAC7B,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAc;IAE7D,gCAAgC;IACY,OAAO,UAAQ;IAE3D,yEAAyE;IAC7B,QAAQ,UAAQ;IAE5D,oDAAoD;IACxC,IAAI,SAAK;IAErB,+EAA+E;IACnE,KAAK,SAAO;IAExB,iDAAiD;IACrC,KAAK,SAAK;IAGb,SAAS,EAAG,MAAM,CAAA;IAG3B,cAAc,EAAG,SAAS,GAAG,MAAM,CAAA;IAGnC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAA;IAE3B,OAAO,CAAC,cAAc,CAAQ;IACvC,+EAA+E;IACtE,OAAO,CAAC,QAAQ,CAAQ;IAEjC,OAAO,CAAC,IAAI,CAAC,CAAgH;IAC7H,qEAAqE;IACrE,OAAO,CAAC,aAAa,CAAQ;IAEpB,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY;IAIrC,2EAA2E;IAC3E,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO;IAQtB,iHAAiH;IACxG,YAAY;cAKF,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAKvD,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,YAAY;IAKpB,OAAO,KAAK,GAAG,GAEd;IAED,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,WAAW;IAMV,MAAM;CAsChB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,MAAM,CAAA;KACpB;CACF"}