selective-ui 1.0.2 → 1.0.4
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/LICENSE +21 -21
- package/README.md +7 -2
- package/dist/selective-ui.css +567 -567
- package/dist/selective-ui.css.map +1 -1
- package/dist/selective-ui.esm.js +6186 -6047
- package/dist/selective-ui.esm.js.map +1 -1
- package/dist/selective-ui.esm.min.js +1 -1
- package/dist/selective-ui.esm.min.js.br +0 -0
- package/dist/selective-ui.min.js +2 -2
- package/dist/selective-ui.min.js.br +0 -0
- package/dist/selective-ui.umd.js +6186 -6047
- package/dist/selective-ui.umd.js.map +1 -1
- package/package.json +68 -68
- package/src/css/components/accessorybox.css +63 -63
- package/src/css/components/directive.css +19 -19
- package/src/css/components/empty-state.css +25 -25
- package/src/css/components/loading-state.css +25 -25
- package/src/css/components/optgroup.css +61 -61
- package/src/css/components/option-handle.css +33 -33
- package/src/css/components/option.css +129 -129
- package/src/css/components/placeholder.css +14 -14
- package/src/css/components/popup.css +38 -38
- package/src/css/components/searchbox.css +28 -28
- package/src/css/components/selectbox.css +53 -53
- package/src/css/index.css +74 -74
- package/src/js/adapter/mixed-adapter.js +434 -434
- package/src/js/components/accessorybox.js +124 -124
- package/src/js/components/directive.js +37 -37
- package/src/js/components/empty-state.js +67 -67
- package/src/js/components/loading-state.js +59 -59
- package/src/js/components/option-handle.js +113 -113
- package/src/js/components/placeholder.js +56 -56
- package/src/js/components/popup.js +470 -470
- package/src/js/components/searchbox.js +167 -167
- package/src/js/components/selectbox.js +749 -692
- package/src/js/core/base/adapter.js +162 -162
- package/src/js/core/base/model.js +59 -59
- package/src/js/core/base/recyclerview.js +82 -82
- package/src/js/core/base/view.js +62 -62
- package/src/js/core/model-manager.js +286 -286
- package/src/js/core/search-controller.js +603 -521
- package/src/js/index.js +136 -136
- package/src/js/models/group-model.js +142 -142
- package/src/js/models/option-model.js +236 -236
- package/src/js/services/dataset-observer.js +73 -73
- package/src/js/services/ea-observer.js +87 -87
- package/src/js/services/effector.js +403 -403
- package/src/js/services/refresher.js +39 -39
- package/src/js/services/resize-observer.js +151 -151
- package/src/js/services/select-observer.js +60 -60
- package/src/js/types/adapter.type.js +32 -32
- package/src/js/types/effector.type.js +23 -23
- package/src/js/types/ievents.type.js +10 -10
- package/src/js/types/libs.type.js +27 -27
- package/src/js/types/model.type.js +11 -11
- package/src/js/types/recyclerview.type.js +11 -11
- package/src/js/types/resize-observer.type.js +18 -18
- package/src/js/types/view.group.type.js +12 -12
- package/src/js/types/view.option.type.js +14 -14
- package/src/js/types/view.type.js +10 -10
- package/src/js/utils/guard.js +46 -46
- package/src/js/utils/ievents.js +83 -83
- package/src/js/utils/istorage.js +60 -60
- package/src/js/utils/libs.js +618 -618
- package/src/js/utils/selective.js +385 -385
- package/src/js/views/group-view.js +102 -102
- package/src/js/views/option-view.js +152 -152
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import { ModelManager } from "../core/model-manager";
|
|
2
|
-
import { OptionModel } from "../models/option-model";
|
|
3
|
-
import { iEvents } from "../utils/ievents";
|
|
4
|
-
import { Libs } from "../utils/libs";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
export class AccessoryBox {
|
|
10
|
-
/**
|
|
11
|
-
* @type {MountViewResult<any>}
|
|
12
|
-
*/
|
|
13
|
-
nodeMounted = null;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @type {HTMLDivElement}
|
|
17
|
-
*/
|
|
18
|
-
node = null;
|
|
19
|
-
|
|
20
|
-
options = null;
|
|
21
|
-
|
|
22
|
-
/** @type {HTMLDivElement} */
|
|
23
|
-
selectUIMask;
|
|
24
|
-
|
|
25
|
-
/** @type {HTMLDivElement} */
|
|
26
|
-
parentMask;
|
|
27
|
-
|
|
28
|
-
/** @type {ModelManager} */
|
|
29
|
-
modelManager;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Initializes the accessory box with optional configuration and immediately calls init() if provided.
|
|
33
|
-
*
|
|
34
|
-
* @param {object|null} options - Configuration options for the accessory box (e.g., layout and behavior).
|
|
35
|
-
*/
|
|
36
|
-
constructor(options = null) {
|
|
37
|
-
options && this.init(options);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Creates the accessory box DOM node and stores the provided options.
|
|
42
|
-
* The node is initially hidden and stops mouseup events from bubbling.
|
|
43
|
-
*
|
|
44
|
-
* @param {object} options - Configuration object for the accessory box.
|
|
45
|
-
*/
|
|
46
|
-
init(options) {
|
|
47
|
-
this.nodeMounted = Libs.mountNode({
|
|
48
|
-
AccessoryBox: {
|
|
49
|
-
tag: {node: "div", classList: ["selective-ui-accessorybox", "hide"], onmouseup: (evt) => {
|
|
50
|
-
evt.stopPropagation();
|
|
51
|
-
}}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this.node = /** @type {HTMLDivElement} */ (this.nodeMounted.view);
|
|
55
|
-
this.options = options;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Sets the root references for the accessory box (mask elements) and refreshes its location in the DOM.
|
|
60
|
-
*
|
|
61
|
-
* @param {HTMLDivElement} selectUIMask - The overlay/mask element of the main Select UI.
|
|
62
|
-
*/
|
|
63
|
-
setRoot(selectUIMask) {
|
|
64
|
-
this.selectUIMask = selectUIMask;
|
|
65
|
-
this.parentMask = /** @type {HTMLDivElement} */ (selectUIMask.parentElement);
|
|
66
|
-
|
|
67
|
-
this.refreshLocation();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Inserts the accessory box before or after the Select UI mask depending on the configured accessoryStyle.
|
|
72
|
-
* Keeps the accessory box aligned relative to the parent mask.
|
|
73
|
-
*/
|
|
74
|
-
refreshLocation() {
|
|
75
|
-
this.parentMask.insertBefore(this.node, (this.options.accessoryStyle == "top" ? this.selectUIMask : this.selectUIMask.nextSibling));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Assigns a ModelManager instance used to trigger and manage selection state changes.
|
|
80
|
-
*
|
|
81
|
-
* @param {ModelManager} modelManager - The model manager controlling option state.
|
|
82
|
-
*/
|
|
83
|
-
setModelManager(modelManager) {
|
|
84
|
-
this.modelManager = modelManager;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Renders accessory items for the currently selected options in multiple-select mode.
|
|
89
|
-
* Shows the accessory box when there are items; otherwise hides it. Triggers a window resize event.
|
|
90
|
-
*
|
|
91
|
-
* @param {OptionModel[]} modelDatas - List of option models to render as accessory items.
|
|
92
|
-
*/
|
|
93
|
-
setModelData(modelDatas) {
|
|
94
|
-
this.node.replaceChildren();
|
|
95
|
-
|
|
96
|
-
if (modelDatas.length > 0 && this.options.multiple) {
|
|
97
|
-
this.node.classList.remove("hide");
|
|
98
|
-
|
|
99
|
-
modelDatas.forEach(modelData => {
|
|
100
|
-
Libs.mountNode({
|
|
101
|
-
AccessoryItem: {
|
|
102
|
-
tag: {node: "div", classList: ["accessory-item"]},
|
|
103
|
-
child: {
|
|
104
|
-
Button: {
|
|
105
|
-
tag: {node: "span", classList: ["accessory-item-button"], role: "button", ariaLabel: `${this.options.textAccessoryDeselect}${modelData.textContent}`, title: `${this.options.textAccessoryDeselect}${modelData.textContent}`, onclick: (evt) => {
|
|
106
|
-
this.modelManager.triggerChanging("select");
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
modelData.selected = false;
|
|
109
|
-
}, 10);
|
|
110
|
-
}}
|
|
111
|
-
},
|
|
112
|
-
Content: {
|
|
113
|
-
tag: {node: "span", classList: ["accessory-item-content"], innerHTML: modelData.text}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, this.node);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
this.node.classList.add("hide");
|
|
122
|
-
}
|
|
123
|
-
iEvents.trigger(window, "resize");
|
|
124
|
-
}
|
|
1
|
+
import { ModelManager } from "../core/model-manager";
|
|
2
|
+
import { OptionModel } from "../models/option-model";
|
|
3
|
+
import { iEvents } from "../utils/ievents";
|
|
4
|
+
import { Libs } from "../utils/libs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
export class AccessoryBox {
|
|
10
|
+
/**
|
|
11
|
+
* @type {MountViewResult<any>}
|
|
12
|
+
*/
|
|
13
|
+
nodeMounted = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {HTMLDivElement}
|
|
17
|
+
*/
|
|
18
|
+
node = null;
|
|
19
|
+
|
|
20
|
+
options = null;
|
|
21
|
+
|
|
22
|
+
/** @type {HTMLDivElement} */
|
|
23
|
+
selectUIMask;
|
|
24
|
+
|
|
25
|
+
/** @type {HTMLDivElement} */
|
|
26
|
+
parentMask;
|
|
27
|
+
|
|
28
|
+
/** @type {ModelManager} */
|
|
29
|
+
modelManager;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Initializes the accessory box with optional configuration and immediately calls init() if provided.
|
|
33
|
+
*
|
|
34
|
+
* @param {object|null} options - Configuration options for the accessory box (e.g., layout and behavior).
|
|
35
|
+
*/
|
|
36
|
+
constructor(options = null) {
|
|
37
|
+
options && this.init(options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates the accessory box DOM node and stores the provided options.
|
|
42
|
+
* The node is initially hidden and stops mouseup events from bubbling.
|
|
43
|
+
*
|
|
44
|
+
* @param {object} options - Configuration object for the accessory box.
|
|
45
|
+
*/
|
|
46
|
+
init(options) {
|
|
47
|
+
this.nodeMounted = Libs.mountNode({
|
|
48
|
+
AccessoryBox: {
|
|
49
|
+
tag: {node: "div", classList: ["selective-ui-accessorybox", "hide"], onmouseup: (evt) => {
|
|
50
|
+
evt.stopPropagation();
|
|
51
|
+
}}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.node = /** @type {HTMLDivElement} */ (this.nodeMounted.view);
|
|
55
|
+
this.options = options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sets the root references for the accessory box (mask elements) and refreshes its location in the DOM.
|
|
60
|
+
*
|
|
61
|
+
* @param {HTMLDivElement} selectUIMask - The overlay/mask element of the main Select UI.
|
|
62
|
+
*/
|
|
63
|
+
setRoot(selectUIMask) {
|
|
64
|
+
this.selectUIMask = selectUIMask;
|
|
65
|
+
this.parentMask = /** @type {HTMLDivElement} */ (selectUIMask.parentElement);
|
|
66
|
+
|
|
67
|
+
this.refreshLocation();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Inserts the accessory box before or after the Select UI mask depending on the configured accessoryStyle.
|
|
72
|
+
* Keeps the accessory box aligned relative to the parent mask.
|
|
73
|
+
*/
|
|
74
|
+
refreshLocation() {
|
|
75
|
+
this.parentMask.insertBefore(this.node, (this.options.accessoryStyle == "top" ? this.selectUIMask : this.selectUIMask.nextSibling));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Assigns a ModelManager instance used to trigger and manage selection state changes.
|
|
80
|
+
*
|
|
81
|
+
* @param {ModelManager} modelManager - The model manager controlling option state.
|
|
82
|
+
*/
|
|
83
|
+
setModelManager(modelManager) {
|
|
84
|
+
this.modelManager = modelManager;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Renders accessory items for the currently selected options in multiple-select mode.
|
|
89
|
+
* Shows the accessory box when there are items; otherwise hides it. Triggers a window resize event.
|
|
90
|
+
*
|
|
91
|
+
* @param {OptionModel[]} modelDatas - List of option models to render as accessory items.
|
|
92
|
+
*/
|
|
93
|
+
setModelData(modelDatas) {
|
|
94
|
+
this.node.replaceChildren();
|
|
95
|
+
|
|
96
|
+
if (modelDatas.length > 0 && this.options.multiple) {
|
|
97
|
+
this.node.classList.remove("hide");
|
|
98
|
+
|
|
99
|
+
modelDatas.forEach(modelData => {
|
|
100
|
+
Libs.mountNode({
|
|
101
|
+
AccessoryItem: {
|
|
102
|
+
tag: {node: "div", classList: ["accessory-item"]},
|
|
103
|
+
child: {
|
|
104
|
+
Button: {
|
|
105
|
+
tag: {node: "span", classList: ["accessory-item-button"], role: "button", ariaLabel: `${this.options.textAccessoryDeselect}${modelData.textContent}`, title: `${this.options.textAccessoryDeselect}${modelData.textContent}`, onclick: (evt) => {
|
|
106
|
+
this.modelManager.triggerChanging("select");
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
modelData.selected = false;
|
|
109
|
+
}, 10);
|
|
110
|
+
}}
|
|
111
|
+
},
|
|
112
|
+
Content: {
|
|
113
|
+
tag: {node: "span", classList: ["accessory-item-content"], innerHTML: modelData.text}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, this.node);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.node.classList.add("hide");
|
|
122
|
+
}
|
|
123
|
+
iEvents.trigger(window, "resize");
|
|
124
|
+
}
|
|
125
125
|
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {Libs} from "../utils/libs.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @class
|
|
5
|
-
*/
|
|
6
|
-
export class Directive {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.#init();
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @type {Element}
|
|
12
|
-
*/
|
|
13
|
-
node = null;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents a directive button element used to toggle dropdown state.
|
|
17
|
-
* Initializes a clickable node with appropriate ARIA attributes for accessibility.
|
|
18
|
-
*/
|
|
19
|
-
#init() {
|
|
20
|
-
this.node = Libs.nodeCreator({
|
|
21
|
-
node: "div", classList: "selective-ui-directive", role: "button", ariaLabel: "Toggle dropdown"
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Sets the dropdown state by toggling the "drop-down" CSS class on the directive node.
|
|
27
|
-
*
|
|
28
|
-
* @param {boolean} value - If true, adds the "drop-down" class; otherwise removes it.
|
|
29
|
-
*/
|
|
30
|
-
setDropdown(value) {
|
|
31
|
-
if (value) {
|
|
32
|
-
this.node.classList.add("drop-down");
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.node.classList.remove("drop-down");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
import {Libs} from "../utils/libs.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export class Directive {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.#init();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @type {Element}
|
|
12
|
+
*/
|
|
13
|
+
node = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents a directive button element used to toggle dropdown state.
|
|
17
|
+
* Initializes a clickable node with appropriate ARIA attributes for accessibility.
|
|
18
|
+
*/
|
|
19
|
+
#init() {
|
|
20
|
+
this.node = Libs.nodeCreator({
|
|
21
|
+
node: "div", classList: "selective-ui-directive", role: "button", ariaLabel: "Toggle dropdown"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sets the dropdown state by toggling the "drop-down" CSS class on the directive node.
|
|
27
|
+
*
|
|
28
|
+
* @param {boolean} value - If true, adds the "drop-down" class; otherwise removes it.
|
|
29
|
+
*/
|
|
30
|
+
setDropdown(value) {
|
|
31
|
+
if (value) {
|
|
32
|
+
this.node.classList.add("drop-down");
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.node.classList.remove("drop-down");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
38
|
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import {Libs} from "../utils/libs.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @class
|
|
5
|
-
*/
|
|
6
|
-
export class EmptyState {
|
|
7
|
-
/**
|
|
8
|
-
* @type {HTMLDivElement}
|
|
9
|
-
*/
|
|
10
|
-
node = null;
|
|
11
|
-
|
|
12
|
-
options = null;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Represents an empty state component that displays a message when no data or search results are available.
|
|
16
|
-
* Provides methods to show/hide the state and check its visibility.
|
|
17
|
-
*/
|
|
18
|
-
constructor(options = null) {
|
|
19
|
-
options && this.init(options);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Initializes the empty state element with ARIA attributes for accessibility and stores configuration options.
|
|
24
|
-
*
|
|
25
|
-
* @param {object} options - Configuration object containing text for "no data" and "not found" states.
|
|
26
|
-
*/
|
|
27
|
-
init(options) {
|
|
28
|
-
this.options = options;
|
|
29
|
-
|
|
30
|
-
this.node = /** @type {HTMLDivElement} */ (Libs.nodeCreator({
|
|
31
|
-
node: "div",
|
|
32
|
-
classList: ["selective-ui-empty-state", "hide"],
|
|
33
|
-
role: "status",
|
|
34
|
-
ariaLive: "polite"
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Displays the empty state message based on the provided type.
|
|
40
|
-
*
|
|
41
|
-
* @param {"notfound" | "nodata"} [type="nodata"] - Determines which message to show:
|
|
42
|
-
* "notfound" for search results not found, "nodata" for no available data.
|
|
43
|
-
*/
|
|
44
|
-
show(type = "nodata") {
|
|
45
|
-
const text = type === "notfound"
|
|
46
|
-
? this.options.textNotFound
|
|
47
|
-
: this.options.textNoData;
|
|
48
|
-
|
|
49
|
-
this.node.textContent = text;
|
|
50
|
-
this.node.classList.remove("hide");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Hides the empty state element by adding the "hide" class.
|
|
55
|
-
*/
|
|
56
|
-
hide() {
|
|
57
|
-
this.node.classList.add("hide");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Indicates whether the empty state is currently visible.
|
|
62
|
-
*
|
|
63
|
-
* @returns {boolean} - True if visible, false otherwise.
|
|
64
|
-
*/
|
|
65
|
-
get isVisible() {
|
|
66
|
-
return !this.node.classList.contains("hide");
|
|
67
|
-
}
|
|
1
|
+
import {Libs} from "../utils/libs.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export class EmptyState {
|
|
7
|
+
/**
|
|
8
|
+
* @type {HTMLDivElement}
|
|
9
|
+
*/
|
|
10
|
+
node = null;
|
|
11
|
+
|
|
12
|
+
options = null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents an empty state component that displays a message when no data or search results are available.
|
|
16
|
+
* Provides methods to show/hide the state and check its visibility.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options = null) {
|
|
19
|
+
options && this.init(options);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the empty state element with ARIA attributes for accessibility and stores configuration options.
|
|
24
|
+
*
|
|
25
|
+
* @param {object} options - Configuration object containing text for "no data" and "not found" states.
|
|
26
|
+
*/
|
|
27
|
+
init(options) {
|
|
28
|
+
this.options = options;
|
|
29
|
+
|
|
30
|
+
this.node = /** @type {HTMLDivElement} */ (Libs.nodeCreator({
|
|
31
|
+
node: "div",
|
|
32
|
+
classList: ["selective-ui-empty-state", "hide"],
|
|
33
|
+
role: "status",
|
|
34
|
+
ariaLive: "polite"
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Displays the empty state message based on the provided type.
|
|
40
|
+
*
|
|
41
|
+
* @param {"notfound" | "nodata"} [type="nodata"] - Determines which message to show:
|
|
42
|
+
* "notfound" for search results not found, "nodata" for no available data.
|
|
43
|
+
*/
|
|
44
|
+
show(type = "nodata") {
|
|
45
|
+
const text = type === "notfound"
|
|
46
|
+
? this.options.textNotFound
|
|
47
|
+
: this.options.textNoData;
|
|
48
|
+
|
|
49
|
+
this.node.textContent = text;
|
|
50
|
+
this.node.classList.remove("hide");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Hides the empty state element by adding the "hide" class.
|
|
55
|
+
*/
|
|
56
|
+
hide() {
|
|
57
|
+
this.node.classList.add("hide");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Indicates whether the empty state is currently visible.
|
|
62
|
+
*
|
|
63
|
+
* @returns {boolean} - True if visible, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
get isVisible() {
|
|
66
|
+
return !this.node.classList.contains("hide");
|
|
67
|
+
}
|
|
68
68
|
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { Libs } from "../utils/libs";
|
|
2
|
-
|
|
3
|
-
export class LoadingState {
|
|
4
|
-
|
|
5
|
-
/** @type {HTMLDivElement} */
|
|
6
|
-
node = null;
|
|
7
|
-
|
|
8
|
-
options = null;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents a loading state component that displays a loading message during data fetch or processing.
|
|
12
|
-
* Provides methods to show/hide the state and check its visibility.
|
|
13
|
-
*/
|
|
14
|
-
constructor(options = null) {
|
|
15
|
-
options && this.init(options);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Initializes the loading state element with ARIA attributes for accessibility and stores configuration options.
|
|
20
|
-
*
|
|
21
|
-
* @param {object} options - Configuration object containing text for the loading message.
|
|
22
|
-
*/
|
|
23
|
-
init(options) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.node = /** @type {HTMLDivElement} */(Libs.nodeCreator({
|
|
26
|
-
node: "div",
|
|
27
|
-
classList: ["selective-ui-loading-state", "hide"],
|
|
28
|
-
textContent: options.textLoading,
|
|
29
|
-
role: "status",
|
|
30
|
-
ariaLive: "polite"
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Displays the loading state message and adjusts its size based on whether items are present.
|
|
36
|
-
*
|
|
37
|
-
* @param {boolean} hasItems - If true, applies a "small" style for compact display.
|
|
38
|
-
*/
|
|
39
|
-
show(hasItems) {
|
|
40
|
-
this.node.textContent = this.options.textLoading;
|
|
41
|
-
this.node.classList.toggle("small", hasItems);
|
|
42
|
-
this.node.classList.remove("hide");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Hides the loading state element by adding the "hide" class.
|
|
47
|
-
*/
|
|
48
|
-
hide() {
|
|
49
|
-
this.node.classList.add("hide");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Indicates whether the loading state is currently visible.
|
|
54
|
-
*
|
|
55
|
-
* @returns {boolean} - True if visible, false otherwise.
|
|
56
|
-
*/
|
|
57
|
-
get isVisible() {
|
|
58
|
-
return !this.node.classList.contains("hide");
|
|
59
|
-
}
|
|
1
|
+
import { Libs } from "../utils/libs";
|
|
2
|
+
|
|
3
|
+
export class LoadingState {
|
|
4
|
+
|
|
5
|
+
/** @type {HTMLDivElement} */
|
|
6
|
+
node = null;
|
|
7
|
+
|
|
8
|
+
options = null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents a loading state component that displays a loading message during data fetch or processing.
|
|
12
|
+
* Provides methods to show/hide the state and check its visibility.
|
|
13
|
+
*/
|
|
14
|
+
constructor(options = null) {
|
|
15
|
+
options && this.init(options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the loading state element with ARIA attributes for accessibility and stores configuration options.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} options - Configuration object containing text for the loading message.
|
|
22
|
+
*/
|
|
23
|
+
init(options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.node = /** @type {HTMLDivElement} */(Libs.nodeCreator({
|
|
26
|
+
node: "div",
|
|
27
|
+
classList: ["selective-ui-loading-state", "hide"],
|
|
28
|
+
textContent: options.textLoading,
|
|
29
|
+
role: "status",
|
|
30
|
+
ariaLive: "polite"
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Displays the loading state message and adjusts its size based on whether items are present.
|
|
36
|
+
*
|
|
37
|
+
* @param {boolean} hasItems - If true, applies a "small" style for compact display.
|
|
38
|
+
*/
|
|
39
|
+
show(hasItems) {
|
|
40
|
+
this.node.textContent = this.options.textLoading;
|
|
41
|
+
this.node.classList.toggle("small", hasItems);
|
|
42
|
+
this.node.classList.remove("hide");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Hides the loading state element by adding the "hide" class.
|
|
47
|
+
*/
|
|
48
|
+
hide() {
|
|
49
|
+
this.node.classList.add("hide");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Indicates whether the loading state is currently visible.
|
|
54
|
+
*
|
|
55
|
+
* @returns {boolean} - True if visible, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
get isVisible() {
|
|
58
|
+
return !this.node.classList.contains("hide");
|
|
59
|
+
}
|
|
60
60
|
}
|