@proximus/lavender-switch 1.4.8-beta.3 → 1.4.8
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 +1 -0
- package/dist/index.es.js +29 -24
- package/package.json +1 -1
package/dist/Switch.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class Switch extends PxElement<HTMLInputElement> {
|
|
|
17
17
|
formResetCallback(): void;
|
|
18
18
|
formStateRestoreCallback(state: any): void;
|
|
19
19
|
setupForId(): void;
|
|
20
|
+
get $label(): HTMLLabelElement;
|
|
20
21
|
get $switch(): Element;
|
|
21
22
|
get inverted(): string;
|
|
22
23
|
set inverted(value: string);
|
package/dist/index.es.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { PxElement as
|
|
2
|
-
const
|
|
3
|
-
a.replaceSync(
|
|
4
|
-
var c = /* @__PURE__ */ ((
|
|
5
|
-
const i = class i extends
|
|
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
6
|
constructor() {
|
|
7
7
|
var e;
|
|
8
|
-
super(a), this.template = () => `<div class="switch">
|
|
9
|
-
<input type="checkbox" tabindex="-1"
|
|
8
|
+
super(a), this.template = () => `<div class="switch" tabindex="0" role="switch">
|
|
9
|
+
<input type="checkbox" tabindex="-1"/>
|
|
10
10
|
<label></label>
|
|
11
11
|
</div>`, this.shadowRoot.innerHTML = this.template(), this.internals = (e = this.attachInternals) == null ? void 0 : e.call(this);
|
|
12
12
|
}
|
|
@@ -14,25 +14,27 @@ const i = class i extends d {
|
|
|
14
14
|
return [...super.observedAttributes, "inverted", "hover"];
|
|
15
15
|
}
|
|
16
16
|
connectedCallback() {
|
|
17
|
-
this.
|
|
18
|
-
const e = () => {
|
|
17
|
+
this.$el.addEventListener("change", () => {
|
|
19
18
|
var t;
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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}`;
|
|
27
29
|
}
|
|
28
30
|
attributeChangedCallback(e, t, s) {
|
|
29
31
|
if (t !== s)
|
|
30
32
|
switch (e) {
|
|
31
33
|
case "checked":
|
|
32
|
-
this.$el.checked = s !== null, this.ariaChecked = `${this.$el.checked}`;
|
|
34
|
+
this.$el.checked = s !== null, this.$switch.ariaChecked = `${this.$el.checked}`;
|
|
33
35
|
break;
|
|
34
36
|
case "disabled":
|
|
35
|
-
this.$el.disabled = s !== null, this.ariaDisabled = `${this.$el.disabled}`, this.tabIndex = this.$el.disabled ? -1 : 0;
|
|
37
|
+
this.$el.disabled = s !== null, this.$switch.ariaDisabled = `${this.$el.disabled}`, this.$switch.tabIndex = this.$el.disabled ? -1 : 0;
|
|
36
38
|
break;
|
|
37
39
|
case "hover":
|
|
38
40
|
this.$el.classList.toggle("hover");
|
|
@@ -61,7 +63,10 @@ const i = class i extends d {
|
|
|
61
63
|
}
|
|
62
64
|
setupForId() {
|
|
63
65
|
const e = Math.random().toString(36).substr(2, 9);
|
|
64
|
-
this.$el.setAttribute("id", e);
|
|
66
|
+
this.$el.setAttribute("id", e), this.$label && this.$label.setAttribute("for", e);
|
|
67
|
+
}
|
|
68
|
+
get $label() {
|
|
69
|
+
return this.shadowRoot.querySelector("label");
|
|
65
70
|
}
|
|
66
71
|
get $switch() {
|
|
67
72
|
return this.shadowRoot.querySelector(".switch");
|
|
@@ -76,19 +81,19 @@ const i = class i extends d {
|
|
|
76
81
|
return this.$el.checked;
|
|
77
82
|
}
|
|
78
83
|
set checked(e) {
|
|
79
|
-
this.$el.checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked"), this.ariaChecked = `${e}`;
|
|
84
|
+
this.$el.checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked"), this.$switch.ariaChecked = `${e}`;
|
|
80
85
|
}
|
|
81
86
|
set disabled(e) {
|
|
82
|
-
this.$el.disabled = e, e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled"), this.ariaDisabled = `${e}
|
|
87
|
+
this.$el.disabled = e, e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled"), this.$switch.ariaDisabled = `${e}`;
|
|
83
88
|
}
|
|
84
89
|
get disabled() {
|
|
85
90
|
return this.$el.disabled;
|
|
86
91
|
}
|
|
87
92
|
};
|
|
88
93
|
i.nativeName = "input", i.accessorExclusions = ["checked", "disabled"];
|
|
89
|
-
let
|
|
90
|
-
customElements.get("px-switch") || customElements.define("px-switch",
|
|
94
|
+
let o = i;
|
|
95
|
+
customElements.get("px-switch") || customElements.define("px-switch", o);
|
|
91
96
|
export {
|
|
92
97
|
c as InputState,
|
|
93
|
-
|
|
98
|
+
o as Switch
|
|
94
99
|
};
|