@proximus/lavender-switch 2.0.0-alpha.165 → 2.0.0-alpha.169
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 +4 -4
- package/dist/index.es.js +90 -93
- package/package.json +1 -1
package/dist/Switch.d.ts
CHANGED
|
@@ -15,11 +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:
|
|
18
|
+
formStateRestoreCallback(state: boolean): void;
|
|
19
19
|
setupForId(): void;
|
|
20
|
-
get $switch(): Element;
|
|
21
|
-
get inverted():
|
|
22
|
-
set inverted(value:
|
|
20
|
+
get $switch(): Element | null;
|
|
21
|
+
get inverted(): boolean;
|
|
22
|
+
set inverted(value: boolean);
|
|
23
23
|
get checked(): boolean;
|
|
24
24
|
set checked(value: boolean);
|
|
25
25
|
set disabled(value: boolean);
|
package/dist/index.es.js
CHANGED
|
@@ -1,94 +1,91 @@
|
|
|
1
|
-
import { PxElement as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
i.nativeName = "input", i.accessorExclusions = ["checked", "disabled"];
|
|
89
|
-
let o = i;
|
|
90
|
-
customElements.get("px-switch") || customElements.define("px-switch", o);
|
|
91
|
-
export {
|
|
92
|
-
c as InputState,
|
|
93
|
-
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
|
+
}
|
|
94
88
|
};
|
|
89
|
+
customElements.get("px-switch") || customElements.define("px-switch", i);
|
|
90
|
+
//#endregion
|
|
91
|
+
export { r as InputState, i as Switch };
|