wj-elements 0.1.182 → 0.1.183

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/light.css CHANGED
@@ -551,7 +551,7 @@
551
551
  --wje-textarea-font-family: var(--wje-font-family);
552
552
  --wje-textarea-background-color: var(--wje-background);
553
553
  --wje-textarea-color: var(--wje-color);
554
- --wje-textarea-color-invalid: var(--wje-color-danger);
554
+ --wje-textarea-color-invalid: var(--wje-color-danger-9);
555
555
  --wje-textarea-border-width: 1px;
556
556
  --wje-textarea-border-style: solid;
557
557
  --wje-textarea-border-color: var(--wje-border-color);
@@ -42,13 +42,14 @@ export default class Input extends WJElement {
42
42
  */
43
43
  static formAssociated: boolean;
44
44
  /**
45
- * Setter for the invalid attribute.
46
- * @param {boolean} isInvalid Whether the input is invalid.
45
+ * Sets or removes the 'invalid' attribute on an element based on the provided value.
46
+ * @param {boolean} value If true, the 'invalid' attribute is set. If false, the 'invalid' attribute is removed.
47
47
  */
48
- set invalid(isInvalid: boolean);
48
+ set invalid(value: boolean);
49
49
  /**
50
- * Getter for the invalid attribute.
51
- * @returns {boolean} Whether the attribute is present.
50
+ * Gets the value of the 'invalid' attribute.
51
+ * Determines whether the 'invalid' attribute is present on the element.
52
+ * @returns {boolean} True if the 'invalid' attribute is present, otherwise false.
52
53
  */
53
54
  get invalid(): boolean;
54
55
  pristine: boolean;
@@ -61,16 +62,42 @@ export default class Input extends WJElement {
61
62
  */
62
63
  set value(value: string);
63
64
  /**
64
- * Getter for the value attribute.
65
- * @returns {string} The value of the attribute.
65
+ * Retrieves the value from the input element if available; otherwise,
66
+ * returns the internal _value property or an empty string as the default.
67
+ * @returns {string} The current value from the input element, the internal _value, or an empty string.
66
68
  */
67
69
  get value(): string;
68
70
  _value: string;
71
+ /**
72
+ * Sets the label attribute of the element.
73
+ * @param {string} value The value to set as the label attribute.
74
+ */
75
+ set label(value: string);
76
+ /**
77
+ * Retrieves the value of the 'label' attribute if it exists.
78
+ * If the 'label' attribute is not set, it returns false.
79
+ * @returns {string|boolean} The value of the 'label' attribute as a string, or false if the attribute is not set.
80
+ */
81
+ get label(): string | boolean;
82
+ /**
83
+ * Sets the custom error display attribute for an element.
84
+ * @param {boolean} value If true, adds the 'custom-error-display' attribute to the element. If false, removes the attribute from the element.
85
+ */
86
+ set customErrorDisplay(value: boolean);
69
87
  /**
70
88
  * Getter for the customErrorDisplay attribute.
71
89
  * @returns {boolean} Whether the attribute is present.
72
90
  */
73
91
  get customErrorDisplay(): boolean;
92
+ /**
93
+ * Sets the `validateOnChange` property. If set to a truthy value, it adds the
94
+ * `validate-on-change` attribute to the element. If set to a falsy value, it
95
+ * removes the `validate-on-change` attribute from the element.
96
+ * @param {boolean} value Determines whether to add or remove the
97
+ * `validate-on-change` attribute. A truthy value adds the attribute, whereas a
98
+ * falsy value removes it.
99
+ */
100
+ set validateOnChange(value: boolean);
74
101
  /**
75
102
  * Getter for the validateOnChange attribute.
76
103
  * @returns {boolean} Whether the attribute is present.
@@ -116,11 +143,41 @@ export default class Input extends WJElement {
116
143
  * @returns {string} The default value of the input element.
117
144
  */
118
145
  get defaultValue(): string;
146
+ /**
147
+ * Sets or removes the 'clearable' attribute on the element.
148
+ * When set to a truthy value, the 'clearable' attribute is added; when falsy, the attribute is removed.
149
+ * @param {boolean} value Determines whether to set or remove the 'clearable' attribute. If true, the 'clearable' attribute is added. If false, it is removed.
150
+ */
119
151
  set clearable(value: boolean);
152
+ /**
153
+ * Checks if the 'clearable' attribute is present on the element.
154
+ * @returns {boolean} True if the 'clearable' attribute is set, otherwise false.
155
+ */
120
156
  get clearable(): boolean;
157
+ /**
158
+ * Sets the placeholder value for an element. If the provided value is non-empty,
159
+ * it assigns the value to the "placeholder" attribute. Otherwise, it removes
160
+ * the "placeholder" attribute from the element.
161
+ * @param {string} value The placeholder text to set or null/undefined to remove the attribute.
162
+ */
121
163
  set placeholder(value: string);
164
+ /**
165
+ * Retrieves the value of the 'placeholder' attribute from the element.
166
+ * If the attribute is not set, it returns an empty string.
167
+ * @returns {string} The value of the 'placeholder' attribute or an empty string if not set.
168
+ */
122
169
  get placeholder(): string;
170
+ /**
171
+ * Sets the `variant` attribute on the element. If a value is provided, it will set the attribute to the given value.
172
+ * If no value is provided, it removes the `variant` attribute from the element.
173
+ * @param {string} value The value to set for the `variant` attribute. If falsy, the attribute is removed.
174
+ */
123
175
  set variant(value: string);
176
+ /**
177
+ * Retrieves the value of the 'variant' attribute from the element.
178
+ * If the attribute is not set, it defaults to 'default'.
179
+ * @returns {string} The value of the 'variant' attribute or 'default' if not set.
180
+ */
124
181
  get variant(): string;
125
182
  beforeDraw(): void;
126
183
  /**
@@ -155,9 +212,9 @@ export default class Input extends WJElement {
155
212
  validateInput(): void;
156
213
  validationError: string;
157
214
  /**
158
- * @summary Propagates the validation state of the input.
159
- * This method sets the 'invalid' property of the input based on its 'pristine' state and its internal validity state.
160
- * If the input is invalid and the 'customErrorDisplay' property is true, it dispatches an 'invalid' event.
215
+ * Checks and updates the validation state of the component based on its current properties.
216
+ * If the component is invalid and a custom error display is enabled, it dispatches an 'invalid' event.
217
+ * @returns {void} This method does not return a value.
161
218
  */
162
219
  propagateValidation(): void;
163
220
  /**
@@ -170,6 +170,8 @@ export default class Select extends WJElement {
170
170
  * @returns {object} The value of the attribute.
171
171
  */
172
172
  get value(): object;
173
+ set required(value: boolean);
174
+ get required(): boolean;
173
175
  /**
174
176
  * Getter for the customErrorDisplay attribute.
175
177
  * @returns {boolean} Whether the attribute is present.
@@ -181,13 +183,16 @@ export default class Select extends WJElement {
181
183
  */
182
184
  get validateOnChange(): boolean;
183
185
  /**
184
- * Setter for the invalid attribute.
185
- * @param {boolean} isInvalid Whether the input is invalid.
186
+ * Sets the 'invalid' property of the element.
187
+ * When set to a truthy value, the 'invalid' attribute is added to the element.
188
+ * When set to a falsy value, the 'invalid' attribute is removed from the element.
189
+ * @param {boolean} value A boolean indicating whether the element is invalid.
186
190
  */
187
- set invalid(isInvalid: boolean);
191
+ set invalid(value: boolean);
188
192
  /**
189
- * Getter for the invalid attribute.
190
- * @returns {boolean} Whether the attribute is present.
193
+ * Retrieves the value of the 'invalid' attribute.
194
+ * This method checks if the 'invalid' attribute is present on the element.
195
+ * @returns {boolean} Returns true if the 'invalid' attribute is present, otherwise false.
191
196
  */
192
197
  get invalid(): boolean;
193
198
  /**
@@ -263,9 +268,9 @@ export default class Select extends WJElement {
263
268
  * The options are determined by combining elements from various sources, including loaded options, added options, and HTML-sourced options.
264
269
  * If a `wje-options` element is present within the component, its loaded options are included in the merged list.
265
270
  * In the absence of a `wje-options` element, duplicates among the added and HTML options are removed, retaining their order.
266
- * @returns {Array<Object>} An array containing all the available options, combining the loaded, added, and HTML-based options, with duplicates removed where applicable.
271
+ * @returns {Array<object>} An array containing all the available options, combining the loaded, added, and HTML-based options, with duplicates removed where applicable.
267
272
  */
268
- get options(): Array<any>;
273
+ get options(): Array<object>;
269
274
  /**
270
275
  * Sets the trigger value.
271
276
  * @param {string} value The trigger value to set.
@@ -291,6 +296,7 @@ export default class Select extends WJElement {
291
296
  * @returns {void} Does not return a value. The method operates by updating the state and behavior of the component.
292
297
  */
293
298
  afterDraw(): void;
299
+ pristine: boolean;
294
300
  /**
295
301
  * Handles the option change event.
296
302
  * @param {Event} e The event.
@@ -413,9 +419,31 @@ export default class Select extends WJElement {
413
419
  */
414
420
  htmlSelectedItem(item: any): any;
415
421
  /**
416
- * @summary Callback function that is called when the custom element is associated with a form.
417
- * This function adds an event listener to the form's submit event, which validates the input and propagates the validation.
418
- * @param {HTMLFormElement} form The form the custom element is associated with.
422
+ * Clones and appends an icon from a template with slot "check" to the given option element.
423
+ * @param {HTMLElement} option The target option element where the "check" icon will be added.
424
+ * @returns {void}
425
+ */
426
+ optionCheckSlot(option: HTMLElement): void;
427
+ /**
428
+ * Validates the selection of options in the select element.
429
+ * Checks if the element is required and no option is selected,
430
+ * in which case it sets a validation error with a custom message.
431
+ * If the element passes validation, it clears any existing validation errors.
432
+ *
433
+ * @return {void} Does not return a value.
434
+ */
435
+ validateSelect(): void;
436
+ /**
437
+ * Checks and updates the validation state of the component based on its current properties.
438
+ * If the component is invalid and a custom error display is enabled, it dispatches an 'invalid' event.
439
+ * @returns {void} This method does not return a value.
440
+ */
441
+ propagateValidation(): void;
442
+ showInvalidMessage(): void;
443
+ /**
444
+ * Lifecycle callback invoked when the custom element becomes associated with a form element.
445
+ * @param {HTMLFormElement} form The form element the custom element is associated with.
446
+ * @returns {void}
419
447
  */
420
448
  formAssociatedCallback(form: HTMLFormElement): void;
421
449
  /**
@@ -454,11 +482,5 @@ export default class Select extends WJElement {
454
482
  * @returns {boolean} Returns true if all elements in the `elements` array are found within the `options` array, otherwise returns false.
455
483
  */
456
484
  areAllElementsInOptions(elements: any[], options: any[]): boolean;
457
- /**
458
- * Clones and appends an icon from a template with slot "check" to the given option element.
459
- * @param {HTMLElement} option The target option element where the "check" icon will be added.
460
- * @returns {void}
461
- */
462
- optionCheckSlot(option: HTMLElement): void;
463
485
  #private;
464
486
  }
@@ -65,6 +65,20 @@ export default class Textarea extends WJElement {
65
65
  */
66
66
  get value(): string;
67
67
  _value: string;
68
+ /**
69
+ * Sets the `validateOnChange` property. If set to a truthy value, it adds the
70
+ * `validate-on-change` attribute to the element. If set to a falsy value, it
71
+ * removes the `validate-on-change` attribute from the element.
72
+ * @param {boolean} value Determines whether to add or remove the
73
+ * `validate-on-change` attribute. A truthy value adds the attribute, whereas a
74
+ * falsy value removes it.
75
+ */
76
+ set validateOnChange(value: boolean);
77
+ /**
78
+ * Getter for the validateOnChange attribute.
79
+ * @returns {boolean} Whether the attribute is present.
80
+ */
81
+ get validateOnChange(): boolean;
68
82
  /**
69
83
  * Getter for the form attribute.
70
84
  * @returns {HTMLFormElement} The form the input is associated with.
@@ -121,6 +135,12 @@ export default class Textarea extends WJElement {
121
135
  * @param {Event} e The event object.
122
136
  */
123
137
  counterFn: (e: Event) => void;
138
+ /**
139
+ * @summary Displays the validation message for the input.
140
+ * If the input has a slot named 'error', it sets the text content of the element with attribute 'error-message' inside the slot to the validation message.
141
+ * If the input does not have an 'error' slot, it sets the text content of the errorMessage property to the validation message.
142
+ */
143
+ showInvalidMessage(): void;
124
144
  /**
125
145
  * @summary Validates the input.
126
146
  * This method checks the validity state of the input. If the input is not valid, it iterates over the validity state object.
package/dist/wje-input.js CHANGED
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import WJElement from "./wje-element.js";
5
5
  import { event } from "./event.js";
6
- const styles = "/*\n[ WJ Input ]\n*/\n\n:host {\n width: 100%;\n margin-bottom: var(--wje-input-margin-bottom);\n display: block;\n label {\n margin: var(--wje-input-label-margin);\n padding: var(--wje-input-label-padding);\n display: var(--wje-input-label-display);\n opacity: 1;\n cursor: text;\n transition: opacity 0.2s ease;\n line-height: var(--wje-input-label-line-height);\n font-size: var(--wje-input-label-font-size);\n }\n .wrapper {\n display: grid;\n grid-template-columns: auto 1fr auto;\n width: 100%;\n > .input-wrapper {\n grid-column: 2;\n }\n }\n .native-input {\n .input-wrapper {\n display: block;\n width: 100%;\n position: relative;\n box-sizing: border-box;\n\n label {\n width: 100%;\n }\n }\n &.default {\n background-color: var(--wje-input-background-color);\n font-family: var(--wje-input-font-family);\n position: relative;\n border-radius: var(--wje-input-border-radius);\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n padding-inline: 0;\n padding-top: 0.25rem;\n padding-bottom: 0.25rem;\n transition: background-color 0.2s ease;\n cursor: text;\n .input-wrapper {\n padding-inline: 0.5rem;\n }\n &.focused {\n border-color: var(--wje-input-border-color-focus) !important;\n label {\n opacity: 0.67;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n input {\n border: none;\n height: 25px;\n min-height: 25px;\n padding: 0;\n margin-top: -4px;\n background: none;\n box-shadow: none;\n width: 100%;\n }\n label {\n &.fade {\n opacity: 0.5;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n ::slotted([slot='start']) {\n border-left: none;\n border-top: none;\n border-bottom: none;\n }\n\n ::slotted([slot='end']) {\n border-right: none;\n border-top: none;\n border-bottom: none;\n }\n }\n &.standard {\n font-family: var(--wje-input-font-family);\n position: relative;\n border-radius: var(--wje-input-border-radius);\n padding-inline: 0;\n padding-top: 0;\n padding-bottom: 0;\n transition: background-color 0.2s ease;\n cursor: text;\n &.focused {\n input {\n border-color: var(--wje-input-border-color-focus) !important;\n }\n }\n input {\n background-color: var(--wje-input-background-color);\n display: block;\n min-height: 32px;\n padding-inline: 0.5rem;\n padding-top: 0;\n padding-bottom: 0;\n /*background: none;*/\n box-shadow: none;\n width: 100%;\n box-sizing: border-box;\n border-radius: var(--wje-input-border-radius);\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n }\n .input-wrapper {\n flex-wrap: nowrap;\n &:hover .clear {\n visibility: visible;\n }\n }\n ::slotted([slot='start']) {\n border-right: none;\n border-radius: var(--wje-input-border-radius) 0 0 var(--wje-input-border-radius);\n }\n\n ::slotted([slot='end']) {\n border-left: none;\n border-radius: 0 var(--wje-input-border-radius) var(--wje-input-border-radius) 0;\n }\n\n &.has-start input {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n }\n\n &.has-end input {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n }\n .error-message {\n position: static;\n\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 line-height: normal;\n }\n }\n }\n}\n\n.clear {\n visibility: hidden;\n position: absolute;\n right: 0;\n top: 3px;\n --wje-padding-top: 0.25rem;\n --wje-padding-start: 0.25rem;\n --wje-padding-end: 0.25rem;\n --wje-padding-bottom: 0.25rem;\n --wje-button-margin-inline: 0 0.25rem;\n}\n\n:host([required]) .input-wrapper::after {\n color: var(--wje-input-color-invalid);\n content: var(--wje-input-required-symbol);\n font-family: var(--wje-force-mac-font-family);\n font-size: 24px;\n position: absolute;\n right: 12px;\n top: 0;\n}\n\n:host([required]) .standard .input-wrapper::after {\n right: 13px;\n top: -20px;\n}\n\n:host([invalid]) {\n .error-message {\n display: block;\n }\n .default {\n label {\n opacity: 1 !important;\n color: var(--wje-input-color-invalid) !important;\n animation-name: shake;\n animation-duration: 0.4s;\n animation-iteration-count: 1;\n }\n }\n}\n\n::slotted([slot='start']),\n::slotted([slot='end']) {\n display: flex;\n align-items: center;\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n padding-inline: var(--wje-input-slot-padding-inline);\n}\n\n:host(.options-show) ::slotted([slot='start']) {\n border-bottom-left-radius: 0 !important;\n}\n\n:host(.options-show) ::slotted([slot='end']) {\n border-bottom-right-radius: 0 !important;\n}\n\nslot[name='start'],\nslot[name='end'] {\n display: flex;\n}\n\nslot[name='error'] {\n display: none;\n margin-inline: 0.5rem;\n}\n\n:host([disabled]) input {\n opacity: 0.5;\n}\n\n:host([invalid]) slot[name='error'] {\n display: block;\n}\n\ninput {\n background-color: var(--wje-input-background-color);\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n font-family: var(--wje-input-font-family);\n color: var(--wje-input-color);\n appearance: none;\n outline: 0;\n padding: 0.25rem 0.5rem;\n line-height: var(--wje-input-line-height);\n font-size: 14px;\n font-weight: normal;\n vertical-align: middle;\n min-height: 32px;\n}\n\n.error-message {\n display: none;\n position: absolute;\n max-width: 100%;\n min-width: auto;\n border-radius: 50px;\n background: black;\n padding: 0.25rem 0.5rem;\n top: 0;\n left: 50%;\n transform: translate(-50%, -75%);\n color: white;\n font-size: 12px;\n width: max-content;\n line-height: normal;\n}\n\n@keyframes shake {\n 8%,\n 41% {\n transform: translateX(-4px);\n }\n 25%,\n 58% {\n transform: translateX(4px);\n }\n 75% {\n transform: translateX(-2px);\n }\n 92% {\n transform: translateX(2px);\n }\n 0%,\n 100% {\n transform: translateX(0);\n }\n}\n";
6
+ const styles = "/*\n[ WJ Input ]\n*/\n\n:host {\n width: 100%;\n margin-bottom: var(--wje-input-margin-bottom);\n display: block;\n label {\n margin: var(--wje-input-label-margin);\n padding: var(--wje-input-label-padding);\n display: var(--wje-input-label-display);\n opacity: 1;\n cursor: text;\n transition: opacity 0.2s ease;\n line-height: var(--wje-input-label-line-height);\n font-size: var(--wje-input-label-font-size);\n }\n .wrapper {\n display: grid;\n grid-template-columns: auto 1fr auto;\n width: 100%;\n > .input-wrapper {\n grid-column: 2;\n }\n }\n .native-input {\n .input-wrapper {\n display: block;\n width: 100%;\n position: relative;\n box-sizing: border-box;\n\n label {\n width: 100%;\n }\n }\n &.default {\n background-color: var(--wje-input-background-color);\n font-family: var(--wje-input-font-family);\n position: relative;\n border-radius: var(--wje-input-border-radius);\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n padding-inline: 0;\n padding-top: 0.25rem;\n padding-bottom: 0.25rem;\n transition: background-color 0.2s ease;\n cursor: text;\n .input-wrapper {\n padding-inline: 0.5rem;\n }\n &.focused {\n border-color: var(--wje-input-border-color-focus) !important;\n label {\n opacity: 0.67;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n input {\n border: none;\n height: 25px;\n min-height: 25px;\n padding: 0;\n margin-top: -4px;\n background: none;\n box-shadow: none;\n width: 100%;\n }\n label {\n &.fade {\n opacity: 0.5;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n ::slotted([slot='start']) {\n border-left: none;\n border-top: none;\n border-bottom: none;\n }\n\n ::slotted([slot='end']) {\n border-right: none;\n border-top: none;\n border-bottom: none;\n }\n }\n &.standard {\n font-family: var(--wje-input-font-family);\n position: relative;\n border-radius: var(--wje-input-border-radius);\n padding-inline: 0;\n padding-top: 0;\n padding-bottom: 0;\n transition: background-color 0.2s ease;\n cursor: text;\n &.focused {\n input {\n border-color: var(--wje-input-border-color-focus) !important;\n }\n }\n input {\n background-color: var(--wje-input-background-color);\n display: block;\n min-height: 32px;\n padding-inline: 0.5rem;\n padding-top: 0;\n padding-bottom: 0;\n /*background: none;*/\n box-shadow: none;\n width: 100%;\n box-sizing: border-box;\n border-radius: var(--wje-input-border-radius);\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n }\n .input-wrapper {\n flex-wrap: nowrap;\n &:hover .clear {\n visibility: visible;\n }\n }\n ::slotted([slot='start']) {\n border-right: none;\n border-radius: var(--wje-input-border-radius) 0 0 var(--wje-input-border-radius);\n }\n\n ::slotted([slot='end']) {\n border-left: none;\n border-radius: 0 var(--wje-input-border-radius) var(--wje-input-border-radius) 0;\n }\n\n &.has-start input {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n }\n\n &.has-end input {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n }\n slot[name='error'] {\n position: static;\n\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 line-height: normal;\n }\n }\n }\n}\n\n:host([type=hidden]) {\n margin: 0;\n .native-input {\n padding: 0;\n border-width: 0;\n }\n}\n\n.clear {\n visibility: hidden;\n position: absolute;\n right: 0;\n top: 3px;\n --wje-padding-top: 0.25rem;\n --wje-padding-start: 0.25rem;\n --wje-padding-end: 0.25rem;\n --wje-padding-bottom: 0.25rem;\n --wje-button-margin-inline: 0 0.25rem;\n}\n\n:host([required]) .wrapper::after {\n color: var(--wje-input-color-invalid);\n content: var(--wje-input-required-symbol);\n font-size: 24px;\n position: absolute;\n right: 12px;\n top: 0;\n}\n\n:host([required]) .standard .input-wrapper::after {\n right: 13px;\n top: -20px;\n}\n\n:host([invalid]) {\n .default {\n label {\n opacity: 1 !important;\n color: var(--wje-input-color-invalid) !important;\n animation-name: shake;\n animation-duration: 0.4s;\n animation-iteration-count: 1;\n }\n }\n}\n\n::slotted([slot='start']),\n::slotted([slot='end']) {\n display: flex;\n align-items: center;\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n padding-inline: var(--wje-input-slot-padding-inline);\n}\n\n:host(.options-show) ::slotted([slot='start']) {\n border-bottom-left-radius: 0 !important;\n}\n\n:host(.options-show) ::slotted([slot='end']) {\n border-bottom-right-radius: 0 !important;\n}\n\nslot[name='start'],\nslot[name='end'] {\n display: flex;\n}\n\nslot[name='error'] {\n display: none;\n}\n\n:host([invalid]) slot[name='error'] {\n display: block;\n}\n\n:host([disabled]) input {\n opacity: 0.5;\n}\n\ninput {\n background-color: var(--wje-input-background-color);\n border-width: var(--wje-input-border-width);\n border-style: var(--wje-input-border-style);\n border-color: var(--wje-input-border-color);\n color: var(--wje-input-color);\n appearance: none;\n outline: 0;\n padding: 0.25rem 0.5rem;\n line-height: var(--wje-input-line-height);\n font-size: 14px;\n font-weight: normal;\n vertical-align: middle;\n min-height: 32px;\n}\n\nslot[name='error'] {\n display: none;\n position: absolute;\n max-width: 100%;\n min-width: auto;\n border-radius: 50px;\n background: black;\n padding: 0.25rem 0.5rem;\n top: 0;\n left: 50%;\n transform: translate(-50%, -50%);\n color: white;\n font-size: var(--wje-font-size-small);\n width: max-content;\n line-height: normal;\n}\n\n@keyframes shake {\n 8%,\n 41% {\n transform: translateX(-4px);\n }\n 25%,\n 58% {\n transform: translateX(4px);\n }\n 75% {\n transform: translateX(-2px);\n }\n 92% {\n transform: translateX(2px);\n }\n 0%,\n 100% {\n transform: translateX(0);\n }\n}\n";
7
7
  class Input extends WJElement {
8
8
  /**
9
9
  * Creates an instance of Input.
@@ -41,13 +41,40 @@ class Input extends WJElement {
41
41
  this._value = value;
42
42
  }
43
43
  /**
44
- * Getter for the value attribute.
45
- * @returns {string} The value of the attribute.
44
+ * Retrieves the value from the input element if available; otherwise,
45
+ * returns the internal _value property or an empty string as the default.
46
+ * @returns {string} The current value from the input element, the internal _value, or an empty string.
46
47
  */
47
48
  get value() {
48
49
  var _a;
49
50
  return ((_a = this.input) == null ? void 0 : _a.value) ?? this._value ?? "";
50
51
  }
52
+ /**
53
+ * Sets the label attribute of the element.
54
+ * @param {string} value The value to set as the label attribute.
55
+ */
56
+ set label(value) {
57
+ this.setAttribute("label", value);
58
+ }
59
+ /**
60
+ * Retrieves the value of the 'label' attribute if it exists.
61
+ * If the 'label' attribute is not set, it returns false.
62
+ * @returns {string|boolean} The value of the 'label' attribute as a string, or false if the attribute is not set.
63
+ */
64
+ get label() {
65
+ return this.getAttribute("label") || false;
66
+ }
67
+ /**
68
+ * Sets the custom error display attribute for an element.
69
+ * @param {boolean} value If true, adds the 'custom-error-display' attribute to the element. If false, removes the attribute from the element.
70
+ */
71
+ set customErrorDisplay(value) {
72
+ if (value) {
73
+ this.setAttribute("custom-error-display", "");
74
+ } else {
75
+ this.removeAttribute("custom-error-display");
76
+ }
77
+ }
51
78
  /**
52
79
  * Getter for the customErrorDisplay attribute.
53
80
  * @returns {boolean} Whether the attribute is present.
@@ -55,6 +82,21 @@ class Input extends WJElement {
55
82
  get customErrorDisplay() {
56
83
  return this.hasAttribute("custom-error-display");
57
84
  }
85
+ /**
86
+ * Sets the `validateOnChange` property. If set to a truthy value, it adds the
87
+ * `validate-on-change` attribute to the element. If set to a falsy value, it
88
+ * removes the `validate-on-change` attribute from the element.
89
+ * @param {boolean} value Determines whether to add or remove the
90
+ * `validate-on-change` attribute. A truthy value adds the attribute, whereas a
91
+ * falsy value removes it.
92
+ */
93
+ set validateOnChange(value) {
94
+ if (value) {
95
+ this.setAttribute("validate-on-change", "");
96
+ } else {
97
+ this.removeAttribute("validate-on-change");
98
+ }
99
+ }
58
100
  /**
59
101
  * Getter for the validateOnChange attribute.
60
102
  * @returns {boolean} Whether the attribute is present.
@@ -63,19 +105,23 @@ class Input extends WJElement {
63
105
  return this.hasAttribute("validate-on-change");
64
106
  }
65
107
  /**
66
- * Getter for the invalid attribute.
67
- * @returns {boolean} Whether the attribute is present.
108
+ * Sets or removes the 'invalid' attribute on an element based on the provided value.
109
+ * @param {boolean} value If true, the 'invalid' attribute is set. If false, the 'invalid' attribute is removed.
68
110
  */
69
- get invalid() {
70
- return this.hasAttribute("invalid");
111
+ set invalid(value) {
112
+ if (value) {
113
+ this.setAttribute("invalid", "");
114
+ } else {
115
+ this.removeAttribute("invalid");
116
+ }
71
117
  }
72
118
  /**
73
- * Setter for the invalid attribute.
74
- * @param {boolean} isInvalid Whether the input is invalid.
119
+ * Gets the value of the 'invalid' attribute.
120
+ * Determines whether the 'invalid' attribute is present on the element.
121
+ * @returns {boolean} True if the 'invalid' attribute is present, otherwise false.
75
122
  */
76
- set invalid(isInvalid) {
77
- if (isInvalid) this.setAttribute("invalid", "");
78
- else this.removeAttribute("invalid");
123
+ get invalid() {
124
+ return this.hasAttribute("invalid");
79
125
  }
80
126
  /**
81
127
  * Getter for the form attribute.
@@ -131,6 +177,11 @@ class Input extends WJElement {
131
177
  set defaultValue(value) {
132
178
  this.setAttribute("value", value);
133
179
  }
180
+ /**
181
+ * Sets or removes the 'clearable' attribute on the element.
182
+ * When set to a truthy value, the 'clearable' attribute is added; when falsy, the attribute is removed.
183
+ * @param {boolean} value Determines whether to set or remove the 'clearable' attribute. If true, the 'clearable' attribute is added. If false, it is removed.
184
+ */
134
185
  set clearable(value) {
135
186
  if (value) {
136
187
  this.setAttribute("clearable", "");
@@ -138,9 +189,19 @@ class Input extends WJElement {
138
189
  this.removeAttribute("clearable");
139
190
  }
140
191
  }
192
+ /**
193
+ * Checks if the 'clearable' attribute is present on the element.
194
+ * @returns {boolean} True if the 'clearable' attribute is set, otherwise false.
195
+ */
141
196
  get clearable() {
142
197
  return this.hasAttribute("clearable");
143
198
  }
199
+ /**
200
+ * Sets the placeholder value for an element. If the provided value is non-empty,
201
+ * it assigns the value to the "placeholder" attribute. Otherwise, it removes
202
+ * the "placeholder" attribute from the element.
203
+ * @param {string} value The placeholder text to set or null/undefined to remove the attribute.
204
+ */
144
205
  set placeholder(value) {
145
206
  if (value) {
146
207
  this.setAttribute("placeholder", value);
@@ -148,9 +209,19 @@ class Input extends WJElement {
148
209
  this.removeAttribute("placeholder");
149
210
  }
150
211
  }
212
+ /**
213
+ * Retrieves the value of the 'placeholder' attribute from the element.
214
+ * If the attribute is not set, it returns an empty string.
215
+ * @returns {string} The value of the 'placeholder' attribute or an empty string if not set.
216
+ */
151
217
  get placeholder() {
152
218
  return this.getAttribute("placeholder") || "";
153
219
  }
220
+ /**
221
+ * Sets the `variant` attribute on the element. If a value is provided, it will set the attribute to the given value.
222
+ * If no value is provided, it removes the `variant` attribute from the element.
223
+ * @param {string} value The value to set for the `variant` attribute. If falsy, the attribute is removed.
224
+ */
154
225
  set variant(value) {
155
226
  if (value) {
156
227
  this.setAttribute("variant", value);
@@ -158,6 +229,11 @@ class Input extends WJElement {
158
229
  this.removeAttribute("variant");
159
230
  }
160
231
  }
232
+ /**
233
+ * Retrieves the value of the 'variant' attribute from the element.
234
+ * If the attribute is not set, it defaults to 'default'.
235
+ * @returns {string} The value of the 'variant' attribute or 'default' if not set.
236
+ */
161
237
  get variant() {
162
238
  return this.getAttribute("variant") || "default";
163
239
  }
@@ -195,7 +271,7 @@ class Input extends WJElement {
195
271
  draw() {
196
272
  let hasSlotStart = this.hasSlot(this, "start");
197
273
  let hasSlotEnd = this.hasSlot(this, "end");
198
- let hasSlotError = this.hasSlot(this, "error");
274
+ this.hasSlot(this, "error");
199
275
  let fragment = document.createDocumentFragment();
200
276
  let native = document.createElement("div");
201
277
  native.setAttribute("part", "native");
@@ -222,21 +298,7 @@ class Input extends WJElement {
222
298
  }
223
299
  });
224
300
  let error = document.createElement("div");
225
- error.classList.add("error-message");
226
- error.setAttribute("part", "error");
227
- let errorSlot = null;
228
- if (hasSlotError) {
229
- errorSlot = document.createElement("slot");
230
- errorSlot.setAttribute("name", "error");
231
- if (this.hasAttribute("error-inline")) {
232
- native.appendChild(errorSlot);
233
- } else {
234
- error.appendChild(errorSlot);
235
- wrapper.appendChild(error);
236
- }
237
- } else {
238
- wrapper.appendChild(error);
239
- }
301
+ error.setAttribute("slot", "error");
240
302
  let start = null;
241
303
  if (hasSlotStart) {
242
304
  start = document.createElement("slot");
@@ -253,14 +315,20 @@ class Input extends WJElement {
253
315
  wrapper.appendChild(start);
254
316
  native.classList.add("has-start");
255
317
  }
256
- if (this.variant === "standard") {
257
- if (this.label) native.appendChild(label);
258
- } else {
259
- inputWrapper.appendChild(label);
318
+ if (this.label) {
319
+ if (this.variant === "standard") {
320
+ native.append(label);
321
+ } else {
322
+ inputWrapper.appendChild(label);
323
+ }
260
324
  }
261
325
  inputWrapper.appendChild(input);
262
326
  wrapper.appendChild(inputWrapper);
263
327
  native.appendChild(wrapper);
328
+ let errorSlot = document.createElement("slot");
329
+ errorSlot.setAttribute("name", "error");
330
+ native.append(errorSlot);
331
+ this.append(error);
264
332
  if (this.clearable) {
265
333
  this.clear = document.createElement("wje-button");
266
334
  this.clear.classList.add("clear");
@@ -347,14 +415,14 @@ class Input extends WJElement {
347
415
  let hasSlotError = this.hasSlot(this, "error");
348
416
  if (hasSlotError) {
349
417
  const slot = this.querySelector("[slot='error']");
350
- let errorMessage = slot.querySelector("[error-message]");
351
- if (!errorMessage) {
418
+ let errorMessageEL = slot.querySelector("[error-message]");
419
+ if (!errorMessageEL) {
352
420
  const error = document.createElement("div");
353
421
  error.setAttribute("error-message", "");
354
- slot.appendChild(error);
355
- errorMessage = error;
422
+ slot.append(error);
423
+ errorMessageEL = error;
356
424
  }
357
- errorMessage.textContent = this.internals.validationMessage;
425
+ errorMessageEL.textContent = this.internals.validationMessage;
358
426
  } else {
359
427
  this.errorMessage.textContent = this.internals.validationMessage;
360
428
  }
@@ -386,14 +454,14 @@ class Input extends WJElement {
386
454
  }
387
455
  }
388
456
  /**
389
- * @summary Propagates the validation state of the input.
390
- * This method sets the 'invalid' property of the input based on its 'pristine' state and its internal validity state.
391
- * If the input is invalid and the 'customErrorDisplay' property is true, it dispatches an 'invalid' event.
457
+ * Checks and updates the validation state of the component based on its current properties.
458
+ * If the component is invalid and a custom error display is enabled, it dispatches an 'invalid' event.
459
+ * @returns {void} This method does not return a value.
392
460
  */
393
461
  propagateValidation() {
394
- this.invalid = !this.pristine && !this.internals.validity.valid;
395
- if (this.invalid && this.customErrorDisplay) {
396
- this.dispatchEvent(new Event("invalid"));
462
+ this.invalid = !this.pristine && !this.validity.valid;
463
+ if (this.invalid) {
464
+ event.dispatchCustomEvent(this, "invalid");
397
465
  }
398
466
  }
399
467
  /**