wj-elements 0.1.229 → 0.1.231

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.
@@ -1,124 +1,203 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import WJElement from "./wje-element.js";
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var _internalValue;
9
+ import { F as FormAssociatedElement } from "./form-associated-element-o0UjvdUp.js";
5
10
  import { event } from "./event.js";
6
- const styles = "/*\n[ WJ Toggle ]\n*/\n\n:host {\n --wje-toggle-color-base: var(--wje-color-contrast-3);\n --wje-toggle-width: 30px;\n --wje-toggle-height: 18px;\n --wje-toggle-border-radius: 50px;\n --wje-toggle-handle-width: 13px;\n --wje-toggle-handle-height: 13px;\n --wje-toggle-handle-border-radius: 9px;\n --wje-toggle-handle-color: #fff;\n --wje-toggle-handle-shadow: 1px 0 1px 0.5px rgba(0, 0, 0, 0.12), 2px 4px 6px rgba(0, 0, 0, 0.2);\n --wje-toggle-handle-shadow-checked: 1px 1px 0 rgba(0, 0, 0, 0.08), -3px 3px 6px rgba(0, 0, 0, 0.3);\n --wje-toggle-duration: 250ms;\n --wje-toggle-curve: cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n:host([color='primary']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-primary-9) !important;\n}\n\n:host([color='complete']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-complete-9);\n}\n\n:host([color='success']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-success-9) !important;\n}\n\n:host([color='warning']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-warning-9);\n}\n\n:host([color='danger']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-danger-9);\n}\n\n:host([color='info']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-info-9);\n}\n\n.native-toggle {\n display: flex;\n}\n\nlabel {\n display: flex;\n cursor: pointer;\n align-items: center;\n user-select: none;\n .label-wrapper {\n width: var(--wje-toggle-width) !important;\n min-width: var(--wje-toggle-width);\n height: var(--wje-toggle-height);\n position: relative;\n display: flex;\n align-items: center;\n &:before {\n content: '';\n position: absolute;\n cursor: pointer;\n width: 100%;\n height: 100%;\n top: auto;\n left: 0;\n background: var(--wje-toggle-color-base);\n background-size: 300%;\n background-position: right;\n border-radius: var(--wje-toggle-border-radius);\n border: none;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);\n transition:\n background calc(var(--wje-toggle-duration) + (var(--wje-toggle-duration) * 0.24)),\n box-shadow var(--wje-toggle-duration);\n transition-timing-function: var(--wje-toggle-curve);\n }\n &:after {\n content: '';\n position: absolute;\n transform: translateX(0%);\n background: var(--wje-toggle-handle-color);\n width: var(--wje-toggle-handle-width);\n height: var(--wje-toggle-handle-height);\n border-radius: var(--wje-toggle-handle-border-radius);\n top: auto;\n left: 2px;\n box-shadow: var(--wje-toggle-handle-shadow);\n transition: transform, box-shadow;\n transition-duration: var(--wje-toggle-duration);\n transition-timing-function: var(--wje-toggle-curve);\n }\n }\n}\ninput[type='checkbox'][disabled] {\n & + label {\n cursor: not-allowed !important;\n color: var(--wje-color-contrast-9);\n opacity: 0.58;\n\n &:before {\n cursor: not-allowed !important;\n }\n }\n}\n\ninput[type='checkbox'] {\n position: absolute;\n z-index: -1;\n opacity: 0;\n &:checked {\n & + label {\n .label-wrapper:before {\n background-position: left;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);\n }\n .label-wrapper:after {\n transform: translateX(calc(var(--wje-toggle-width) - var(--wje-toggle-handle-width) - 4px));\n box-shadow: var(--wje-toggle-handle-shadow-checked);\n }\n }\n }\n &:focus {\n & + label {\n .label-wrapper:before {\n outline: none !important;\n box-shadow:\n inset 0 0 0 1px rgba(0, 0, 0, 0.12),\n 0 0 0 0 #78c8fe;\n }\n }\n }\n &[disabled]:active {\n & + label {\n .label-wrapper:after {\n transform: scaleX(1.1);\n transform-origin: center left;\n transition: transform step-start;\n }\n }\n }\n &:checked {\n &[disabled]:active {\n & + label {\n .label-wrapper:after {\n transform: translateX(calc(100% - 6px)) scaleX(1.1);\n transform-origin: center right;\n }\n }\n }\n }\n &:hover {\n &:active {\n & + label {\n .label-wrapper:before {\n background-color: transparent;\n }\n }\n }\n }\n}\n\n:host .text {\n margin-inline: 0.5rem 0;\n}\n\n/*Placememt*/\n:host([placement='end']) {\n label {\n width: 100%;\n }\n .text {\n margin-inline: 0 0.5rem;\n width: 100%;\n }\n}\n\nslot {\n display: flex;\n align-items: center;\n width: 100%;\n}\n";
7
- class Toggle extends WJElement {
8
- /**
9
- * Creates an instance of Toggle.
10
- */
11
+ const styles = "/*\n[ WJ Toggle ]\n*/\n\n:host {\n --wje-toggle-color-base: var(--wje-color-contrast-3);\n --wje-toggle-width: 30px;\n --wje-toggle-height: 18px;\n --wje-toggle-border-radius: 50px;\n --wje-toggle-handle-width: 13px;\n --wje-toggle-handle-height: 13px;\n --wje-toggle-handle-border-radius: 9px;\n --wje-toggle-handle-color: #fff;\n --wje-toggle-handle-shadow: 1px 0 1px 0.5px rgba(0, 0, 0, 0.12), 2px 4px 6px rgba(0, 0, 0, 0.2);\n --wje-toggle-handle-shadow-checked: 1px 1px 0 rgba(0, 0, 0, 0.08), -3px 3px 6px rgba(0, 0, 0, 0.3);\n --wje-toggle-duration: 250ms;\n --wje-toggle-curve: cubic-bezier(0.4, 0, 0.2, 1);\n}\n\n:host([color='primary']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-primary-9) !important;\n}\n\n:host([color='complete']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-complete-9);\n}\n\n:host([color='success']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-success-9) !important;\n}\n\n:host([color='warning']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-warning-9);\n}\n\n:host([color='danger']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-danger-9);\n}\n\n:host([color='info']) input:checked + label > .label-wrapper {\n --wje-toggle-color-base: var(--wje-color-info-9);\n}\n\n.native-toggle {\n\n label {\n display: flex;\n cursor: pointer;\n align-items: center;\n user-select: none;\n\n .label-wrapper {\n width: var(--wje-toggle-width) !important;\n min-width: var(--wje-toggle-width);\n height: var(--wje-toggle-height);\n position: relative;\n display: flex;\n align-items: center;\n\n &:before {\n content: '';\n position: absolute;\n cursor: pointer;\n width: 100%;\n height: 100%;\n top: auto;\n left: 0;\n background: var(--wje-toggle-color-base);\n background-size: 300%;\n background-position: right;\n border-radius: var(--wje-toggle-border-radius);\n border: none;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);\n transition: background calc(var(--wje-toggle-duration) + (var(--wje-toggle-duration) * 0.24)),\n box-shadow var(--wje-toggle-duration);\n transition-timing-function: var(--wje-toggle-curve);\n }\n\n &:after {\n content: '';\n position: absolute;\n transform: translateX(0%);\n background: var(--wje-toggle-handle-color);\n width: var(--wje-toggle-handle-width);\n height: var(--wje-toggle-handle-height);\n border-radius: var(--wje-toggle-handle-border-radius);\n top: auto;\n left: 2px;\n box-shadow: var(--wje-toggle-handle-shadow);\n transition: transform, box-shadow;\n transition-duration: var(--wje-toggle-duration);\n transition-timing-function: var(--wje-toggle-curve);\n }\n }\n }\n\n input[type='checkbox'][disabled] {\n & + label {\n cursor: not-allowed !important;\n color: var(--wje-color-contrast-9);\n opacity: 0.58;\n\n &:before {\n cursor: not-allowed !important;\n }\n }\n }\n\n input[type='checkbox'] {\n position: absolute;\n z-index: -1;\n opacity: 0;\n\n &:checked {\n & + label {\n .label-wrapper:before {\n background-position: left;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);\n }\n\n .label-wrapper:after {\n transform: translateX(calc(var(--wje-toggle-width) - var(--wje-toggle-handle-width) - 4px));\n box-shadow: var(--wje-toggle-handle-shadow-checked);\n }\n }\n }\n\n &:focus {\n & + label {\n .label-wrapper:before {\n outline: none !important;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12),\n 0 0 0 0 #78c8fe;\n }\n }\n }\n\n &[disabled]:active {\n & + label {\n .label-wrapper:after {\n transform: scaleX(1.1);\n transform-origin: center left;\n transition: transform step-start;\n }\n }\n }\n\n &:checked {\n &[disabled]:active {\n & + label {\n .label-wrapper:after {\n transform: translateX(calc(100% - 6px)) scaleX(1.1);\n transform-origin: center right;\n }\n }\n }\n }\n\n &:hover {\n &:active {\n & + label {\n .label-wrapper:before {\n background-color: transparent;\n }\n }\n }\n }\n }\n}\n\n:host .text {\n margin-inline: 0.5rem 0;\n}\n\n/*Placememt*/\n:host([placement='end']) {\n label {\n width: 100%;\n }\n .text {\n margin-inline: 0 0.5rem;\n width: 100%;\n }\n}\n\n:host([invalid]) {\n label{\n color: var(--wje-input-color-invalid);\n }\n}\n\nslot[name='error'] {\n display: none;\n}\n\n:host([invalid]) slot[name='error'] {\n display: block;\n}\n\nslot[name='error'] {\n display: none;\n max-width: 100%;\n min-width: auto;\n border-radius: 50px;\n top: 0;\n width: max-content;\n line-height: normal;\n position: static;\n background: transparent;\n padding: 0.25rem 0;\n left: auto;\n transform: none;\n color: var(--wje-input-color-invalid);\n font-size: 12px;\n}\n";
12
+ class Toggle extends FormAssociatedElement {
11
13
  constructor() {
12
14
  super();
13
- /**
14
- * Set color attribute for the toggle element.
15
- * @type {string}
16
- */
17
- __publicField(this, "className", "Toggle");
15
+ __privateAdd(this, _internalValue);
16
+ this.invalid = false;
17
+ this.pristine = true;
18
+ }
19
+ /**
20
+ * Setter for the value attribute.
21
+ * @param {string} value The value to set.
22
+ */
23
+ set value(value) {
24
+ __privateSet(this, _internalValue, value);
25
+ if (this.input) {
26
+ this.input.value = value;
27
+ }
28
+ }
29
+ /**
30
+ * Getter for the value attribute.
31
+ * @returns {string} The value of the attribute.
32
+ */
33
+ get value() {
34
+ return __privateGet(this, _internalValue) ?? this.getAttribute("value") ?? "on";
18
35
  }
19
36
  /**
20
- * Set checked attribute for the toggle element.
37
+ * Getter for the customErrorDisplay attribute.
38
+ * @returns {boolean} Whether the attribute is present.
21
39
  */
22
- set disabled(value) {
23
- if (value) this.setAttribute("disabled", "");
24
- else this.removeAttribute("disabled");
40
+ get customErrorDisplay() {
41
+ return this.hasAttribute("custom-error-display");
25
42
  }
26
43
  /**
27
- * Get checked attribute for the toggle element.
28
- * @returns {boolean} true if the toggle is disabled, false otherwise
44
+ * Getter for the validateOnChange attribute.
45
+ * @returns {boolean} Whether the attribute is present.
29
46
  */
30
- get disabled() {
31
- return this.hasAttribute("disabled");
47
+ get validateOnChange() {
48
+ return this.hasAttribute("validate-on-change");
32
49
  }
33
50
  /**
34
- * Set checked attribute for the toggle element.
51
+ * Setter for the defaultValue attribute.
52
+ * This method sets the 'value' attribute of the custom input element to the provided value.
53
+ * The 'value' attribute represents the default value of the input element.
54
+ * @param {string} value The value to set as the default value.
55
+ */
56
+ set defaultValue(value) {
57
+ this.setAttribute("value", value);
58
+ }
59
+ /**
60
+ * Getter for the defaultValue attribute.
61
+ * This method retrieves the 'value' attribute of the custom input element.
62
+ * The 'value' attribute represents the default value of the input element.
63
+ * If the 'value' attribute is not set, it returns an empty string.
64
+ * @returns {string} The default value of the input element.
65
+ */
66
+ get defaultValue() {
67
+ return this.getAttribute("value") ?? "";
68
+ }
69
+ /**
70
+ * Set checked attribute.
71
+ * @param {boolean} value true if the toggle is checked, false otherwise
35
72
  */
36
73
  set checked(value) {
37
- if (value) this.setAttribute("checked", "");
38
- else this.removeAttribute("checked");
74
+ if (value) {
75
+ this.setAttribute("checked", "");
76
+ this.internals.setFormValue(this.value);
77
+ } else {
78
+ this.removeAttribute("checked");
79
+ this.internals.setFormValue(null);
80
+ }
81
+ if (this.input) {
82
+ this.input.checked = value;
83
+ }
39
84
  }
40
85
  /**
41
- * Get checked attribute for the toggle element.
86
+ * Get checked attribute.
42
87
  * @returns {boolean} true if the toggle is checked, false otherwise
43
88
  */
44
89
  get checked() {
45
90
  return this.hasAttribute("checked");
46
91
  }
47
- /**
48
- * Get CSS stylesheet for the Button element.
49
- * @static
50
- * @returns {CSSStyleSheet} styles - The CSS stylesheet for the Button element.
51
- */
52
92
  static get cssStyleSheet() {
53
93
  return styles;
54
94
  }
55
- /**
56
- * Get observed attributes for the toggle element.
57
- * @returns {string[]}
58
- */
59
95
  static get observedAttributes() {
60
- return ["checked", "disabled"];
96
+ return ["checked", "disabled", "required"];
61
97
  }
62
- /**
63
- * Set up the attributes for the toggle element.
64
- */
65
98
  setupAttributes() {
66
99
  this.isShadowRoot = "open";
100
+ if (this.pristine) {
101
+ this.value = __privateGet(this, _internalValue);
102
+ this.pristine = false;
103
+ }
104
+ }
105
+ attributeChangedCallback(name, oldValue, newValue) {
106
+ if (!this.input) return;
107
+ if (name === "checked") {
108
+ const isChecked = this.hasAttribute("checked");
109
+ this.input.checked = isChecked;
110
+ if (isChecked) {
111
+ this.internals.setFormValue(this.value);
112
+ } else {
113
+ this.internals.setFormValue(null);
114
+ }
115
+ } else if (name === "disabled") {
116
+ this.input.disabled = this.hasAttribute("disabled");
117
+ } else if (name === "indeterminate") {
118
+ this.input.indeterminate = this.hasAttribute("indeterminate");
119
+ } else if (name === "value") {
120
+ __privateSet(this, _internalValue, newValue ?? void 0);
121
+ this.input.value = this.value;
122
+ if (this.input.checked) {
123
+ this.internals.setFormValue(this.value);
124
+ }
125
+ }
67
126
  }
68
- /**
69
- * Draw the toggle element for the component.
70
- */
71
127
  draw() {
72
- let fragment = document.createDocumentFragment();
73
- let element = document.createElement("div");
74
- element.setAttribute("part", "native");
75
- element.classList.add("native-toggle");
76
- let input = document.createElement("input");
128
+ const fragment = document.createDocumentFragment();
129
+ const native = document.createElement("div");
130
+ native.setAttribute("part", "native");
131
+ native.classList.add("native-toggle");
132
+ const input = document.createElement("input");
77
133
  input.setAttribute("part", "input");
78
- input.setAttribute("type", "checkbox");
79
- input.setAttribute("name", this.name);
80
- input.setAttribute("id", "input");
134
+ input.type = "checkbox";
135
+ input.name = this.name;
136
+ input.id = "input";
81
137
  input.checked = this.hasAttribute("checked");
82
138
  input.disabled = this.hasAttribute("disabled");
83
- let label = document.createElement("label");
139
+ if (this.hasAttribute("required")) input.required = true;
140
+ const label = document.createElement("label");
84
141
  label.setAttribute("for", "input");
85
- let labelWrapper = document.createElement("div");
86
- labelWrapper.setAttribute("part", "toggle");
87
- labelWrapper.classList.add("label-wrapper");
88
- let text = document.createElement("div");
142
+ const toggle = document.createElement("div");
143
+ toggle.setAttribute("part", "toggle");
144
+ toggle.classList.add("label-wrapper");
145
+ const text = document.createElement("div");
89
146
  text.classList.add("text");
90
147
  text.innerHTML = "<slot></slot>";
91
- if (this.color) this.classList.add("wje-color-" + this.color, "wje-color");
92
- element.appendChild(input);
93
- element.appendChild(label);
148
+ let errorSlot = document.createElement("slot");
149
+ errorSlot.setAttribute("name", "error");
150
+ let error = document.createElement("div");
151
+ error.setAttribute("slot", "error");
94
152
  if (this.placement === "end") {
95
- element.classList.add("end");
153
+ native.classList.add("end");
96
154
  label.appendChild(text);
97
- label.appendChild(labelWrapper);
155
+ label.appendChild(toggle);
98
156
  } else {
99
- label.appendChild(labelWrapper);
157
+ label.appendChild(toggle);
100
158
  label.appendChild(text);
101
159
  }
102
- fragment.appendChild(element);
160
+ native.appendChild(input);
161
+ native.appendChild(label);
162
+ native.append(errorSlot);
163
+ this.append(error);
164
+ fragment.appendChild(native);
103
165
  this.input = input;
104
166
  return fragment;
105
167
  }
106
- /**
107
- * After draw method for the toggle element to add event listeners for the input element after the element is drawn.
108
- */
109
168
  afterDraw() {
169
+ this.internals.setFormValue(this.checked ? this.value : null);
110
170
  if (!this.disabled) {
111
171
  this.input.addEventListener("input", (e) => {
172
+ this.validate();
173
+ this.pristine = false;
174
+ this.propagateValidation();
175
+ this.indeterminate = false;
112
176
  this.checked = e.target.checked;
113
177
  event.dispatchCustomEvent(this, "wje-toggle:input");
114
178
  });
115
179
  this.input.addEventListener("change", (e) => {
116
- this.checked = e.target.checked;
117
180
  event.dispatchCustomEvent(this, "wje-toggle:change");
118
181
  });
182
+ this.addEventListener("invalid", (e) => {
183
+ this.invalid = true;
184
+ this.pristine = false;
185
+ this.showInvalidMessage();
186
+ });
187
+ this.validate();
188
+ if (this.invalid) {
189
+ this.showInvalidMessage();
190
+ }
119
191
  }
120
192
  }
193
+ /**
194
+ * Removes the event listener when the checkbox is disconnected.
195
+ */
196
+ beforeDisconnect() {
197
+ event.removeElement(this.input);
198
+ }
121
199
  }
200
+ _internalValue = new WeakMap();
122
201
  Toggle.define("wje-toggle", Toggle);
123
202
  export {
124
203
  Toggle as default
@@ -1 +1 @@
1
- {"version":3,"file":"wje-toggle.js","sources":["../packages/wje-toggle/toggle.element.js","../packages/wje-toggle/toggle.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Toggle` is a custom web component that represents a toggle input.\n * @summary This element represents a toggle input.\n * @documentation https://elements.webjet.sk/components/toggle\n * @status stable\n * @augments {WJElement}\n * @csspart native - The native toggle wrapper.\n * @csspart input - The toggle input.\n * @csspart toggle - The toggle part.\n * @slot - The default slot for the toggle.\n * @cssproperty [--wje-toggle-color-base=var(--wje-color-contrast-3)] - The base background color of the toggle. Defines the default background color when the toggle is in an unselected state.\n * @cssproperty [--wje-toggle-width=30px] - The overall width of the toggle switch. Determines how wide the toggle component appears.\n * @cssproperty [--wje-toggle-height=18px] - The overall height of the toggle switch. Specifies how tall the toggle component appears.\n * @cssproperty [--wje-toggle-border-radius=50px] - The border radius of the toggle. Controls how rounded the corners of the toggle are.\n * @cssproperty [--wje-toggle-handle-width=14px] - The width of the toggle handle (knob). Determines the size of the handle for user interaction.\n * @cssproperty [--wje-toggle-handle-height=14px] - The height of the toggle handle (knob). Specifies the vertical size of the handle.\n * @cssproperty [--wje-toggle-handle-border-radius=9px] - The border radius of the toggle handle. Controls how rounded the handle is.\n * @cssproperty [--wje-toggle-handle-color=#fff] - The color of the toggle handle. Accepts any valid CSS color, such as `hex`, `rgb`, or `css variable`.\n * @cssproperty [--wje-toggle-handle-shadow=1px 0 1px 0.5px rgba(0,0,0,0.12), 2px 4px 6px rgba(0,0,0,0.2)] - The shadow applied to the toggle handle. Adds a subtle shadow effect for better visual clarity.\n * @cssproperty [--wje-toggle-handle-shadow-checked=1px 1px 0 rgba(0,0,0,0.08), -3px 3px 6px rgba(0,0,0,0.3)] - The shadow applied to the toggle handle when it is in the checked (on) state. Provides visual feedback to indicate the toggle state.\n * @cssproperty [--wje-toggle-duration=250ms] - The duration of the toggle animation in milliseconds. Controls how long the toggle animation lasts during state changes.\n * @cssproperty [--wje-toggle-curve=cubic-bezier(.4,0,.2,1)] - The easing curve used for the toggle animation. Defines the speed curve for the animation, enhancing the user experience with smooth transitions.\n * @tag wje-toggle\n */\n\nexport default class Toggle extends WJElement {\n /**\n * Creates an instance of Toggle.\n */\n constructor() {\n super();\n }\n\n /**\n * Set checked attribute for the toggle element.\n */\n set disabled(value) {\n if (value) this.setAttribute('disabled', '');\n else this.removeAttribute('disabled');\n }\n\n /**\n * Get checked attribute for the toggle element.\n * @returns {boolean} true if the toggle is disabled, false otherwise\n */\n get disabled() {\n return this.hasAttribute('disabled');\n }\n\n /**\n * Set checked attribute for the toggle element.\n */\n set checked(value) {\n if (value) this.setAttribute('checked', '');\n else this.removeAttribute('checked');\n }\n\n /**\n * Get checked attribute for the toggle element.\n * @returns {boolean} true if the toggle is checked, false otherwise\n */\n get checked() {\n return this.hasAttribute('checked');\n }\n\n /**\n * Set color attribute for the toggle element.\n * @type {string}\n */\n className = 'Toggle';\n\n /**\n * Get CSS stylesheet for the Button element.\n * @static\n * @returns {CSSStyleSheet} styles - The CSS stylesheet for the Button element.\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Get observed attributes for the toggle element.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['checked', 'disabled'];\n }\n\n /**\n * Set up the attributes for the toggle element.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draw the toggle element for the component.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let element = document.createElement('div');\n element.setAttribute('part', 'native');\n element.classList.add('native-toggle');\n\n let input = document.createElement('input');\n input.setAttribute('part', 'input');\n input.setAttribute('type', 'checkbox');\n input.setAttribute('name', this.name);\n input.setAttribute('id', 'input');\n input.checked = this.hasAttribute('checked');\n input.disabled = this.hasAttribute('disabled');\n\n let label = document.createElement('label');\n label.setAttribute('for', 'input');\n\n let labelWrapper = document.createElement('div');\n labelWrapper.setAttribute('part', 'toggle');\n labelWrapper.classList.add('label-wrapper');\n\n let text = document.createElement('div');\n text.classList.add('text');\n text.innerHTML = '<slot></slot>';\n\n if (this.color) this.classList.add('wje-color-' + this.color, 'wje-color');\n\n element.appendChild(input);\n element.appendChild(label);\n\n if (this.placement === 'end') {\n element.classList.add('end');\n label.appendChild(text);\n label.appendChild(labelWrapper);\n } else {\n label.appendChild(labelWrapper);\n label.appendChild(text);\n }\n\n fragment.appendChild(element);\n\n this.input = input;\n\n return fragment;\n }\n\n /**\n * After draw method for the toggle element to add event listeners for the input element after the element is drawn.\n */\n afterDraw() {\n if (!this.disabled) {\n this.input.addEventListener('input', (e) => {\n this.checked = e.target.checked;\n event.dispatchCustomEvent(this, 'wje-toggle:input');\n });\n\n this.input.addEventListener('change', (e) => {\n this.checked = e.target.checked;\n event.dispatchCustomEvent(this, 'wje-toggle:change');\n });\n }\n }\n}\n","import Toggle from './toggle.element.js';\n\nexport default Toggle;\n\nToggle.define('wje-toggle', Toggle);\n"],"names":[],"mappings":";;;;;;AA4Be,MAAM,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA,EAI1C,cAAc;AACV,UAAO;AAuCX;AAAA;AAAA;AAAA;AAAA,qCAAY;AAAA,EAtChB;AAAA;AAAA;AAAA;AAAA,EAKI,IAAI,SAAS,OAAO;AAChB,QAAI,MAAO,MAAK,aAAa,YAAY,EAAE;AAAA,QACtC,MAAK,gBAAgB,UAAU;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,WAAW;AACX,WAAO,KAAK,aAAa,UAAU;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKI,IAAI,QAAQ,OAAO;AACf,QAAI,MAAO,MAAK,aAAa,WAAW,EAAE;AAAA,QACrC,MAAK,gBAAgB,SAAS;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,UAAU;AACV,WAAO,KAAK,aAAa,SAAS;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaI,WAAW,gBAAgB;AACvB,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,WAAW,qBAAqB;AAC5B,WAAO,CAAC,WAAW,UAAU;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKI,kBAAkB;AACd,SAAK,eAAe;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKI,OAAO;AACH,QAAI,WAAW,SAAS,uBAAwB;AAEhD,QAAI,UAAU,SAAS,cAAc,KAAK;AAC1C,YAAQ,aAAa,QAAQ,QAAQ;AACrC,YAAQ,UAAU,IAAI,eAAe;AA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AAO,OAAO,cAAc,MAAM;"}
1
+ {"version":3,"file":"wje-toggle.js","sources":["../packages/wje-toggle/toggle.element.js","../packages/wje-toggle/toggle.js"],"sourcesContent":["import { FormAssociatedElement } from '../internals/form-associated-element.js';\nimport { event } from '../utils/event.js';\n\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Toggle` is a custom web component that represents a toggle input.\n * @summary This element represents a toggle input.\n * @documentation https://elements.webjet.sk/components/toggle\n * @status stable\n * @augments {FormAssociatedElement}\n * @csspart native - The native toggle wrapper.\n * @csspart input - The toggle input.\n * @csspart toggle - The toggle part.\n * @slot - The default slot for the toggle.\n * @cssproperty [--wje-toggle-color-base=var(--wje-color-contrast-3)] - The base background color of the toggle. Defines the default background color when the toggle is in an unselected state.\n * @cssproperty [--wje-toggle-width=30px] - The overall width of the toggle switch. Determines how wide the toggle component appears.\n * @cssproperty [--wje-toggle-height=18px] - The overall height of the toggle switch. Specifies how tall the toggle component appears.\n * @cssproperty [--wje-toggle-border-radius=50px] - The border radius of the toggle. Controls how rounded the corners of the toggle are.\n * @cssproperty [--wje-toggle-handle-width=14px] - The width of the toggle handle (knob). Determines the size of the handle for user interaction.\n * @cssproperty [--wje-toggle-handle-height=14px] - The height of the toggle handle (knob). Specifies the vertical size of the handle.\n * @cssproperty [--wje-toggle-handle-border-radius=9px] - The border radius of the toggle handle. Controls how rounded the handle is.\n * @cssproperty [--wje-toggle-handle-color=#fff] - The color of the toggle handle. Accepts any valid CSS color, such as `hex`, `rgb`, or `css variable`.\n * @cssproperty [--wje-toggle-handle-shadow=1px 0 1px 0.5px rgba(0,0,0,0.12), 2px 4px 6px rgba(0,0,0,0.2)] - The shadow applied to the toggle handle. Adds a subtle shadow effect for better visual clarity.\n * @cssproperty [--wje-toggle-handle-shadow-checked=1px 1px 0 rgba(0,0,0,0.08), -3px 3px 6px rgba(0,0,0,0.3)] - The shadow applied to the toggle handle when it is in the checked (on) state. Provides visual feedback to indicate the toggle state.\n * @cssproperty [--wje-toggle-duration=250ms] - The duration of the toggle animation in milliseconds. Controls how long the toggle animation lasts during state changes.\n * @cssproperty [--wje-toggle-curve=cubic-bezier(.4,0,.2,1)] - The easing curve used for the toggle animation. Defines the speed curve for the animation, enhancing the user experience with smooth transitions.\n * @tag wje-toggle\n */\n\nexport default class Toggle extends FormAssociatedElement {\n #internalValue;\n\n constructor() {\n super();\n\n this.invalid = false;\n this.pristine = true;\n }\n\n /**\n * Setter for the value attribute.\n * @param {string} value The value to set.\n */\n set value(value) {\n this.#internalValue = value;\n if (this.input) {\n this.input.value = value;\n }\n }\n\n /**\n * Getter for the value attribute.\n * @returns {string} The value of the attribute.\n */\n get value() {\n return this.#internalValue ?? this.getAttribute('value') ?? 'on';\n }\n\n /**\n * Getter for the customErrorDisplay attribute.\n * @returns {boolean} Whether the attribute is present.\n */\n get customErrorDisplay() {\n return this.hasAttribute('custom-error-display');\n }\n\n /**\n * Getter for the validateOnChange attribute.\n * @returns {boolean} Whether the attribute is present.\n */\n get validateOnChange() {\n return this.hasAttribute('validate-on-change');\n }\n\n /**\n * Setter for the defaultValue attribute.\n * This method sets the 'value' attribute of the custom input element to the provided value.\n * The 'value' attribute represents the default value of the input element.\n * @param {string} value The value to set as the default value.\n */\n set defaultValue(value) {\n this.setAttribute('value', value);\n }\n\n /**\n * Getter for the defaultValue attribute.\n * This method retrieves the 'value' attribute of the custom input element.\n * The 'value' attribute represents the default value of the input element.\n * If the 'value' attribute is not set, it returns an empty string.\n * @returns {string} The default value of the input element.\n */\n get defaultValue() {\n return this.getAttribute('value') ?? '';\n }\n\n /**\n * Set checked attribute.\n * @param {boolean} value true if the toggle is checked, false otherwise\n */\n set checked(value) {\n if (value) {\n this.setAttribute('checked', '');\n this.internals.setFormValue(this.value); // len ak je checked\n } else {\n this.removeAttribute('checked');\n this.internals.setFormValue(null); // ak nie je checked, nič sa neposiela\n }\n if (this.input) {\n this.input.checked = value;\n }\n }\n\n /**\n * Get checked attribute.\n * @returns {boolean} true if the toggle is checked, false otherwise\n */\n get checked() {\n return this.hasAttribute('checked');\n }\n\n static get cssStyleSheet() {\n return styles;\n }\n\n static get observedAttributes() {\n return ['checked', 'disabled', 'required'];\n }\n\n setupAttributes() {\n this.isShadowRoot = 'open';\n // if some value was set via value setter then dont use default value\n if (this.pristine) {\n this.value = this.#internalValue;\n this.pristine = false;\n }\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n if (!this.input) return;\n if (name === 'checked') {\n const isChecked = this.hasAttribute('checked');\n this.input.checked = isChecked;\n // Reflect into form value\n if (isChecked) {\n this.internals.setFormValue(this.value);\n } else {\n this.internals.setFormValue(null);\n }\n } else if (name === 'disabled') {\n this.input.disabled = this.hasAttribute('disabled');\n } else if (name === 'indeterminate') {\n this.input.indeterminate = this.hasAttribute('indeterminate');\n } else if (name === 'value') {\n // keep payload in sync; do not toggle checked here\n this.#internalValue = newValue ?? undefined;\n this.input.value = this.value;\n // If currently checked, update the submitted payload\n if (this.input.checked) {\n this.internals.setFormValue(this.value);\n }\n }\n }\n\n draw() {\n const fragment = document.createDocumentFragment();\n\n const native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-toggle');\n\n const input = document.createElement('input');\n input.setAttribute('part', 'input');\n input.type = 'checkbox';\n input.name = this.name;\n input.id = 'input';\n input.checked = this.hasAttribute('checked');\n input.disabled = this.hasAttribute('disabled');\n if (this.hasAttribute('required')) input.required = true;\n\n const label = document.createElement('label');\n label.setAttribute('for', 'input');\n\n const toggle = document.createElement('div');\n toggle.setAttribute('part', 'toggle');\n toggle.classList.add('label-wrapper');\n\n const text = document.createElement('div');\n text.classList.add('text');\n text.innerHTML = '<slot></slot>';\n\n // Error\n let errorSlot = document.createElement('slot');\n errorSlot.setAttribute('name', 'error');\n\n let error = document.createElement('div');\n error.setAttribute('slot', 'error');\n\n // APPEND\n if (this.placement === 'end') {\n native.classList.add('end');\n label.appendChild(text);\n label.appendChild(toggle);\n } else {\n label.appendChild(toggle);\n label.appendChild(text);\n }\n\n native.appendChild(input);\n native.appendChild(label);\n native.append(errorSlot);\n\n this.append(error);\n\n fragment.appendChild(native);\n\n this.input = input;\n\n return fragment;\n }\n\n afterDraw() {\n this.internals.setFormValue(this.checked ? this.value : null); // Set initial form value based on checked state\n\n if (!this.disabled) {\n this.input.addEventListener('input', (e) => {\n this.validate();\n\n this.pristine = false;\n this.propagateValidation();\n\n this.indeterminate = false;\n this.checked = e.target.checked;\n\n event.dispatchCustomEvent(this, 'wje-toggle:input');\n });\n\n this.input.addEventListener('change', (e) => {\n event.dispatchCustomEvent(this, 'wje-toggle:change');\n });\n\n this.addEventListener('invalid', (e) => {\n this.invalid = true;\n this.pristine = false;\n\n this.showInvalidMessage();\n });\n\n this.validate();\n\n if (this.invalid) {\n this.showInvalidMessage();\n }\n }\n }\n\n /**\n * Removes the event listener when the checkbox is disconnected.\n */\n beforeDisconnect() {\n event.removeElement(this.input);\n }\n}\n","import Toggle from './toggle.element.js';\n\nexport default Toggle;\n\nToggle.define('wje-toggle', Toggle);\n"],"names":[],"mappings":";;;;;;;;;;;AA8Be,MAAM,eAAe,sBAAsB;AAAA,EAGtD,cAAc;AACV,UAAO;AAHX;AAKI,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,MAAM,OAAO;AACb,uBAAK,gBAAiB;AACtB,QAAI,KAAK,OAAO;AACZ,WAAK,MAAM,QAAQ;AAAA,IAC/B;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,QAAQ;AACR,WAAO,mBAAK,mBAAkB,KAAK,aAAa,OAAO,KAAK;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,qBAAqB;AACrB,WAAO,KAAK,aAAa,sBAAsB;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,mBAAmB;AACnB,WAAO,KAAK,aAAa,oBAAoB;AAAA,EACrD;AAAA;AAAA;AAAA;A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AK;AACxB,WAAO,YAAY,KAAK;AACxB,WAAO,OAAO,SAAS;AAEvB,SAAK,OAAO,KAAK;AAEjB,aAAS,YAAY,MAAM;AAE3B,SAAK,QAAQ;AAEb,WAAO;AAAA,EACf;AAAA,EAEI,YAAY;AACR,SAAK,UAAU,aAAa,KAAK,UAAU,KAAK,QAAQ,IAAI;AAE5D,QAAI,CAAC,KAAK,UAAU;AAChB,WAAK,MAAM,iBAAiB,SAAS,CAAC,MAAM;AACxC,aAAK,SAAU;AAEf,aAAK,WAAW;AAChB,aAAK,oBAAqB;AAE1B,aAAK,gBAAgB;AACrB,aAAK,UAAU,EAAE,OAAO;AAExB,cAAM,oBAAoB,MAAM,kBAAkB;AAAA,MAClE,CAAa;AAED,WAAK,MAAM,iBAAiB,UAAU,CAAC,MAAM;AACzC,cAAM,oBAAoB,MAAM,mBAAmB;AAAA,MACnE,CAAa;AAED,WAAK,iBAAiB,WAAW,CAAC,MAAM;AACpC,aAAK,UAAU;AACf,aAAK,WAAW;AAEhB,aAAK,mBAAoB;AAAA,MACzC,CAAa;AAED,WAAK,SAAU;AAEf,UAAI,KAAK,SAAS;AACd,aAAK,mBAAoB;AAAA,MACzC;AAAA,IACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKI,mBAAmB;AACf,UAAM,cAAc,KAAK,KAAK;AAAA,EACtC;AACA;AAvOI;AC3BJ,OAAO,OAAO,cAAc,MAAM;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wj-elements",
3
3
  "description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
4
- "version": "0.1.229",
4
+ "version": "0.1.231",
5
5
  "homepage": "https://github.com/lencys/wj-elements",
6
6
  "author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
7
7
  "license": "MIT",