@proximus/lavender-switch 2.0.0-alpha.21 → 2.0.0-alpha.211

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
@@ -4,10 +4,10 @@ export declare enum InputState {
4
4
  SUCCESS = "success"
5
5
  }
6
6
  export declare class Switch extends PxElement<HTMLInputElement> {
7
+ protected static readonly template: HTMLTemplateElement;
7
8
  static nativeName: string;
8
9
  static accessorExclusions: string[];
9
10
  protected internals: ElementInternals;
10
- private template;
11
11
  constructor();
12
12
  static get observedAttributes(): string[];
13
13
  connectedCallback(): void;
@@ -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,171 @@
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": "template",
17
+ "privacy": "protected",
18
+ "static": true,
19
+ "readonly": true
20
+ },
21
+ {
22
+ "kind": "field",
23
+ "name": "nativeName",
24
+ "type": {
25
+ "text": "string"
26
+ },
27
+ "static": true,
28
+ "default": "'input'"
29
+ },
30
+ {
31
+ "kind": "field",
32
+ "name": "accessorExclusions",
33
+ "type": {
34
+ "text": "array"
35
+ },
36
+ "static": true,
37
+ "default": "['checked', 'disabled']"
38
+ },
39
+ {
40
+ "kind": "field",
41
+ "name": "internals",
42
+ "type": {
43
+ "text": "ElementInternals"
44
+ },
45
+ "privacy": "protected"
46
+ },
47
+ {
48
+ "kind": "method",
49
+ "name": "formData",
50
+ "return": {
51
+ "type": {
52
+ "text": "FormData"
53
+ }
54
+ }
55
+ },
56
+ {
57
+ "kind": "field",
58
+ "name": "formAssociated",
59
+ "static": true,
60
+ "readonly": true
61
+ },
62
+ {
63
+ "kind": "method",
64
+ "name": "formResetCallback"
65
+ },
66
+ {
67
+ "kind": "method",
68
+ "name": "formStateRestoreCallback",
69
+ "parameters": [
70
+ {
71
+ "name": "state",
72
+ "type": {
73
+ "text": "boolean"
74
+ }
75
+ }
76
+ ]
77
+ },
78
+ {
79
+ "kind": "method",
80
+ "name": "setupForId"
81
+ },
82
+ {
83
+ "kind": "field",
84
+ "name": "$switch",
85
+ "readonly": true
86
+ },
87
+ {
88
+ "kind": "field",
89
+ "name": "inverted"
90
+ },
91
+ {
92
+ "kind": "field",
93
+ "name": "checked",
94
+ "type": {
95
+ "text": "boolean"
96
+ }
97
+ },
98
+ {
99
+ "kind": "field",
100
+ "name": "disabled",
101
+ "type": {
102
+ "text": "boolean"
103
+ }
104
+ }
105
+ ],
106
+ "events": [
107
+ {
108
+ "name": "change",
109
+ "type": {
110
+ "text": "Event"
111
+ }
112
+ }
113
+ ],
114
+ "attributes": [
115
+ {
116
+ "name": "inverted"
117
+ },
118
+ {
119
+ "name": "hover"
120
+ }
121
+ ],
122
+ "superclass": {
123
+ "name": "PxElement",
124
+ "package": "@proximus/lavender-common"
125
+ },
126
+ "tagName": "px-switch",
127
+ "customElement": true
128
+ }
129
+ ],
130
+ "exports": [
131
+ {
132
+ "kind": "js",
133
+ "name": "Switch",
134
+ "declaration": {
135
+ "name": "Switch",
136
+ "module": "src/Switch.ts"
137
+ }
138
+ },
139
+ {
140
+ "kind": "custom-element-definition",
141
+ "name": "px-switch",
142
+ "declaration": {
143
+ "name": "Switch",
144
+ "module": "src/Switch.ts"
145
+ }
146
+ }
147
+ ]
148
+ },
149
+ {
150
+ "kind": "javascript-module",
151
+ "path": "src/index.ts",
152
+ "declarations": [],
153
+ "exports": [
154
+ {
155
+ "kind": "js",
156
+ "name": "*",
157
+ "declaration": {
158
+ "name": "*",
159
+ "module": "src/Switch"
160
+ }
161
+ }
162
+ ]
163
+ },
164
+ {
165
+ "kind": "javascript-module",
166
+ "path": "src/switch.css",
167
+ "declarations": [],
168
+ "exports": []
169
+ }
170
+ ]
171
+ }
package/dist/index.es.js CHANGED
@@ -1,99 +1,94 @@
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
- }
1
+ import { PxElement as e, createTemplate as t, renderTemplate as n } from "@proximus/lavender-common";
2
+ //#region src/switch.css?inline
3
+ var r = ":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)}}", i = new CSSStyleSheet();
4
+ i.replaceSync(r);
5
+ var a = /* @__PURE__ */ function(e) {
6
+ return e.ERROR = "error", e.SUCCESS = "success", e;
7
+ }({}), o = class r extends e {
8
+ static {
9
+ this.template = t("<div class=\"switch\"><input type=\"checkbox\" tabindex=\"-1\" inert/><label></label></div>");
10
+ }
11
+ static {
12
+ this.nativeName = "input";
13
+ }
14
+ static {
15
+ this.accessorExclusions = ["checked", "disabled"];
16
+ }
17
+ constructor() {
18
+ super(i), n(this.shadowRoot, r.template), this.internals = this.attachInternals?.();
19
+ }
20
+ static get observedAttributes() {
21
+ return [
22
+ ...super.observedAttributes,
23
+ "inverted",
24
+ "hover"
25
+ ];
26
+ }
27
+ connectedCallback() {
28
+ this.role = "switch";
29
+ let e = () => {
30
+ this.disabled || (this.checked = !this.checked, this.dispatchEvent(new Event("change", {
31
+ bubbles: !0,
32
+ composed: !0
33
+ })), this.internals?.setFormValue(this.formData()));
34
+ };
35
+ this.addEventListener("click", e), this.addEventListener("keypress", (t) => {
36
+ (t.code === "Space" || t.code === "Enter") && e();
37
+ }), this.tabIndex = 0, this.hasAttribute("checked") && (this.checked = !0), this.ariaChecked = `${this.checked}`;
38
+ }
39
+ attributeChangedCallback(e, t, n) {
40
+ if (t !== n) switch (e) {
41
+ case "checked":
42
+ this.$el.checked = n !== null, this.ariaChecked = `${this.$el.checked}`;
43
+ break;
44
+ case "disabled":
45
+ this.$el.disabled = n !== null, this.ariaDisabled = `${this.$el.disabled}`, this.tabIndex = this.$el.disabled ? -1 : 0;
46
+ break;
47
+ case "hover":
48
+ this.$el.classList.toggle("hover");
49
+ break;
50
+ default: super.attributeChangedCallback(e, t, n);
51
+ }
52
+ }
53
+ formData() {
54
+ let e = new FormData(), t = this.getAttribute("name");
55
+ return this.$el.name && t && e.append(t, this.$el.value), e;
56
+ }
57
+ static get formAssociated() {
58
+ return !0;
59
+ }
60
+ formResetCallback() {
61
+ this.checked = !1;
62
+ }
63
+ formStateRestoreCallback(e) {
64
+ this.checked = e;
65
+ }
66
+ setupForId() {
67
+ let e = Math.random().toString(36).substr(2, 9);
68
+ this.$el.setAttribute("id", e);
69
+ }
70
+ get $switch() {
71
+ return this.shadowRoot.querySelector(".switch");
72
+ }
73
+ get inverted() {
74
+ return this.hasAttribute("inverted");
75
+ }
76
+ set inverted(e) {
77
+ this._updateBooleanAttribute("inverted", e);
78
+ }
79
+ get checked() {
80
+ return this.$el.checked;
81
+ }
82
+ set checked(e) {
83
+ this.$el.checked = e, this._updateBooleanAttribute("checked", e), this.ariaChecked = `${e}`;
84
+ }
85
+ set disabled(e) {
86
+ this.$el.disabled = e, this._updateBooleanAttribute("disabled", e), this.ariaDisabled = `${e}`, this.tabIndex = e ? -1 : 0;
87
+ }
88
+ get disabled() {
89
+ return this.$el.disabled;
90
+ }
92
91
  };
93
- i.nativeName = "input", i.accessorExclusions = ["checked", "disabled"];
94
- let o = i;
95
92
  customElements.get("px-switch") || customElements.define("px-switch", o);
96
- export {
97
- c as InputState,
98
- o as Switch
99
- };
93
+ //#endregion
94
+ export { a as InputState, o 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,35 @@
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.211",
5
+ "description-markup": "markdown",
6
+ "contributions": {
7
+ "html": {
8
+ "elements": [
9
+ {
10
+ "name": "px-switch",
11
+ "description": "\n\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
+ ],
25
+ "events": [{ "name": "change", "type": "Event" }]
26
+ }
27
+ }
28
+ ]
29
+ },
30
+ "css": {
31
+ "properties": [],
32
+ "pseudo-elements": []
33
+ }
34
+ }
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proximus/lavender-switch",
3
- "version": "2.0.0-alpha.21",
3
+ "version": "2.0.0-alpha.211",
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"