@proximus/lavender-switch 2.0.0-alpha.20 → 2.0.0-alpha.200

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/Switch.d.ts CHANGED
@@ -15,12 +15,11 @@ export declare class Switch extends PxElement<HTMLInputElement> {
15
15
  formData(): FormData;
16
16
  static get formAssociated(): boolean;
17
17
  formResetCallback(): void;
18
- formStateRestoreCallback(state: any): void;
18
+ formStateRestoreCallback(state: boolean): void;
19
19
  setupForId(): void;
20
- get $label(): HTMLLabelElement;
21
- get $switch(): Element;
22
- get inverted(): string;
23
- set inverted(value: string);
20
+ get $switch(): Element | null;
21
+ get inverted(): boolean;
22
+ set inverted(value: boolean);
24
23
  get checked(): boolean;
25
24
  set checked(value: boolean);
26
25
  set disabled(value: boolean);
@@ -0,0 +1,173 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/Switch.ts",
8
+ "declarations": [
9
+ {
10
+ "kind": "class",
11
+ "description": "",
12
+ "name": "Switch",
13
+ "members": [
14
+ {
15
+ "kind": "field",
16
+ "name": "nativeName",
17
+ "type": {
18
+ "text": "string"
19
+ },
20
+ "static": true,
21
+ "default": "'input'"
22
+ },
23
+ {
24
+ "kind": "field",
25
+ "name": "accessorExclusions",
26
+ "type": {
27
+ "text": "array"
28
+ },
29
+ "static": true,
30
+ "default": "['checked', 'disabled']"
31
+ },
32
+ {
33
+ "kind": "field",
34
+ "name": "internals",
35
+ "type": {
36
+ "text": "ElementInternals"
37
+ },
38
+ "privacy": "protected"
39
+ },
40
+ {
41
+ "kind": "field",
42
+ "name": "template",
43
+ "privacy": "private"
44
+ },
45
+ {
46
+ "kind": "method",
47
+ "name": "formData",
48
+ "return": {
49
+ "type": {
50
+ "text": "FormData"
51
+ }
52
+ }
53
+ },
54
+ {
55
+ "kind": "field",
56
+ "name": "formAssociated",
57
+ "static": true,
58
+ "readonly": true
59
+ },
60
+ {
61
+ "kind": "method",
62
+ "name": "formResetCallback"
63
+ },
64
+ {
65
+ "kind": "method",
66
+ "name": "formStateRestoreCallback",
67
+ "parameters": [
68
+ {
69
+ "name": "state",
70
+ "type": {
71
+ "text": "boolean"
72
+ }
73
+ }
74
+ ]
75
+ },
76
+ {
77
+ "kind": "method",
78
+ "name": "setupForId"
79
+ },
80
+ {
81
+ "kind": "field",
82
+ "name": "$switch",
83
+ "readonly": true
84
+ },
85
+ {
86
+ "kind": "field",
87
+ "name": "inverted"
88
+ },
89
+ {
90
+ "kind": "field",
91
+ "name": "checked",
92
+ "type": {
93
+ "text": "boolean"
94
+ }
95
+ },
96
+ {
97
+ "kind": "field",
98
+ "name": "disabled",
99
+ "type": {
100
+ "text": "boolean"
101
+ }
102
+ },
103
+ {
104
+ "kind": "field",
105
+ "name": "innerHTML"
106
+ }
107
+ ],
108
+ "events": [
109
+ {
110
+ "name": "change",
111
+ "type": {
112
+ "text": "Event"
113
+ }
114
+ }
115
+ ],
116
+ "attributes": [
117
+ {
118
+ "name": "inverted"
119
+ },
120
+ {
121
+ "name": "hover"
122
+ }
123
+ ],
124
+ "superclass": {
125
+ "name": "PxElement",
126
+ "package": "@proximus/lavender-common"
127
+ },
128
+ "tagName": "px-switch",
129
+ "customElement": true
130
+ }
131
+ ],
132
+ "exports": [
133
+ {
134
+ "kind": "js",
135
+ "name": "Switch",
136
+ "declaration": {
137
+ "name": "Switch",
138
+ "module": "src/Switch.ts"
139
+ }
140
+ },
141
+ {
142
+ "kind": "custom-element-definition",
143
+ "name": "px-switch",
144
+ "declaration": {
145
+ "name": "Switch",
146
+ "module": "src/Switch.ts"
147
+ }
148
+ }
149
+ ]
150
+ },
151
+ {
152
+ "kind": "javascript-module",
153
+ "path": "src/index.ts",
154
+ "declarations": [],
155
+ "exports": [
156
+ {
157
+ "kind": "js",
158
+ "name": "*",
159
+ "declaration": {
160
+ "name": "*",
161
+ "module": "src/Switch"
162
+ }
163
+ }
164
+ ]
165
+ },
166
+ {
167
+ "kind": "javascript-module",
168
+ "path": "src/switch.css",
169
+ "declarations": [],
170
+ "exports": []
171
+ }
172
+ ]
173
+ }
package/dist/index.es.js CHANGED
@@ -1,99 +1,91 @@
1
- import { PxElement as l } from "@proximus/lavender-common";
2
- const d = ':host{display:inline-flex}.switch *{box-sizing:border-box}.switch{display:inline-flex;align-items:center;border-radius:var(--px-radius-pill)}.switch:focus-visible{outline:var(--px-focus-outline-mobile) solid var(--px-color-border-focus-outline-default);outline-offset:var(--px-focus-offset-mobile)}.switch:has(input[inverted]):focus-visible{outline-color:var(--px-color-border-focus-outline-inverted)}label{display:flex;flex-shrink:0;padding:var(--px-padding-3xs-mobile);border-radius:var(--px-radius-pill);background-color:var(--px-color-background-container-strong-default);outline:var(--px-size-border-m) solid var(--px-color-border-none-default);width:var(--px-size-action-input-switch-width);height:calc(var(--px-size-icon-m) + (var(--px-padding-3xs-mobile) * 2));position:relative}label:after{content:"";position:absolute;top:50%;left:var(--px-padding-3xs-mobile);width:var(--px-size-icon-m);max-width:var(--px-size-icon-m);height:var(--px-size-icon-m);border-radius:var(--px-radius-pill);background-color:var(--px-color-background-container-light-default);transform:translateY(-50%);transition:transform .2s ease-in-out}:host input{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin:0}:host(:not([disabled])):host(:hover) label,:host(:not([disabled])):host([hover]) label{outline-color:var(--px-color-border-neutral-default);cursor:pointer}:host([checked]) label{background-color:var(--px-color-background-purpose-success-default);transition:background-color .2s ease-in-out}:host([checked]) label:after{transform:translateY(-50%) translate(calc(var(--px-size-icon-m) - var(--px-padding-3xs-mobile)));transition:transform .2s ease-in-out}:host(:hover) :is(:host(:not([disabled])) :is(:host([checked]) label)),:host([hover]) :is(:host(:not([disabled])) :is(:host([checked]) label)){outline-color:var(--px-color-border-purpose-success-default)}:host([disabled]) label{background-color:var(--px-color-background-state-disabled-default)}:host([disabled]) label:after{background-color:var(--px-color-background-state-disabled-default)}:host([inverted]) label{background-color:var(--px-color-background-container-strong-inverted)}:host(:hover) :is(:host(:not([disabled])) :is(:host([inverted]) label)),:host([hover]) :is(:host(:not([disabled])) :is(:host([inverted]) label)){outline-color:var(--px-color-border-neutral-inverted)}:host([checked]:not([disabled])) :is(:host([inverted]) label){background-color:var(--px-color-background-purpose-success-inverted)}:host(:hover) :is(:host([checked]:not([disabled])) :is(:host([inverted]) label)),:host([hover]) :is(:host([checked]:not([disabled])) :is(:host([inverted]) label)){outline-color:var(--px-color-border-purpose-success-inverted)}:host([disabled]) :is(:host([inverted]) label){background-color:var(--px-color-background-state-disabled-inverted)}:host([disabled]) :is(:host([inverted]) label):after{background-color:var(--px-color-background-state-disabled-inverted)}@media only screen and (min-width: 48em){label{padding:var(--px-padding-3xs-desktop)}}@media only screen and (min-width: 64.0625em){label{padding:var(--px-padding-3xs-desktop)}}', a = new CSSStyleSheet();
3
- a.replaceSync(d);
4
- var c = /* @__PURE__ */ ((r) => (r.ERROR = "error", r.SUCCESS = "success", r))(c || {});
5
- const i = class i extends l {
6
- constructor() {
7
- var e;
8
- super(a), this.template = () => `<div class="switch" tabindex="0" role="switch">
9
- <input type="checkbox" tabindex="-1"/>
10
- <label></label>
11
- </div>`, this.shadowRoot.innerHTML = this.template(), this.internals = (e = this.attachInternals) == null ? void 0 : e.call(this);
12
- }
13
- static get observedAttributes() {
14
- return [...super.observedAttributes, "inverted", "hover"];
15
- }
16
- connectedCallback() {
17
- this.$el.addEventListener("change", () => {
18
- var t;
19
- this.checked = this.$el.checked;
20
- const e = new Event("change", {
21
- bubbles: !0,
22
- composed: !0
23
- // Allow the event to pass through shadow DOM boundaries
24
- });
25
- this.dispatchEvent(e), (t = this.internals) == null || t.setFormValue(this.formData());
26
- }), this.addEventListener("keypress", (e) => {
27
- (e.code === "Space" || e.code === "Enter") && this.$el.click();
28
- }), this.setupForId(), this.hasAttribute("checked") && (this.checked = !0), this.$switch.ariaChecked = `${this.checked}`;
29
- }
30
- attributeChangedCallback(e, t, s) {
31
- if (t !== s)
32
- switch (e) {
33
- case "checked":
34
- this.$el.checked = s !== null, this.$switch.ariaChecked = `${this.$el.checked}`;
35
- break;
36
- case "disabled":
37
- this.$el.disabled = s !== null, this.$switch.ariaDisabled = `${this.$el.disabled}`, this.$switch.tabIndex = this.$el.disabled ? -1 : 0;
38
- break;
39
- case "hover":
40
- this.$el.classList.toggle("hover");
41
- break;
42
- default:
43
- super.attributeChangedCallback(e, t, s);
44
- break;
45
- }
46
- }
47
- formData() {
48
- if (this.$el.name) {
49
- const e = new FormData();
50
- return e.append(this.getAttribute("name"), this.$el.value), e;
51
- }
52
- }
53
- // Form-associated callbacks
54
- static get formAssociated() {
55
- return !0;
56
- }
57
- // Set default behavior when the element is attached to a form
58
- formResetCallback() {
59
- this.checked = !1;
60
- }
61
- formStateRestoreCallback(e) {
62
- this.checked = e;
63
- }
64
- setupForId() {
65
- const e = Math.random().toString(36).substr(2, 9);
66
- this.$el.setAttribute("id", e), this.$label && this.$label.setAttribute("for", e);
67
- }
68
- get $label() {
69
- return this.shadowRoot.querySelector("label");
70
- }
71
- get $switch() {
72
- return this.shadowRoot.querySelector(".switch");
73
- }
74
- get inverted() {
75
- return this.getAttribute("inverted");
76
- }
77
- set inverted(e) {
78
- this.setAttribute("inverted", e);
79
- }
80
- get checked() {
81
- return this.$el.checked;
82
- }
83
- set checked(e) {
84
- this.$el.checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked"), this.$switch.ariaChecked = `${e}`;
85
- }
86
- set disabled(e) {
87
- this.$el.disabled = e, e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled"), this.$switch.ariaDisabled = `${e}`;
88
- }
89
- get disabled() {
90
- return this.$el.disabled;
91
- }
92
- };
93
- i.nativeName = "input", i.accessorExclusions = ["checked", "disabled"];
94
- let o = i;
95
- customElements.get("px-switch") || customElements.define("px-switch", o);
96
- export {
97
- c as InputState,
98
- o as Switch
1
+ import { PxElement as e } from "@proximus/lavender-common";
2
+ //#region src/switch.css?inline
3
+ var t = ":host{display:inline-flex}.switch *{box-sizing:border-box}.switch{border-radius:var(--px-radius-pill);align-items:center;display:inline-flex}:host(:focus-visible){outline:none}:host(:focus-visible) .switch{outline:var(--px-focus-outline-mobile) solid var(--px-color-border-focus-outline-default);outline-offset:var(--px-focus-offset-mobile)}:host([inverted]:focus-visible) .switch{outline-color:var(--px-color-border-focus-outline-inverted)}label{padding:var(--px-padding-3xs-mobile);border-radius:var(--px-radius-pill);background-color:var(--px-color-background-container-strong-default);outline:var(--px-size-border-m) solid var(--px-color-border-none-default);width:var(--px-size-action-input-switch-width);height:calc(var(--px-size-icon-m) + (var(--px-padding-3xs-mobile) * 2));flex-shrink:0;display:flex;position:relative}label:after{content:\"\";top:50%;left:var(--px-padding-3xs-mobile);width:var(--px-size-icon-m);max-width:var(--px-size-icon-m);height:var(--px-size-icon-m);border-radius:var(--px-radius-pill);background-color:var(--px-color-background-container-light-default);transition:transform .2s ease-in-out;position:absolute;transform:translateY(-50%)}:host input{appearance:none;margin:0}:is(:host(:not([disabled])):host(:hover),:host(:not([disabled])):host([hover])) label{outline-color:var(--px-color-border-neutral-default);cursor:pointer}:host([checked]) label{background-color:var(--px-color-background-purpose-success-default);transition:background-color .2s ease-in-out}:host([checked]) label:after{transform:translateY(-50%) translateX(calc(var(--px-size-icon-m) - var(--px-padding-3xs-mobile)));transition:transform .2s ease-in-out}:host(:hover) :is(:host(:not([disabled])) :is(:host([checked]) label)),:host([hover]) :is(:host(:not([disabled])) :is(:host([checked]) label)){outline-color:var(--px-color-border-purpose-success-default)}:host([disabled]) label{background-color:var(--px-color-background-state-disabled-default)}:host([disabled]) label:after{background-color:var(--px-color-background-state-disabled-default)}:host([inverted]) label{background-color:var(--px-color-background-container-strong-inverted)}:host(:hover) :is(:host(:not([disabled])) :is(:host([inverted]) label)),:host([hover]) :is(:host(:not([disabled])) :is(:host([inverted]) label)){outline-color:var(--px-color-border-neutral-inverted)}:host([checked]:not([disabled])) :is(:host([inverted]) label){background-color:var(--px-color-background-purpose-success-inverted)}:host(:hover) :is(:host([checked]:not([disabled])) :is(:host([inverted]) label)),:host([hover]) :is(:host([checked]:not([disabled])) :is(:host([inverted]) label)){outline-color:var(--px-color-border-purpose-success-inverted)}:host([disabled]) :is(:host([inverted]) label){background-color:var(--px-color-background-state-disabled-inverted)}:host([disabled]) :is(:host([inverted]) label):after{background-color:var(--px-color-background-state-disabled-inverted)}@media screen and (width>=48rem){label{padding:var(--px-padding-3xs-desktop)}}@media screen and (width>=64.0625rem){label{padding:var(--px-padding-3xs-desktop)}}", n = new CSSStyleSheet();
4
+ n.replaceSync(t);
5
+ var r = /* @__PURE__ */ function(e) {
6
+ return e.ERROR = "error", e.SUCCESS = "success", e;
7
+ }({}), i = class extends e {
8
+ static {
9
+ this.nativeName = "input";
10
+ }
11
+ static {
12
+ this.accessorExclusions = ["checked", "disabled"];
13
+ }
14
+ constructor() {
15
+ super(n), this.template = () => "<div class=\"switch\">\n <input type=\"checkbox\" tabindex=\"-1\" inert/>\n <label></label>\n </div>", this.shadowRoot.innerHTML = this.template(), this.internals = this.attachInternals?.();
16
+ }
17
+ static get observedAttributes() {
18
+ return [
19
+ ...super.observedAttributes,
20
+ "inverted",
21
+ "hover"
22
+ ];
23
+ }
24
+ connectedCallback() {
25
+ this.role = "switch";
26
+ let e = () => {
27
+ this.disabled || (this.checked = !this.checked, this.dispatchEvent(new Event("change", {
28
+ bubbles: !0,
29
+ composed: !0
30
+ })), this.internals?.setFormValue(this.formData()));
31
+ };
32
+ this.addEventListener("click", e), this.addEventListener("keypress", (t) => {
33
+ (t.code === "Space" || t.code === "Enter") && e();
34
+ }), this.tabIndex = 0, this.hasAttribute("checked") && (this.checked = !0), this.ariaChecked = `${this.checked}`;
35
+ }
36
+ attributeChangedCallback(e, t, n) {
37
+ if (t !== n) switch (e) {
38
+ case "checked":
39
+ this.$el.checked = n !== null, this.ariaChecked = `${this.$el.checked}`;
40
+ break;
41
+ case "disabled":
42
+ this.$el.disabled = n !== null, this.ariaDisabled = `${this.$el.disabled}`, this.tabIndex = this.$el.disabled ? -1 : 0;
43
+ break;
44
+ case "hover":
45
+ this.$el.classList.toggle("hover");
46
+ break;
47
+ default: super.attributeChangedCallback(e, t, n);
48
+ }
49
+ }
50
+ formData() {
51
+ let e = new FormData(), t = this.getAttribute("name");
52
+ return this.$el.name && t && e.append(t, this.$el.value), e;
53
+ }
54
+ static get formAssociated() {
55
+ return !0;
56
+ }
57
+ formResetCallback() {
58
+ this.checked = !1;
59
+ }
60
+ formStateRestoreCallback(e) {
61
+ this.checked = e;
62
+ }
63
+ setupForId() {
64
+ let e = Math.random().toString(36).substr(2, 9);
65
+ this.$el.setAttribute("id", e);
66
+ }
67
+ get $switch() {
68
+ return this.shadowRoot.querySelector(".switch");
69
+ }
70
+ get inverted() {
71
+ return this.hasAttribute("inverted");
72
+ }
73
+ set inverted(e) {
74
+ this._updateBooleanAttribute("inverted", e);
75
+ }
76
+ get checked() {
77
+ return this.$el.checked;
78
+ }
79
+ set checked(e) {
80
+ this.$el.checked = e, this._updateBooleanAttribute("checked", e), this.ariaChecked = `${e}`;
81
+ }
82
+ set disabled(e) {
83
+ this.$el.disabled = e, this._updateBooleanAttribute("disabled", e), this.ariaDisabled = `${e}`, this.tabIndex = e ? -1 : 0;
84
+ }
85
+ get disabled() {
86
+ return this.$el.disabled;
87
+ }
99
88
  };
89
+ customElements.get("px-switch") || customElements.define("px-switch", i);
90
+ //#endregion
91
+ export { r as InputState, i as Switch };
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-css-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "properties": [],
5
+ "pseudoElements": []
6
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-html-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "tags": [
5
+ {
6
+ "name": "px-switch",
7
+ "description": "\n---\n\n\n### **Events:**\n - **change**",
8
+ "attributes": [
9
+ { "name": "inverted", "values": [] },
10
+ { "name": "hover", "values": [] }
11
+ ],
12
+ "references": []
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
+ "name": "@proximus/lavender-switch",
4
+ "version": "2.0.0-alpha.200",
5
+ "description-markup": "markdown",
6
+ "contributions": {
7
+ "html": {
8
+ "elements": [
9
+ {
10
+ "name": "px-switch",
11
+ "description": "\n---\n\n\n### **Events:**\n - **change**",
12
+ "doc-url": "",
13
+ "attributes": [
14
+ { "name": "inverted", "value": { "type": "string" } },
15
+ { "name": "hover", "value": { "type": "string" } }
16
+ ],
17
+ "events": [{ "name": "change", "type": "Event" }],
18
+ "js": {
19
+ "properties": [
20
+ { "name": "$switch" },
21
+ { "name": "inverted" },
22
+ { "name": "checked", "type": "boolean" },
23
+ { "name": "disabled", "type": "boolean" },
24
+ { "name": "innerHTML" }
25
+ ],
26
+ "events": [{ "name": "change", "type": "Event" }]
27
+ }
28
+ }
29
+ ]
30
+ },
31
+ "css": {
32
+ "properties": [],
33
+ "pseudo-elements": []
34
+ }
35
+ }
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proximus/lavender-switch",
3
- "version": "2.0.0-alpha.20",
3
+ "version": "2.0.0-alpha.200",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "clean": "rm -rf dist",
14
14
  "build": "npm run clean && NODE_ENV=development vite build && tsc && npm run transform-package-json && npm run wc-manifest",
15
15
  "test": "vitest run --coverage",
16
- "wc-manifest": "cem analyze --globs \"src/*\" --config ../custom-elements-manifest.config.js --outdir dist"
16
+ "wc-manifest": "cem analyze --globs \"src/*\" --config ../../custom-elements-manifest.config.js --outdir dist"
17
17
  },
18
18
  "publishConfig": {
19
19
  "access": "public"