@proximus/lavender-switch 2.0.0-alpha.17 → 2.0.0-alpha.170

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);
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proximus/lavender-switch",
3
- "version": "2.0.0-alpha.17",
3
+ "version": "2.0.0-alpha.170",
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"