wj-elements 0.1.230 → 0.1.232
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 +1 -1
- package/dist/packages/wje-color-picker/color-picker.element.d.ts +74 -31
- package/dist/packages/wje-dropdown/dropdown.element.d.ts +1 -1
- package/dist/packages/wje-icon-picker/icon-picker.element.d.ts +40 -17
- package/dist/packages/wje-infinite-scroll/infinite-scroll.element.d.ts +1 -0
- package/dist/packages/wje-router/router.element.d.ts +40 -0
- package/dist/packages/wje-toggle/toggle.element.d.ts +39 -23
- package/dist/wje-checkbox.js +2 -2
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-color-picker.js +169 -66
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-dropdown.js +1 -1
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +1 -1
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-icon-picker.js +92 -60
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-infinite-scroll.js +9 -0
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input.js +6 -1
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-radio-group.js +5 -1
- package/dist/wje-radio-group.js.map +1 -1
- package/dist/wje-routerx.js +76 -8
- package/dist/wje-routerx.js.map +1 -1
- package/dist/wje-select.js +1 -1
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-textarea.js +5 -1
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-toggle.js +145 -66
- package/dist/wje-toggle.js.map +1 -1
- package/package.json +1 -1
package/dist/light.css
CHANGED
|
@@ -313,7 +313,7 @@
|
|
|
313
313
|
--wje-color-picker-area: transparent;
|
|
314
314
|
--wje-color-picker-swatch: transparent;
|
|
315
315
|
--wje-color-picker-size: 1rem;
|
|
316
|
-
--wje-color-picker-radius:
|
|
316
|
+
--wje-color-picker-radius: var(--wje-border-radius-large);
|
|
317
317
|
|
|
318
318
|
/* Checkbox */
|
|
319
319
|
--wje-checkbox-interminate: url('data:image/svg+xml;base64,PHN2ZyAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgd2lkdGg9IjI0IiAgaGVpZ2h0PSIyNCIgIHZpZXdCb3g9IjAgMCAyNCAyNCIgIGZpbGw9Im5vbmUiICBzdHJva2U9ImN1cnJlbnRDb2xvciIgIHN0cm9rZS13aWR0aD0iMiIgIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgIHN0cm9rZS1saW5lam9pbj0icm91bmQiICBjbGFzcz0iaWNvbiBpY29uLXRhYmxlciBpY29ucy10YWJsZXItb3V0bGluZSBpY29uLXRhYmxlci1taW51cyI+PHBhdGggc3Ryb2tlPSJub25lIiBkPSJNMCAwaDI0djI0SDB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTUgMTJsMTQgMCIgLz48L3N2Zz4=');
|
|
@@ -46,6 +46,16 @@ export default class ColorPicker extends WJElement {
|
|
|
46
46
|
* @private
|
|
47
47
|
*/
|
|
48
48
|
private _swatches;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the color attribute of the element.
|
|
51
|
+
* @param {string} value The color value to be set. It should be a valid color string such as a named color, HEX, RGB, or HSL format.
|
|
52
|
+
*/
|
|
53
|
+
set color(value: string);
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the color attribute of the element.
|
|
56
|
+
* @returns {string | null} The current value of the 'color' attribute, or null if the attribute is not set.
|
|
57
|
+
*/
|
|
58
|
+
get color(): string | null;
|
|
49
59
|
/**
|
|
50
60
|
* Setter for the marker position.
|
|
51
61
|
* @param {object} value The new marker position.
|
|
@@ -67,11 +77,44 @@ export default class ColorPicker extends WJElement {
|
|
|
67
77
|
*/
|
|
68
78
|
get swatches(): any[];
|
|
69
79
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
80
|
+
* Sets or removes the 'no-color-area' attribute based on the provided value.
|
|
81
|
+
* @param {boolean} value A boolean value indicating whether to set or remove the 'no-color-area' attribute. If true, the attribute is added; if false, the attribute is removed.
|
|
82
|
+
*/
|
|
83
|
+
set noColorArea(value: boolean);
|
|
84
|
+
/**
|
|
85
|
+
* Getter method to check if the 'no-color-area' attribute is applied.
|
|
86
|
+
* @returns {boolean} Returns true if the 'no-color-area' attribute is present; otherwise, false.
|
|
87
|
+
*/
|
|
88
|
+
get noColorArea(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Sets or removes the "no-controls" attribute.
|
|
91
|
+
* @param {boolean} value If true, sets the "no-controls" attribute. If false, removes the "no-controls" attribute.
|
|
92
|
+
*/
|
|
93
|
+
set noControls(value: boolean);
|
|
94
|
+
/**
|
|
95
|
+
* Checks if the 'no-controls' attribute is present on the element.
|
|
96
|
+
* @returns {boolean} Returns true if the 'no-controls' attribute is present; otherwise, false.
|
|
97
|
+
*/
|
|
98
|
+
get noControls(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Sets or removes the 'no-swatches' attribute on the element.
|
|
101
|
+
* If the value is truthy, the 'no-swatches' attribute is added.
|
|
102
|
+
* If the value is falsy, the 'no-swatches' attribute is removed.
|
|
103
|
+
* @param {boolean} value Determines whether the 'no-swatches' attribute is set (true) or removed (false).
|
|
104
|
+
*/
|
|
105
|
+
set noSwatches(value: boolean);
|
|
106
|
+
/**
|
|
107
|
+
* Checks if the 'no-swatches' attribute is present on the element.
|
|
108
|
+
* @returns {boolean} Returns true if the 'no-swatches' attribute is present; otherwise, false.
|
|
109
|
+
*/
|
|
110
|
+
get noSwatches(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Creates and returns a document fragment containing the structure and components of a custom color picker.
|
|
113
|
+
* The method initializes DOM elements such as divs, sliders, and inputs, with specific classes and attributes,
|
|
114
|
+
* and attaches various event listeners to handle user interactions.
|
|
115
|
+
* @returns {DocumentFragment} A DocumentFragment containing the constructed and fully initialized DOM elements for the color picker.
|
|
72
116
|
*/
|
|
73
117
|
draw(): DocumentFragment;
|
|
74
|
-
popup: HTMLElement;
|
|
75
118
|
anchor: HTMLDivElement;
|
|
76
119
|
picker: HTMLDivElement;
|
|
77
120
|
marker: HTMLDivElement;
|
|
@@ -80,50 +123,50 @@ export default class ColorPicker extends WJElement {
|
|
|
80
123
|
alphaSlider: HTMLElement;
|
|
81
124
|
colorPreview: HTMLDivElement;
|
|
82
125
|
input: HTMLElement;
|
|
126
|
+
/**
|
|
127
|
+
* Executes after the component is drawn. Initializes some configurations if not already initialized,
|
|
128
|
+
* including updating slider values, setting marker positions, and applying initial color settings.
|
|
129
|
+
* This method ensures that all necessary visual elements and configurations are properly set up.
|
|
130
|
+
* @returns {void} Does not return a value.
|
|
131
|
+
*/
|
|
132
|
+
afterDraw(): void;
|
|
133
|
+
colorAreaDimension: any;
|
|
83
134
|
/**
|
|
84
135
|
* Sets the hue.
|
|
85
136
|
* @param node
|
|
86
137
|
*/
|
|
87
138
|
createSwatches(node: any): void;
|
|
88
|
-
/**
|
|
89
|
-
* Sets up the event listeners for the ColorPicker.
|
|
90
|
-
*/
|
|
91
|
-
afterDraw(): void;
|
|
92
|
-
init: boolean;
|
|
93
|
-
colorAreaDimension: {
|
|
94
|
-
width: any;
|
|
95
|
-
x: any;
|
|
96
|
-
y: any;
|
|
97
|
-
height: any;
|
|
98
|
-
};
|
|
99
139
|
/**
|
|
100
140
|
* Sets the sliders to the given color.
|
|
101
141
|
* @param color
|
|
102
142
|
*/
|
|
103
143
|
setSliders(color: any): void;
|
|
104
144
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @returns {
|
|
145
|
+
* Retrieves the dimensions and position of the color area element relative to the viewport.
|
|
146
|
+
* @returns {object} An object containing the following properties:
|
|
147
|
+
* width: The width of the element in pixels.
|
|
148
|
+
* height: The height of the element in pixels.
|
|
149
|
+
* x: The x-coordinate of the element's left edge relative to the viewport.
|
|
150
|
+
* y: The y-coordinate of the element's top edge relative to the viewport.
|
|
107
151
|
*/
|
|
108
|
-
dimension():
|
|
109
|
-
width: any;
|
|
110
|
-
x: any;
|
|
111
|
-
y: any;
|
|
112
|
-
height: any;
|
|
113
|
-
};
|
|
152
|
+
dimension(): object;
|
|
114
153
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
154
|
+
* Updates the position of the marker based on the pointer event.
|
|
155
|
+
* This function calculates the position of the marker relative to the color area
|
|
156
|
+
* dimensions based on the given event. It adjusts the marker position and updates
|
|
157
|
+
* the color associated with the new position. It is intended to handle pointer movement
|
|
158
|
+
* events such as mouse or touch interactions.
|
|
159
|
+
* @param {Event} e The event triggering the marker movement, typically a mouse or touch event.
|
|
117
160
|
*/
|
|
118
|
-
moveMarker: (e:
|
|
161
|
+
moveMarker: (e: Event) => void;
|
|
119
162
|
/**
|
|
120
|
-
*
|
|
163
|
+
* Gets the pointer position in client coordinates (viewport-relative).
|
|
121
164
|
* @param e
|
|
122
|
-
* @returns {{
|
|
165
|
+
* @returns {{x: number, y: number}}
|
|
123
166
|
*/
|
|
124
167
|
getPointerPosition(e: any): {
|
|
125
|
-
|
|
126
|
-
|
|
168
|
+
x: number;
|
|
169
|
+
y: number;
|
|
127
170
|
};
|
|
128
171
|
/**
|
|
129
172
|
* Sets the position of the marker.
|
|
@@ -182,6 +225,6 @@ export default class ColorPicker extends WJElement {
|
|
|
182
225
|
* @param {number} alpha The alpha value, typically between 0 and 100, representing the opacity percentage.
|
|
183
226
|
* @returns {string} - The HSVA color string in the format `hsva(h, 100%, 100%, a)`.
|
|
184
227
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
228
|
+
getHSVA: (hue: number, alpha: number) => string;
|
|
229
|
+
#private;
|
|
187
230
|
}
|
|
@@ -30,7 +30,7 @@ export default class Dropdown extends WJElement {
|
|
|
30
30
|
* Sets or removes the 'portaled' attribute on the element.
|
|
31
31
|
* When the value is truthy, the attribute 'portaled' is added to the element.
|
|
32
32
|
* When the value is falsy, the attribute 'portaled' is removed from the element.
|
|
33
|
-
* @param {boolean} value
|
|
33
|
+
* @param {boolean} value Determines whether to add or remove the 'portaled' attribute.
|
|
34
34
|
*/
|
|
35
35
|
set portaled(value: boolean);
|
|
36
36
|
/**
|
|
@@ -2,7 +2,6 @@ import { default as WJElement } from '../wje-element/element.js';
|
|
|
2
2
|
import { default as Input } from '../wje-input/input.js';
|
|
3
3
|
import { default as InfiniteScroll } from '../wje-infinite-scroll/infinite-scroll.js';
|
|
4
4
|
import { default as Tooltip } from '../wje-tooltip/tooltip.js';
|
|
5
|
-
import { default as Popup } from '../wje-popup/popup.js';
|
|
6
5
|
/**
|
|
7
6
|
* @summary This element allows users to pick an icon from a set of available options.
|
|
8
7
|
* `IconPicker` is a custom web component that represents an interactive icon picker. It features
|
|
@@ -45,7 +44,6 @@ export default class IconPicker extends WJElement {
|
|
|
45
44
|
'wje-input': typeof Input;
|
|
46
45
|
'wje-infinite-scroll': typeof InfiniteScroll;
|
|
47
46
|
'wje-tooltip': typeof Tooltip;
|
|
48
|
-
'wje-popup': typeof Popup;
|
|
49
47
|
};
|
|
50
48
|
/**
|
|
51
49
|
* Setter for the markerPosition property.
|
|
@@ -68,28 +66,55 @@ export default class IconPicker extends WJElement {
|
|
|
68
66
|
*/
|
|
69
67
|
get icon(): string;
|
|
70
68
|
/**
|
|
71
|
-
*
|
|
69
|
+
* Setter for the value property.
|
|
70
|
+
* @param value
|
|
71
|
+
*/
|
|
72
|
+
set type(value: string);
|
|
73
|
+
/**
|
|
74
|
+
* Getter for the value property.
|
|
75
|
+
* @returns {string}
|
|
76
|
+
*/
|
|
77
|
+
get type(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Prepares data before the draw operation by fetching tags, transforming objects, and creating an index.
|
|
80
|
+
* @returns {Promise<void>} Resolves when data preparation is complete.
|
|
72
81
|
*/
|
|
73
82
|
beforeDraw(): Promise<void>;
|
|
74
83
|
tags: any[];
|
|
75
84
|
transformedObjects: any[];
|
|
76
85
|
index: any[];
|
|
77
86
|
/**
|
|
78
|
-
* Draws the component.
|
|
79
|
-
*
|
|
87
|
+
* Draws and initializes the native color picker component on the DOM.
|
|
88
|
+
* This method creates and appends the necessary elements, including input and infinite scroll components,
|
|
89
|
+
* and sets their attributes and event listeners. It also provides custom data handling for infinite scrolling
|
|
90
|
+
* and manages the way icons are displayed based on input.
|
|
91
|
+
* @returns {DocumentFragment} A document fragment containing the fully constructed color picker component.
|
|
80
92
|
*/
|
|
81
93
|
draw(): DocumentFragment;
|
|
82
|
-
popup: HTMLElement;
|
|
83
94
|
input: HTMLElement;
|
|
84
|
-
anchor: HTMLDivElement;
|
|
85
95
|
picker: HTMLDivElement;
|
|
86
96
|
infiniteScroll: InfiniteScroll;
|
|
87
97
|
/**
|
|
88
|
-
*
|
|
98
|
+
* Executes actions that occur after the component finishes its draw phase. Sets up event listeners for input clear
|
|
99
|
+
* and infinite scroll item clicks, resets initialization state, and rebinds scroll-related events.
|
|
100
|
+
* @returns {void} Does not return a value.
|
|
89
101
|
*/
|
|
90
102
|
afterDraw(): void;
|
|
91
|
-
value: any;
|
|
92
103
|
init: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Handles the selection of an icon from a given input element and updates the relevant properties and events.
|
|
106
|
+
* @function selectIcon
|
|
107
|
+
* @param {HTMLElement} icon The icon element that was selected. It must have a 'name' attribute and may optionally have a 'filled' attribute.
|
|
108
|
+
* The function performs the following actions:
|
|
109
|
+
* - Retrieves the name of the selected icon from its 'name' attribute.
|
|
110
|
+
* - Determines the style type ('filled' or 'outline') based on the presence of the 'filled' attribute.
|
|
111
|
+
* - Searches for a matching object in the `transformedObjects` array based on name and style.
|
|
112
|
+
* - Creates a new `wje-icon` element and assigns its attributes based on the selected icon's properties.
|
|
113
|
+
* - Updates the selected object's properties and assigns it to the `value`, `icon`, and `type` properties of the class.
|
|
114
|
+
* - Dispatches a custom event (`wje-icon-picker:select`) to signal a change in the selected icon.
|
|
115
|
+
*/
|
|
116
|
+
selectIcon: (icon: HTMLElement) => void;
|
|
117
|
+
value: any;
|
|
93
118
|
/**
|
|
94
119
|
* Initializes the component.
|
|
95
120
|
*/
|
|
@@ -157,12 +182,6 @@ export default class IconPicker extends WJElement {
|
|
|
157
182
|
* // </div>
|
|
158
183
|
*/
|
|
159
184
|
dataToHtml: (data: object) => HTMLElement;
|
|
160
|
-
/**
|
|
161
|
-
* Gets the category of the tags.
|
|
162
|
-
* @param {Array} tags The tags to get the category of.
|
|
163
|
-
* @returns {Array} The category of the tags.
|
|
164
|
-
*/
|
|
165
|
-
getCategory(tags: any[]): any[];
|
|
166
185
|
/**
|
|
167
186
|
* Gets the tags.
|
|
168
187
|
* @returns {Promise<Array>} The tags of the component.
|
|
@@ -181,7 +200,11 @@ export default class IconPicker extends WJElement {
|
|
|
181
200
|
*/
|
|
182
201
|
clearIconsContainer(): void;
|
|
183
202
|
/**
|
|
184
|
-
*
|
|
203
|
+
* Creates a debounced version of the provided function that delays its execution
|
|
204
|
+
* until after the specified delay has passed since the last time it was invoked.
|
|
205
|
+
* @param {Function} fn The function to debounce.
|
|
206
|
+
* @param {number} delay The delay duration in milliseconds.
|
|
207
|
+
* @returns {Function} A new debounced function that delays the execution of the original function.
|
|
185
208
|
*/
|
|
186
|
-
|
|
209
|
+
debounce(fn: Function, delay: number): Function;
|
|
187
210
|
}
|
|
@@ -14,6 +14,45 @@ export default class Routerx extends WJElement {
|
|
|
14
14
|
* @returns {Array<string>}
|
|
15
15
|
*/
|
|
16
16
|
static get observedAttributes(): Array<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Sets the `log` property and updates the corresponding attribute on the element.
|
|
19
|
+
* If the `value` is truthy, the `log` attribute is added to the element.
|
|
20
|
+
* If the `value` is falsy, the `log` attribute is removed from the element.
|
|
21
|
+
* @param {boolean} value The value to set for the `log` property. Determines whether the `log` attribute should be present or not.
|
|
22
|
+
*/
|
|
23
|
+
set log(value: boolean);
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the state of the 'log' attribute.
|
|
26
|
+
* @returns {boolean} A boolean value indicating whether the 'log' attribute is present (true) or not (false) on the element.
|
|
27
|
+
*/
|
|
28
|
+
get log(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sets or removes the 'log-error' attribute based on the provided value.
|
|
31
|
+
* @param {boolean} value A boolean indicating whether the 'log-error' attribute should be set (true) or removed (false).
|
|
32
|
+
*/
|
|
33
|
+
set logError(value: boolean);
|
|
34
|
+
/**
|
|
35
|
+
* Determines whether the 'log-error' attribute is present on the current element.
|
|
36
|
+
* @returns {boolean} Returns true if the 'log-error' attribute exists; otherwise, false.
|
|
37
|
+
*/
|
|
38
|
+
get logError(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the routes for the application.
|
|
41
|
+
* @param {object} value The routes object defining the application's routing structure.
|
|
42
|
+
*/
|
|
43
|
+
set routes(value: object);
|
|
44
|
+
/**
|
|
45
|
+
* Accessor method to retrieve the parsed routes from the root element.
|
|
46
|
+
* @returns {object} The parsed routes object derived from the root element.
|
|
47
|
+
*/
|
|
48
|
+
get routes(): object;
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves the root element of type 'wje-router' from the outer HTML.
|
|
51
|
+
* Parses the current object's outer HTML and returns the first element
|
|
52
|
+
* matching the 'wje-router' tag name found within the resultant HTML document.
|
|
53
|
+
* @returns {Element|null} The first 'wje-router' element found within the parsed HTML document, or null if no such element exists.
|
|
54
|
+
*/
|
|
55
|
+
get rootElement(): Element | null;
|
|
17
56
|
/**
|
|
18
57
|
* Sets up the router after the component is drawn.
|
|
19
58
|
*/
|
|
@@ -36,4 +75,5 @@ export default class Routerx extends WJElement {
|
|
|
36
75
|
* @param {object} transition The transition object.
|
|
37
76
|
*/
|
|
38
77
|
resetScrollPosition: (transition: object) => void;
|
|
78
|
+
#private;
|
|
39
79
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FormAssociatedElement } from '../internals/form-associated-element.js';
|
|
2
2
|
/**
|
|
3
3
|
* `Toggle` is a custom web component that represents a toggle input.
|
|
4
4
|
* @summary This element represents a toggle input.
|
|
5
5
|
* @documentation https://elements.webjet.sk/components/toggle
|
|
6
6
|
* @status stable
|
|
7
|
-
* @augments {
|
|
7
|
+
* @augments {FormAssociatedElement}
|
|
8
8
|
* @csspart native - The native toggle wrapper.
|
|
9
9
|
* @csspart input - The toggle input.
|
|
10
10
|
* @csspart toggle - The toggle part.
|
|
@@ -23,43 +23,59 @@ import { default as WJElement } from '../wje-element/element.js';
|
|
|
23
23
|
* @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.
|
|
24
24
|
* @tag wje-toggle
|
|
25
25
|
*/
|
|
26
|
-
export default class Toggle extends
|
|
26
|
+
export default class Toggle extends FormAssociatedElement {
|
|
27
|
+
static get cssStyleSheet(): any;
|
|
28
|
+
static get observedAttributes(): string[];
|
|
29
|
+
pristine: boolean;
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
* @returns {CSSStyleSheet} styles - The CSS stylesheet for the Button element.
|
|
31
|
+
* Setter for the value attribute.
|
|
32
|
+
* @param {string} value The value to set.
|
|
31
33
|
*/
|
|
32
|
-
|
|
34
|
+
set value(value: string);
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @returns {string
|
|
36
|
+
* Getter for the value attribute.
|
|
37
|
+
* @returns {string} The value of the attribute.
|
|
36
38
|
*/
|
|
37
|
-
|
|
39
|
+
get value(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Getter for the customErrorDisplay attribute.
|
|
42
|
+
* @returns {boolean} Whether the attribute is present.
|
|
43
|
+
*/
|
|
44
|
+
get customErrorDisplay(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Getter for the validateOnChange attribute.
|
|
47
|
+
* @returns {boolean} Whether the attribute is present.
|
|
48
|
+
*/
|
|
49
|
+
get validateOnChange(): boolean;
|
|
38
50
|
/**
|
|
39
|
-
*
|
|
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.
|
|
40
55
|
*/
|
|
41
|
-
set
|
|
56
|
+
set defaultValue(value: string);
|
|
42
57
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
58
|
+
* Getter for the defaultValue attribute.
|
|
59
|
+
* This method retrieves the 'value' attribute of the custom input element.
|
|
60
|
+
* The 'value' attribute represents the default value of the input element.
|
|
61
|
+
* If the 'value' attribute is not set, it returns an empty string.
|
|
62
|
+
* @returns {string} The default value of the input element.
|
|
45
63
|
*/
|
|
46
|
-
get
|
|
64
|
+
get defaultValue(): string;
|
|
47
65
|
/**
|
|
48
|
-
* Set checked attribute
|
|
66
|
+
* Set checked attribute.
|
|
67
|
+
* @param {boolean} value true if the toggle is checked, false otherwise
|
|
49
68
|
*/
|
|
50
69
|
set checked(value: boolean);
|
|
51
70
|
/**
|
|
52
|
-
* Get checked attribute
|
|
71
|
+
* Get checked attribute.
|
|
53
72
|
* @returns {boolean} true if the toggle is checked, false otherwise
|
|
54
73
|
*/
|
|
55
74
|
get checked(): boolean;
|
|
56
|
-
|
|
57
|
-
* Draw the toggle element for the component.
|
|
58
|
-
*/
|
|
75
|
+
attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
|
|
59
76
|
draw(): DocumentFragment;
|
|
60
77
|
input: HTMLInputElement;
|
|
61
|
-
/**
|
|
62
|
-
* After draw method for the toggle element to add event listeners for the input element after the element is drawn.
|
|
63
|
-
*/
|
|
64
78
|
afterDraw(): void;
|
|
79
|
+
indeterminate: boolean;
|
|
80
|
+
#private;
|
|
65
81
|
}
|
package/dist/wje-checkbox.js
CHANGED
|
@@ -12,7 +12,7 @@ var _internalValue;
|
|
|
12
12
|
import WJElement from "./wje-element.js";
|
|
13
13
|
import { F as FormAssociatedElement } from "./form-associated-element-o0UjvdUp.js";
|
|
14
14
|
import { event } from "./event.js";
|
|
15
|
-
const styles = "/*\n[ Checkbox ]\n*/\n\n:host {\n display: block;\n margin-top: var(--wje-checkbox-margin-top);\n margin-bottom: var(--wje-checkbox-margin-bottom);\n margin-inline: var(--wje-checkbox-margin-inline);\n line-height: 100%;\n padding-left: 0;\n\n label {\n display: flex;\n align-items: center;\n cursor: pointer;\n position: relative;\n padding-left: calc(var(--wje-checkbox-size) + 0.5rem);\n min-height: var(--wje-checkbox-size);\n margin-bottom: 0;\n &:before {\n content: '';\n position: absolute;\n width: var(--wje-checkbox-size);\n height: var(--wje-checkbox-size);\n left: 0;\n -webkit-box-sizing: inherit;\n box-sizing: border-box;\n background-color: var(--wje-color-contrast-0);\n border-width: 1px;\n border-style: solid;\n border-color: var(--wje-color-contrast-3);\n }\n }\n}\n\n.native-checkbox {\n label {\n &:hover {\n color: var(--wje-color-contrast-11);\n }\n\n &:before {\n border-radius: var(--wje-checkbox-border-radius);\n }\n }\n\n input[type='checkbox'] {\n position: absolute;\n margin: 0;\n z-index: -1;\n width: 16px;\n height: 16px;\n opacity: 0;\n
|
|
15
|
+
const styles = "/*\n[ Checkbox ]\n*/\n\n:host {\n display: block;\n margin-top: var(--wje-checkbox-margin-top);\n margin-bottom: var(--wje-checkbox-margin-bottom);\n margin-inline: var(--wje-checkbox-margin-inline);\n line-height: 100%;\n padding-left: 0;\n\n label {\n display: flex;\n align-items: center;\n cursor: pointer;\n position: relative;\n padding-left: calc(var(--wje-checkbox-size) + 0.5rem);\n min-height: var(--wje-checkbox-size);\n margin-bottom: 0;\n &:before {\n content: '';\n position: absolute;\n width: var(--wje-checkbox-size);\n height: var(--wje-checkbox-size);\n left: 0;\n -webkit-box-sizing: inherit;\n box-sizing: border-box;\n background-color: var(--wje-color-contrast-0);\n border-width: 1px;\n border-style: solid;\n border-color: var(--wje-color-contrast-3);\n }\n }\n}\n\n.native-checkbox {\n label {\n &:hover {\n color: var(--wje-color-contrast-11);\n }\n\n &:before {\n border-radius: var(--wje-checkbox-border-radius);\n }\n }\n\n input[type='checkbox'] {\n position: absolute;\n margin: 0;\n z-index: -1;\n width: 16px;\n height: 16px;\n opacity: 0;\n pointer-events: none;\n & + label {\n &::after {\n content: '';\n position: absolute;\n left: 0;\n border-right: 0 solid transparent;\n border-bottom: 0 solid transparent;\n width: var(--wje-checkbox-size);\n height: var(--wje-checkbox-size);\n overflow: hidden;\n }\n }\n }\n\n input[type='checkbox']:checked + label::after {\n content: '';\n mask-image: var(--wje-checkbox-checkmark);\n mask-size: var(--wje-checkbox-size);\n background-color: var(--wje-color-primary-9);\n }\n\n /* Disabled */\n input[type='checkbox'][disabled] {\n & + label {\n cursor: not-allowed !important;\n color: var(--wje-color-contrast-8);\n opacity: 0.58;\n\n &:before {\n background: var(--wje-color-contrast-2);\n }\n &:after {\n background: transparent;\n }\n }\n }\n\n input[type='checkbox']:checked[disabled] {\n & + label {\n cursor: not-allowed !important;\n color: var(--wje-color-contrast-8);\n opacity: 0.58;\n\n &:before {\n background: var(--wje-color-contrast-2);\n }\n &:after {\n background: var(--wje-color-contrast-5);\n }\n }\n }\n\n /* Indeterminate */\n input[type='checkbox']:not(:checked):indeterminate {\n & + label {\n &:after {\n content: '';\n mask-image: var(--wje-checkbox-interminate);\n mask-size: var(--wje-checkbox-size);\n background-color: var(--wje-color-primary-9);\n }\n }\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\n:host([variant='circle']) {\n label {\n &:after {\n border-radius: 99px;\n }\n\n &:before {\n border-radius: 99px;\n }\n }\n}\n\n:host([placement='end']) {\n label {\n padding-left: 0;\n padding-right: 26px;\n\n &:before {\n right: 0;\n left: auto;\n }\n }\n\n input[type='checkbox']:checked {\n & + label {\n position: relative;\n\n &::after {\n position: absolute;\n right: 0;\n left: auto;\n }\n }\n }\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\n/*Colors*/\n\n:host([color='primary']) {\n input[type='checkbox']:checked + label::after,\n input[type='checkbox']:indeterminate + label:after {\n background-color: var(--wje-color-contrast-0);\n }\n :is(input[type='checkbox']:checked + label)::before,\n :is(input[type='checkbox']:indeterminate + label)::before {\n border-color: var(--wje-color-primary-9);\n background-color: var(--wje-color-primary-9);\n }\n}\n\n:host([color='complete']) {\n input[type='checkbox']:checked + label::after,\n input[type='checkbox']:indeterminate + label:after {\n background-color: var(--wje-color-contrast-0);\n }\n :is(input[type='checkbox']:checked + label)::before,\n :is(input[type='checkbox']:indeterminate + label)::before {\n border-color: var(--wje-color-complete-9);\n background-color: var(--wje-color-complete-9);\n }\n}\n\n:host([color='success']) {\n input[type='checkbox']:checked + label::after,\n input[type='checkbox']:indeterminate + label:after {\n background-color: var(--wje-color-contrast-0);\n }\n :is(input[type='checkbox']:checked + label)::before,\n :is(input[type='checkbox']:indeterminate + label)::before {\n border-color: var(--wje-color-success-9);\n background-color: var(--wje-color-success-9);\n }\n}\n\n:host([color='warning']) {\n input[type='checkbox']:checked + label::after,\n input[type='checkbox']:indeterminate + label:after {\n background-color: var(--wje-color-contrast-0);\n }\n :is(input[type='checkbox']:checked + label)::before,\n :is(input[type='checkbox']:indeterminate + label)::before {\n border-color: var(--wje-color-warning-9);\n background-color: var(--wje-color-warning-9);\n }\n}\n\n:host([color='danger']) {\n input[type='checkbox']:checked + label::after,\n input[type='checkbox']:indeterminate + label:after {\n background-color: var(--wje-color-contrast-0);\n }\n :is(input[type='checkbox']:checked + label)::before,\n :is(input[type='checkbox']:indeterminate + label)::before {\n border-color: var(--wje-color-danger-9);\n background-color: var(--wje-color-danger-9);\n }\n}\n\n:host([color='info']) {\n input[type='checkbox']:checked + label::after,\n input[type='checkbox']:indeterminate + label:after {\n background-color: var(--wje-color-contrast-0);\n }\n :is(input[type='checkbox']:checked + label)::before,\n :is(input[type='checkbox']:indeterminate + label)::before {\n border-color: var(--wje-color-info-9);\n background-color: var(--wje-color-info-9);\n }\n}\n";
|
|
16
16
|
class Checkbox extends FormAssociatedElement {
|
|
17
17
|
/**
|
|
18
18
|
* Checkbox constructor method.
|
|
@@ -217,7 +217,7 @@ class Checkbox extends FormAssociatedElement {
|
|
|
217
217
|
this.input.addEventListener("change", (e) => {
|
|
218
218
|
event.dispatchCustomEvent(this, "wje-toggle:change");
|
|
219
219
|
});
|
|
220
|
-
this.addEventListener("
|
|
220
|
+
this.addEventListener("invalid", (e) => {
|
|
221
221
|
this.invalid = true;
|
|
222
222
|
this.pristine = false;
|
|
223
223
|
this.showInvalidMessage();
|
package/dist/wje-checkbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-checkbox.js","sources":["../packages/wje-checkbox/checkbox.element.js","../packages/wje-checkbox/checkbox.js"],"sourcesContent":["import { FormAssociatedElement } from '../internals/form-associated-element.js';\nimport { event } from '../utils/event.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-toggle:change\".\n * It is triggered when the input event is fired, which happens when the state of the checkbox changes.\n * The event is dispatched on the current instance of the Checkbox class.\n * @documentation https://elements.webjet.sk/components/checkbox\n * @status stable\n * @augments {FormAssociatedElement}\n * @slot - The checkbox main content.\n * @csspart native - The component's native wrapper.\n * @cssproperty [--wje-checkbox-border-radius=--wje-border-radius-medium] - Border radius of the component;\n * @cssproperty [--wje-checkbox-border-width=1px] - Border width of the component;\n * @cssproperty [--wje-checkbox-border-style=solid] - Border style of the component;\n * @cssproperty [--wje-checkbox-border-color=--wje-color-contrast-1] - Border color of the component;\n * @cssproperty [--wje-checkbox-margin-inline=0] - Margin inline of the component;\n */\nexport default class Checkbox extends FormAssociatedElement {\n\t#internalValue;\n\t/**\n\t * Checkbox constructor method.\n\t */\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis.invalid = false;\n\t\tthis.pristine = true;\n\t}\n\n\t/**\n\t * Setter for the value attribute.\n\t * @param {string} value The value to set.\n\t */\n\tset value(value) {\n\t\tthis.#internalValue = value;\n\t\tif (this.input) {\n\t\t\tthis.input.value = value;\n\t\t}\n\t}\n\n\t/**\n\t * Getter for the value attribute.\n\t * @returns {string} The value of the attribute.\n\t */\n\tget value() {\n\t\treturn this.#internalValue ?? this.getAttribute('value') ?? 'on';;\n\t}\n\n\t/**\n\t * Getter for the customErrorDisplay attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget customErrorDisplay() {\n\t\treturn this.hasAttribute('custom-error-display');\n\t}\n\n\t/**\n\t * Getter for the validateOnChange attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget validateOnChange() {\n\t\treturn this.hasAttribute('validate-on-change');\n\t}\n\n\t/**\n\t * Setter for the defaultValue attribute.\n\t * This method sets the 'value' attribute of the custom input element to the provided value.\n\t * The 'value' attribute represents the default value of the input element.\n\t * @param {string} value The value to set as the default value.\n\t */\n\tset defaultValue(value) {\n\t\tthis.setAttribute('value', value);\n\t}\n\n\t/**\n\t * Getter for the defaultValue attribute.\n\t * This method retrieves the 'value' attribute of the custom input element.\n\t * The 'value' attribute represents the default value of the input element.\n\t * If the 'value' attribute is not set, it returns an empty string.\n\t * @returns {string} The default value of the input element.\n\t */\n\tget defaultValue() {\n\t\treturn this.getAttribute('value') ?? '';\n\t}\n\n\t/**\n\t * Sets or removes the 'indeterminate' attribute for the object.\n\t * This property typically reflects the visual or functional state where\n\t * the component is neither fully active nor inactive.\n\t * @param {boolean} value A boolean where `true` indicates the 'indeterminate'\n\t * state should be set, and `false` removes it.\n\t */\n\tset indeterminate(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('indeterminate', '');\n\t\t} else {\n\t\t\tthis.removeAttribute('indeterminate');\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the current state of the 'indeterminate' attribute.\n\t *\n\t * The 'indeterminate' attribute is typically used to signify a state\n\t * where a checkbox is neither checked nor unchecked, such as a partially\n\t * selected state.\n\t * @returns {boolean} Returns true if the 'indeterminate' attribute is present; otherwise, false.\n\t */\n\tget indeterminate() {\n\t\treturn this.hasAttribute('indeterminate');\n\t}\n\n\t/**\n\t * Set checked attribute.\n\t * @param {boolean} value true if the toggle is checked, false otherwise\n\t */\n\tset checked(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('checked', '');\n\t\t\tthis.internals.setFormValue(this.value); // len ak je checked\n\t\t} else {\n\t\t\tthis.removeAttribute('checked');\n\t\t\tthis.internals.setFormValue(null); // ak nie je checked, nič sa neposiela\n\t\t}\n\t\tif (this.input) {\n\t\t\tthis.input.checked = value;\n\t\t}\n\t}\n\n\t/**\n\t * Get checked attribute.\n\t * @returns {boolean} true if the toggle is checked, false otherwise\n\t */\n\tget checked() {\n\t\treturn this.hasAttribute('checked');\n\t}\n\n\t/**\n\t * The class name for the Checkbox.\n\t */\n\tclassName = 'Checkbox';\n\n\t/**\n\t * Getter for the CSS stylesheet.\n\t * @returns {string} The CSS stylesheet.\n\t */\n\tstatic get cssStyleSheet() {\n\t\treturn styles;\n\t}\n\n\tstatic get observedAttributes() {\n\t\treturn ['checked', 'disabled', 'value', 'indeterminate'];\n\t}\n\n\tattributeChangedCallback(name, oldValue, newValue) {\n\t\tif (!this.input) return;\n\t\tif (name === 'checked') {\n\t\t\tconst isChecked = this.hasAttribute('checked');\n\t\t\tthis.input.checked = isChecked;\n\t\t\t// Reflect into form value\n\t\t\tif (isChecked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t} else {\n\t\t\t\tthis.internals.setFormValue(null);\n\t\t\t}\n\t\t} else if (name === 'disabled') {\n\t\t\tthis.input.disabled = this.hasAttribute('disabled');\n\t\t} else if (name === 'indeterminate') {\n\t\t\tthis.input.indeterminate = this.hasAttribute('indeterminate');\n\t\t} else if (name === 'value') {\n\t\t\t// keep payload in sync; do not toggle checked here\n\t\t\tthis.#internalValue = newValue ?? undefined;\n\t\t\tthis.input.value = this.value;\n\t\t\t// If currently checked, update the submitted payload\n\t\t\tif (this.input.checked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets up the attributes for the checkbox.\n\t */\n\tsetupAttributes() {\n\t\tthis.isShadowRoot = 'open';\n\t\t// if some value was set via value setter then dont use default value\n\t\tif (this.pristine) {\n\t\t\tthis.value = this.#internalValue;\n\t\t\tthis.pristine = false;\n\t\t}\n\t}\n\n\t/**\n\t * Draws the checkbox element.\n\t * @returns {DocumentFragment} The created fragment.\n\t */\n\tdraw() {\n\t\tlet fragment = document.createDocumentFragment();\n\n\t\tlet native = document.createElement('div');\n\t\tnative.setAttribute('part', 'native');\n\t\tnative.classList.add('native-checkbox');\n\n\t\tlet input = document.createElement('input');\n\t\tinput.type = 'checkbox';\n\t\tinput.id = 'checkbox';\n\t\tinput.name = this.name || 'checkbox';\n\t\tinput.checked = this.checked;\n\t\tinput.disabled = this.disabled;\n\t\tinput.indeterminate = this.indeterminate;\n\t\tinput.required = this.required;\n\t\tinput.value = this.value;\n\n\t\tlet label = document.createElement('label');\n\t\tlabel.htmlFor = 'checkbox';\n\t\tlabel.innerHTML = '<slot></slot>';\n\n\t\t// Error\n\t\tlet errorSlot = document.createElement('slot');\n\t\terrorSlot.setAttribute('name', 'error');\n\n\t\tlet error = document.createElement('div');\n\t\terror.setAttribute('slot', 'error');\n\n\t\tnative.append(input);\n\t\tnative.append(label);\n\t\tnative.append(errorSlot);\n\n\t\tthis.append(error);\n\n\t\tthis.input = input;\n\n\t\tfragment.appendChild(native);\n\n\t\treturn fragment;\n\t}\n\n\t/**\n\t * Adds an event listener after drawing the checkbox.\n\t */\n\tafterDraw() {\n\t\tthis.internals.setFormValue(this.checked ? this.value : null); // Set initial form value based on checked state\n\n\t\tif (!this.disabled) {\n\t\t\tthis.input.addEventListener('input', (e) => {\n\t\t\t\tthis.validate();\n\n\t\t\t\tthis.pristine = false;\n\t\t\t\tthis.propagateValidation();\n\n\t\t\t\t// User interaction decides the checked state; value stays as payload\n\t\t\t\tthis.indeterminate = false;\n\t\t\t\tthis.checked = e.target.checked;\n\n\t\t\t\t// Fire checkbox-specific event name\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:input');\n\t\t\t});\n\n\t\t\tthis.input.addEventListener('change', (e) => {\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:change');\n\t\t\t});\n\n\t\t\tthis.addEventListener('wje-toggle:invalid', (e) => {\n\t\t\t\tthis.invalid = true;\n\t\t\t\tthis.pristine = false;\n\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t});\n\n\t\t\tthis.validate();\n\n\t\t\tif (this.invalid) {\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the event listener when the checkbox is disconnected.\n\t */\n\tbeforeDisconnect() {\n\t\tevent.removeElement(this.input);\n\t}\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Checkbox from './checkbox.element.js';\n\n// export * from \"./checkbox.element.js\";\nexport default Checkbox;\n\nWJElement.define('wje-checkbox', Checkbox);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBe,MAAM,iBAAiB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAK3D,cAAc;AACb,UAAO;AALR;AA0HA;AAAA;AAAA;AAAA,qCAAY;AAnHX,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,MAAM,OAAO;AAChB,uBAAK,gBAAiB;AACtB,QAAI,KAAK,OAAO;AACf,WAAK,MAAM,QAAQ;AAAA,IACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,QAAQ;AACX,WAAO,mBAAK,mBAAkB,KAAK,aAAa,OAAO,KAAK;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;A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M,YAAY;AAGlB,QAAI,YAAY,SAAS,cAAc,MAAM;AAC7C,cAAU,aAAa,QAAQ,OAAO;AAEtC,QAAI,QAAQ,SAAS,cAAc,KAAK;AACxC,UAAM,aAAa,QAAQ,OAAO;AAElC,WAAO,OAAO,KAAK;AACnB,WAAO,OAAO,KAAK;AACnB,WAAO,OAAO,SAAS;AAEvB,SAAK,OAAO,KAAK;AAEjB,SAAK,QAAQ;AAEb,aAAS,YAAY,MAAM;AAE3B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKC,YAAY;AACX,SAAK,UAAU,aAAa,KAAK,UAAU,KAAK,QAAQ,IAAI;AAE5D,QAAI,CAAC,KAAK,UAAU;AACnB,WAAK,MAAM,iBAAiB,SAAS,CAAC,MAAM;AAC3C,aAAK,SAAU;AAEf,aAAK,WAAW;AAChB,aAAK,oBAAqB;AAG1B,aAAK,gBAAgB;AACrB,aAAK,UAAU,EAAE,OAAO;AAGxB,cAAM,oBAAoB,MAAM,kBAAkB;AAAA,MACtD,CAAI;AAED,WAAK,MAAM,iBAAiB,UAAU,CAAC,MAAM;AAC5C,cAAM,oBAAoB,MAAM,mBAAmB;AAAA,MACvD,CAAI;AAED,WAAK,iBAAiB,sBAAsB,CAAC,MAAM;AAClD,aAAK,UAAU;AACf,aAAK,WAAW;AAEhB,aAAK,mBAAoB;AAAA,MAC7B,CAAI;AAED,WAAK,SAAU;AAEf,UAAI,KAAK,SAAS;AACjB,aAAK,mBAAoB;AAAA,MAC7B;AAAA,IACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKC,mBAAmB;AAClB,UAAM,cAAc,KAAK,KAAK;AAAA,EAChC;AACA;AAzQC;ACdD,UAAU,OAAO,gBAAgB,QAAQ;"}
|
|
1
|
+
{"version":3,"file":"wje-checkbox.js","sources":["../packages/wje-checkbox/checkbox.element.js","../packages/wje-checkbox/checkbox.js"],"sourcesContent":["import { FormAssociatedElement } from '../internals/form-associated-element.js';\nimport { event } from '../utils/event.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-toggle:change\".\n * It is triggered when the input event is fired, which happens when the state of the checkbox changes.\n * The event is dispatched on the current instance of the Checkbox class.\n * @documentation https://elements.webjet.sk/components/checkbox\n * @status stable\n * @augments {FormAssociatedElement}\n * @slot - The checkbox main content.\n * @csspart native - The component's native wrapper.\n * @cssproperty [--wje-checkbox-border-radius=--wje-border-radius-medium] - Border radius of the component;\n * @cssproperty [--wje-checkbox-border-width=1px] - Border width of the component;\n * @cssproperty [--wje-checkbox-border-style=solid] - Border style of the component;\n * @cssproperty [--wje-checkbox-border-color=--wje-color-contrast-1] - Border color of the component;\n * @cssproperty [--wje-checkbox-margin-inline=0] - Margin inline of the component;\n */\nexport default class Checkbox extends FormAssociatedElement {\n\t#internalValue;\n\t/**\n\t * Checkbox constructor method.\n\t */\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis.invalid = false;\n\t\tthis.pristine = true;\n\t}\n\n\t/**\n\t * Setter for the value attribute.\n\t * @param {string} value The value to set.\n\t */\n\tset value(value) {\n\t\tthis.#internalValue = value;\n\t\tif (this.input) {\n\t\t\tthis.input.value = value;\n\t\t}\n\t}\n\n\t/**\n\t * Getter for the value attribute.\n\t * @returns {string} The value of the attribute.\n\t */\n\tget value() {\n\t\treturn this.#internalValue ?? this.getAttribute('value') ?? 'on';;\n\t}\n\n\t/**\n\t * Getter for the customErrorDisplay attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget customErrorDisplay() {\n\t\treturn this.hasAttribute('custom-error-display');\n\t}\n\n\t/**\n\t * Getter for the validateOnChange attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget validateOnChange() {\n\t\treturn this.hasAttribute('validate-on-change');\n\t}\n\n\t/**\n\t * Setter for the defaultValue attribute.\n\t * This method sets the 'value' attribute of the custom input element to the provided value.\n\t * The 'value' attribute represents the default value of the input element.\n\t * @param {string} value The value to set as the default value.\n\t */\n\tset defaultValue(value) {\n\t\tthis.setAttribute('value', value);\n\t}\n\n\t/**\n\t * Getter for the defaultValue attribute.\n\t * This method retrieves the 'value' attribute of the custom input element.\n\t * The 'value' attribute represents the default value of the input element.\n\t * If the 'value' attribute is not set, it returns an empty string.\n\t * @returns {string} The default value of the input element.\n\t */\n\tget defaultValue() {\n\t\treturn this.getAttribute('value') ?? '';\n\t}\n\n\t/**\n\t * Sets or removes the 'indeterminate' attribute for the object.\n\t * This property typically reflects the visual or functional state where\n\t * the component is neither fully active nor inactive.\n\t * @param {boolean} value A boolean where `true` indicates the 'indeterminate'\n\t * state should be set, and `false` removes it.\n\t */\n\tset indeterminate(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('indeterminate', '');\n\t\t} else {\n\t\t\tthis.removeAttribute('indeterminate');\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the current state of the 'indeterminate' attribute.\n\t *\n\t * The 'indeterminate' attribute is typically used to signify a state\n\t * where a checkbox is neither checked nor unchecked, such as a partially\n\t * selected state.\n\t * @returns {boolean} Returns true if the 'indeterminate' attribute is present; otherwise, false.\n\t */\n\tget indeterminate() {\n\t\treturn this.hasAttribute('indeterminate');\n\t}\n\n\t/**\n\t * Set checked attribute.\n\t * @param {boolean} value true if the toggle is checked, false otherwise\n\t */\n\tset checked(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('checked', '');\n\t\t\tthis.internals.setFormValue(this.value); // len ak je checked\n\t\t} else {\n\t\t\tthis.removeAttribute('checked');\n\t\t\tthis.internals.setFormValue(null); // ak nie je checked, nič sa neposiela\n\t\t}\n\t\tif (this.input) {\n\t\t\tthis.input.checked = value;\n\t\t}\n\t}\n\n\t/**\n\t * Get checked attribute.\n\t * @returns {boolean} true if the toggle is checked, false otherwise\n\t */\n\tget checked() {\n\t\treturn this.hasAttribute('checked');\n\t}\n\n\t/**\n\t * The class name for the Checkbox.\n\t */\n\tclassName = 'Checkbox';\n\n\t/**\n\t * Getter for the CSS stylesheet.\n\t * @returns {string} The CSS stylesheet.\n\t */\n\tstatic get cssStyleSheet() {\n\t\treturn styles;\n\t}\n\n\tstatic get observedAttributes() {\n\t\treturn ['checked', 'disabled', 'value', 'indeterminate'];\n\t}\n\n\tattributeChangedCallback(name, oldValue, newValue) {\n\t\tif (!this.input) return;\n\t\tif (name === 'checked') {\n\t\t\tconst isChecked = this.hasAttribute('checked');\n\t\t\tthis.input.checked = isChecked;\n\t\t\t// Reflect into form value\n\t\t\tif (isChecked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t} else {\n\t\t\t\tthis.internals.setFormValue(null);\n\t\t\t}\n\t\t} else if (name === 'disabled') {\n\t\t\tthis.input.disabled = this.hasAttribute('disabled');\n\t\t} else if (name === 'indeterminate') {\n\t\t\tthis.input.indeterminate = this.hasAttribute('indeterminate');\n\t\t} else if (name === 'value') {\n\t\t\t// keep payload in sync; do not toggle checked here\n\t\t\tthis.#internalValue = newValue ?? undefined;\n\t\t\tthis.input.value = this.value;\n\t\t\t// If currently checked, update the submitted payload\n\t\t\tif (this.input.checked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets up the attributes for the checkbox.\n\t */\n\tsetupAttributes() {\n\t\tthis.isShadowRoot = 'open';\n\t\t// if some value was set via value setter then dont use default value\n\t\tif (this.pristine) {\n\t\t\tthis.value = this.#internalValue;\n\t\t\tthis.pristine = false;\n\t\t}\n\t}\n\n\t/**\n\t * Draws the checkbox element.\n\t * @returns {DocumentFragment} The created fragment.\n\t */\n\tdraw() {\n\t\tlet fragment = document.createDocumentFragment();\n\n\t\tlet native = document.createElement('div');\n\t\tnative.setAttribute('part', 'native');\n\t\tnative.classList.add('native-checkbox');\n\n\t\tlet input = document.createElement('input');\n\t\tinput.type = 'checkbox';\n\t\tinput.id = 'checkbox';\n\t\tinput.name = this.name || 'checkbox';\n\t\tinput.checked = this.checked;\n\t\tinput.disabled = this.disabled;\n\t\tinput.indeterminate = this.indeterminate;\n\t\tinput.required = this.required;\n\t\tinput.value = this.value;\n\n\t\tlet label = document.createElement('label');\n\t\tlabel.htmlFor = 'checkbox';\n\t\tlabel.innerHTML = '<slot></slot>';\n\n\t\t// Error\n\t\tlet errorSlot = document.createElement('slot');\n\t\terrorSlot.setAttribute('name', 'error');\n\n\t\tlet error = document.createElement('div');\n\t\terror.setAttribute('slot', 'error');\n\n\t\t// APPEND\n\t\tnative.append(input);\n\t\tnative.append(label);\n\t\tnative.append(errorSlot);\n\n\t\tthis.append(error);\n\n\t\tthis.input = input;\n\n\t\tfragment.appendChild(native);\n\n\t\treturn fragment;\n\t}\n\n\t/**\n\t * Adds an event listener after drawing the checkbox.\n\t */\n\tafterDraw() {\n\t\tthis.internals.setFormValue(this.checked ? this.value : null); // Set initial form value based on checked state\n\n\t\tif (!this.disabled) {\n\t\t\tthis.input.addEventListener('input', (e) => {\n\t\t\t\tthis.validate();\n\n\t\t\t\tthis.pristine = false;\n\t\t\t\tthis.propagateValidation();\n\n\t\t\t\t// User interaction decides the checked state; value stays as payload\n\t\t\t\tthis.indeterminate = false;\n\t\t\t\tthis.checked = e.target.checked;\n\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:input');\n\t\t\t});\n\n\t\t\tthis.input.addEventListener('change', (e) => {\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:change');\n\t\t\t});\n\n\t\t\tthis.addEventListener('invalid', (e) => {\n\t\t\t\tthis.invalid = true;\n\t\t\t\tthis.pristine = false;\n\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t});\n\n\t\t\tthis.validate();\n\n\t\t\tif (this.invalid) {\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the event listener when the checkbox is disconnected.\n\t */\n\tbeforeDisconnect() {\n\t\tevent.removeElement(this.input);\n\t}\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Checkbox from './checkbox.element.js';\n\n// export *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