@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 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: any): void;
18
+ formStateRestoreCallback(state: boolean): void;
19
19
  setupForId(): void;
20
- get $switch(): Element;
21
- get inverted(): string;
22
- set inverted(value: string);
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 d } from "@proximus/lavender-common";
2
- const l = ':host{display:inline-flex}.switch *{box-sizing:border-box}.switch{display:inline-flex;align-items:center;border-radius:var(--px-radius-pill)}: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{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 screen and (min-width: 48rem){label{padding:var(--px-padding-3xs-desktop)}}@media screen and (min-width: 64.0625rem){label{padding:var(--px-padding-3xs-desktop)}}', a = new CSSStyleSheet();
3
- a.replaceSync(l);
4
- var c = /* @__PURE__ */ ((r) => (r.ERROR = "error", r.SUCCESS = "success", r))(c || {});
5
- const i = class i extends d {
6
- constructor() {
7
- var e;
8
- super(a), this.template = () => `<div class="switch">
9
- <input type="checkbox" tabindex="-1" inert/>
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.role = "switch";
18
- const e = () => {
19
- var t;
20
- this.disabled || (this.checked = !this.checked, this.dispatchEvent(
21
- new Event("change", { bubbles: !0, composed: !0 })
22
- ), (t = this.internals) == null || t.setFormValue(this.formData()));
23
- };
24
- this.addEventListener("click", e), this.addEventListener("keypress", (t) => {
25
- (t.code === "Space" || t.code === "Enter") && e();
26
- }), this.tabIndex = 0, this.hasAttribute("checked") && (this.checked = !0), this.ariaChecked = `${this.checked}`;
27
- }
28
- attributeChangedCallback(e, t, s) {
29
- if (t !== s)
30
- switch (e) {
31
- case "checked":
32
- this.$el.checked = s !== null, this.ariaChecked = `${this.$el.checked}`;
33
- break;
34
- case "disabled":
35
- this.$el.disabled = s !== null, this.ariaDisabled = `${this.$el.disabled}`, this.tabIndex = this.$el.disabled ? -1 : 0;
36
- break;
37
- case "hover":
38
- this.$el.classList.toggle("hover");
39
- break;
40
- default:
41
- super.attributeChangedCallback(e, t, s);
42
- break;
43
- }
44
- }
45
- formData() {
46
- if (this.$el.name) {
47
- const e = new FormData();
48
- return e.append(this.getAttribute("name"), this.$el.value), e;
49
- }
50
- }
51
- // Form-associated callbacks
52
- static get formAssociated() {
53
- return !0;
54
- }
55
- // Set default behavior when the element is attached to a form
56
- formResetCallback() {
57
- this.checked = !1;
58
- }
59
- formStateRestoreCallback(e) {
60
- this.checked = e;
61
- }
62
- setupForId() {
63
- const e = Math.random().toString(36).substr(2, 9);
64
- this.$el.setAttribute("id", e);
65
- }
66
- get $switch() {
67
- return this.shadowRoot.querySelector(".switch");
68
- }
69
- get inverted() {
70
- return this.getAttribute("inverted");
71
- }
72
- set inverted(e) {
73
- this.setAttribute("inverted", e);
74
- }
75
- get checked() {
76
- return this.$el.checked;
77
- }
78
- set checked(e) {
79
- this.$el.checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked"), this.ariaChecked = `${e}`;
80
- }
81
- set disabled(e) {
82
- this.$el.disabled = e, e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled"), this.ariaDisabled = `${e}`, this.tabIndex = e ? -1 : 0;
83
- }
84
- get disabled() {
85
- return this.$el.disabled;
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proximus/lavender-switch",
3
- "version": "2.0.0-alpha.165",
3
+ "version": "2.0.0-alpha.169",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",