@proximus/lavender-switch 1.0.0-alpha.2

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.
Files changed (2) hide show
  1. package/dist/index.js +93 -0
  2. package/package.json +41 -0
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ import { PxElement as d } from "@proximus/lavender-common";
2
+ const n = ':host{display:inline-flex}.switch *{box-sizing:border-box}.switch{display:inline-flex;align-items:center;border-radius:var(--px-radius-pill)}label{display:flex;flex-shrink:0;padding:var(--px-padding-3xs-mobile);border-radius:var(--px-radius-pill);background-color:var(--px-background-color-action-neutral-strong-default);box-shadow:0 0 0 var(--px-border-size-m) var(--px-border-color-none);width:var(--px-action-input-switch-size-width);height:calc(var(--px-action-size-m) + var(--px-padding-3xs-mobile) * 2);position:relative}input:not([disabled])+label:hover:not([disabled]){box-shadow:0 0 0 var(--px-border-size-m) var(--px-border-color-action-neutral-default)}label:focus{outline:2px solid black}label:after{content:"";position:absolute;top:50%;left:var(--px-padding-3xs-mobile);width:var(--px-action-size-m);max-width:var(--px-action-size-m);height:var(--px-action-size-m);border-radius:var(--px-radius-pill);background-color:var(--px-background-color-action-neutral-bare-default);transform:translateY(-50%);transition:transform .2s ease-in-out}input{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin:0}input:checked+label{background-color:var(--px-background-color-purpose-success-default);transition:background-color .2s ease-in-out}input:not([disabled])+:is(input:checked+label):hover{box-shadow:0 0 0 var(--px-border-size-m) var(--px-border-color-purpose-success-default)}input:checked+label:after{transform:translateY(-50%) translate(calc(var(--px-action-size-m) - var(--px-padding-3xs-mobile)));transition:transform .2s ease-in-out}input[disabled]+label{background-color:var(--px-background-color-action-disabled-default)}input[disabled]+label:after{background-color:var(--px-background-color-action-disabled-default)}input[inverted]+label{background-color:var( --px-background-color-action-neutral-strong-inverted )}input[inverted]:not([disabled])+label:hover{box-shadow:0 0 0 var(--px-border-size-m) var(--px-border-color-action-neutral-inverted)}input[inverted]:checked:not([disabled])+label{background-color:var(--px-background-color-purpose-success-inverted)}input[inverted]:checked:not([disabled])+label:hover{box-shadow:0 0 0 var(--px-border-size-m) var(--px-border-color-purpose-success-inverted)}input[inverted][disabled]+label{background-color:var(--px-background-color-action-disabled-inverted)}input[inverted][disabled]+label:after{background-color:var(--px-background-color-action-disabled-inverted)}@media only screen and (min-width: 768px){label{padding:var(--px-padding-3xs-tablet)}}@media only screen and (min-width: 1025px){label{padding:var(--px-padding-3xs-desktop)}}', o = new CSSStyleSheet();
3
+ o.replaceSync(n);
4
+ var l = /* @__PURE__ */ ((r) => (r.ERROR = "error", r.SUCCESS = "success", r))(l || {});
5
+ const s = class s extends d {
6
+ constructor() {
7
+ var e;
8
+ super(o), 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"];
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, i) {
31
+ if (t !== i)
32
+ switch (e) {
33
+ case "checked":
34
+ this.$el.checked = i !== null, this.$switch.ariaChecked = `${this.$el.checked}`;
35
+ break;
36
+ case "disabled":
37
+ this.$el.disabled = i !== null, this.$switch.ariaDisabled = `${this.$el.disabled}`;
38
+ break;
39
+ default:
40
+ super.attributeChangedCallback(e, t, i);
41
+ break;
42
+ }
43
+ }
44
+ formData() {
45
+ if (this.$el.name) {
46
+ const e = new FormData();
47
+ return e.append(this.getAttribute("name"), this.$el.value), e;
48
+ }
49
+ }
50
+ // Form-associated callbacks
51
+ static get formAssociated() {
52
+ return !0;
53
+ }
54
+ // Set default behavior when the element is attached to a form
55
+ formResetCallback() {
56
+ this.$el.value = "";
57
+ }
58
+ setupForId() {
59
+ const e = Math.random().toString(36).substr(2, 9);
60
+ this.$el.setAttribute("id", e), this.$label && this.$label.setAttribute("for", e);
61
+ }
62
+ get $label() {
63
+ return this.shadowRoot.querySelector("label");
64
+ }
65
+ get $switch() {
66
+ return this.shadowRoot.querySelector(".switch");
67
+ }
68
+ get inverted() {
69
+ return this.getAttribute("inverted");
70
+ }
71
+ set inverted(e) {
72
+ this.setAttribute("inverted", e);
73
+ }
74
+ get checked() {
75
+ return this.$el.checked;
76
+ }
77
+ set checked(e) {
78
+ this.$el.checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked"), this.$switch.ariaChecked = `${e}`;
79
+ }
80
+ set disabled(e) {
81
+ this.$el.disabled = e, e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled"), this.$switch.ariaDisabled = `${e}`;
82
+ }
83
+ get disabled() {
84
+ return this.$el.disabled;
85
+ }
86
+ };
87
+ s.nativeName = "input";
88
+ let a = s;
89
+ customElements.define("px-switch", a);
90
+ export {
91
+ l as InputState,
92
+ a as Switch
93
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@proximus/lavender-switch",
3
+ "version": "1.0.0-alpha.2",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.ts",
9
+ "development": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./src/*.css": {
13
+ "development": "src/*.css"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "type": "module",
20
+ "scripts": {
21
+ "build": "rm -rf dist;tsc; vite build",
22
+ "test": "vitest run --coverage"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "gitHead": "bad89d519c6fc1d431ebc46bee89fcd80cf18b83",
28
+ "lerna": {
29
+ "command": {
30
+ "publish": {
31
+ "assets": [
32
+ "CHANGELOG.md",
33
+ "package.json",
34
+ "dist/*.js",
35
+ "dist/*.cjs",
36
+ "dist/css/**/*.css"
37
+ ]
38
+ }
39
+ }
40
+ }
41
+ }