chuijs 3.6.2 → 3.6.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.
Files changed (119) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1203 -162
  3. package/framework/appLayout/default/chui_app_layout.js +747 -747
  4. package/framework/appLayout/default/global_style.css +592 -568
  5. package/framework/appLayout/default/main_theme_style.css +118 -101
  6. package/framework/components/chui_accordion/accordion.js +63 -63
  7. package/framework/components/chui_accordion/styles.css +79 -75
  8. package/framework/components/chui_badge/badge.js +55 -55
  9. package/framework/components/chui_badge/styles.css +29 -29
  10. package/framework/components/chui_button/button.js +48 -48
  11. package/framework/components/chui_button/styles.css +75 -70
  12. package/framework/components/chui_calendar/calendar.js +97 -97
  13. package/framework/components/chui_card/card.js +87 -0
  14. package/framework/components/chui_card/styles.css +72 -0
  15. package/framework/components/chui_code/code.js +18 -18
  16. package/framework/components/chui_code/styles.css +9 -9
  17. package/framework/components/chui_console/console.js +27 -27
  18. package/framework/components/chui_console/styles.css +31 -31
  19. package/framework/components/chui_content_block/content_block.js +51 -51
  20. package/framework/components/chui_content_block/styles.css +2 -2
  21. package/framework/components/chui_context_menu/context_menu.js +230 -0
  22. package/framework/components/chui_context_menu/styles.css +136 -0
  23. package/framework/components/chui_custom_element/custom_element.js +24 -24
  24. package/framework/components/chui_details/details.js +85 -85
  25. package/framework/components/chui_details/styles.css +70 -66
  26. package/framework/components/chui_fieldset/fieldset.js +40 -40
  27. package/framework/components/chui_fieldset/styles.css +24 -24
  28. package/framework/components/chui_form/form.js +40 -40
  29. package/framework/components/chui_form/styles.css +21 -21
  30. package/framework/components/chui_graphs/graphs.js +234 -190
  31. package/framework/components/chui_graphs/styles.css +37 -32
  32. package/framework/components/chui_hero/hero.js +98 -0
  33. package/framework/components/chui_hero/styles.css +91 -0
  34. package/framework/components/chui_html_block/html_block.js +16 -16
  35. package/framework/components/chui_html_block/styles.css +5 -5
  36. package/framework/components/chui_hx/hx.js +15 -15
  37. package/framework/components/chui_hx/styles.css +38 -38
  38. package/framework/components/chui_icons/icons.js +2144 -2144
  39. package/framework/components/chui_icons/styles.css +13 -13
  40. package/framework/components/chui_inputs/chui_check_box/check_box.js +32 -32
  41. package/framework/components/chui_inputs/chui_check_box/styles.css +91 -86
  42. package/framework/components/chui_inputs/chui_combo_box/combo_box.js +166 -150
  43. package/framework/components/chui_inputs/chui_combo_box/styles.css +113 -107
  44. package/framework/components/chui_inputs/chui_date/date.js +177 -174
  45. package/framework/components/chui_inputs/chui_date/styles.css +163 -128
  46. package/framework/components/chui_inputs/chui_email/email.js +61 -61
  47. package/framework/components/chui_inputs/chui_email/styles.css +69 -71
  48. package/framework/components/chui_inputs/chui_file/file.js +76 -76
  49. package/framework/components/chui_inputs/chui_file/styles.css +99 -99
  50. package/framework/components/chui_inputs/chui_multi_combo_box/multi_combo_box.js +295 -295
  51. package/framework/components/chui_inputs/chui_multi_combo_box/styles.css +212 -235
  52. package/framework/components/chui_inputs/chui_number/number.js +108 -108
  53. package/framework/components/chui_inputs/chui_number/styles.css +84 -84
  54. package/framework/components/chui_inputs/chui_password/password.js +99 -99
  55. package/framework/components/chui_inputs/chui_password/styles.css +97 -97
  56. package/framework/components/chui_inputs/chui_radio_button/radio_button.js +45 -45
  57. package/framework/components/chui_inputs/chui_radio_button/styles.css +76 -73
  58. package/framework/components/chui_inputs/chui_select_box/select_box.js +187 -170
  59. package/framework/components/chui_inputs/chui_select_box/styles.css +123 -117
  60. package/framework/components/chui_inputs/chui_text/styles.css +83 -84
  61. package/framework/components/chui_inputs/chui_text/text.js +91 -91
  62. package/framework/components/chui_inputs/chui_text_area/styles.css +57 -57
  63. package/framework/components/chui_inputs/chui_text_area/text_area.js +61 -61
  64. package/framework/components/chui_inputs/chui_toggle/styles.css +66 -61
  65. package/framework/components/chui_inputs/chui_toggle/toggle.js +36 -36
  66. package/framework/components/chui_label/label.js +54 -54
  67. package/framework/components/chui_label/styles.css +11 -11
  68. package/framework/components/chui_media/audio.js +908 -908
  69. package/framework/components/chui_media/audio_styles.css +458 -458
  70. package/framework/components/chui_media/image.js +105 -105
  71. package/framework/components/chui_media/image_styles.css +61 -61
  72. package/framework/components/chui_media/video.js +248 -248
  73. package/framework/components/chui_media/video_styles.css +160 -160
  74. package/framework/components/chui_menu_bar/menu_bar.js +66 -74
  75. package/framework/components/chui_menu_bar/styles.css +114 -76
  76. package/framework/components/chui_modal/modal.js +142 -135
  77. package/framework/components/chui_modal/styles.css +36 -36
  78. package/framework/components/chui_notification/notification.js +72 -72
  79. package/framework/components/chui_notification/notification_download.js +78 -78
  80. package/framework/components/chui_notification/notification_download_progress.css +119 -123
  81. package/framework/components/chui_notification/notification_download_progress.js +105 -105
  82. package/framework/components/chui_notification/notification_update.js +54 -54
  83. package/framework/components/chui_notification/styles.css +91 -91
  84. package/framework/components/chui_notification/styles_download.css +85 -85
  85. package/framework/components/chui_notification/styles_update.css +73 -73
  86. package/framework/components/chui_paragraph/paragraph.js +14 -14
  87. package/framework/components/chui_paragraph/styles.css +6 -6
  88. package/framework/components/chui_popups/popups.js +250 -250
  89. package/framework/components/chui_popups/styles.css +129 -115
  90. package/framework/components/chui_progress_bar/progress_bar.js +28 -28
  91. package/framework/components/chui_progress_bar/styles.css +28 -28
  92. package/framework/components/chui_radio_group/radio_group.js +57 -57
  93. package/framework/components/chui_radio_group/styles.css +3 -3
  94. package/framework/components/chui_slideshow/slideshow.js +75 -75
  95. package/framework/components/chui_slideshow/styles.css +94 -85
  96. package/framework/components/chui_spinner/spinner.js +45 -45
  97. package/framework/components/chui_spinner/styles.css +23 -23
  98. package/framework/components/chui_table/styles.css +42 -42
  99. package/framework/components/chui_table/table.js +234 -234
  100. package/framework/components/chui_tabs/chui_tabs.js +77 -77
  101. package/framework/components/chui_tabs/styles.css +54 -48
  102. package/framework/components/chui_text_editor/styles.css +217 -217
  103. package/framework/components/chui_text_editor/text_editor.js +144 -144
  104. package/framework/components/chui_text_editor/text_editor_panel.js +568 -568
  105. package/framework/components/chui_tree_view/styles.css +81 -75
  106. package/framework/components/chui_tree_view/tree_view.js +90 -90
  107. package/framework/components/chui_webview/styles.css +27 -27
  108. package/framework/components/chui_webview/webview.js +103 -103
  109. package/framework/components/telegram_bot/chui_telegram_bot.js +183 -183
  110. package/framework/modules/chui_animations/animations.js +121 -121
  111. package/framework/modules/chui_animations/styles.css +79 -79
  112. package/framework/modules/chui_fonts.js +7129 -6974
  113. package/framework/modules/chui_functions.js +106 -78
  114. package/framework/modules/chui_logger/chui_logger.js +53 -53
  115. package/framework/modules/chui_page/page.js +86 -86
  116. package/framework/modules/chui_page/styles.css +9 -9
  117. package/framework/tray_bar/chui_menu_items.js +48 -48
  118. package/index.js +570 -555
  119. package/package.json +51 -46
@@ -1,14 +1,14 @@
1
- chui_icon {
2
- font-family: 'chui_mir';
3
- font-weight: normal;
4
- font-style: normal;
5
- font-size: var(--header_icon_size);
6
- display: inherit;
7
- text-transform: none;
8
- word-wrap: normal;
9
- white-space: nowrap;
10
- direction: ltr;
11
- color: var(--text_color);
12
- pointer-events: none;
13
- transition: all var(--transition_time);
1
+ chui_icon {
2
+ font-family: 'chui_mir';
3
+ font-weight: normal;
4
+ font-style: normal;
5
+ font-size: var(--header_icon_size);
6
+ display: inherit;
7
+ text-transform: none;
8
+ word-wrap: normal;
9
+ white-space: nowrap;
10
+ direction: ltr;
11
+ color: var(--text_color);
12
+ pointer-events: none;
13
+ transition: all var(--transition_time);
14
14
  }
@@ -1,33 +1,33 @@
1
- class CheckBox {
2
- #id = require("randomstring").generate();
3
- #checkBox = document.createElement('checkbox');
4
- #input = document.createElement('input');
5
- #label = document.createElement('label');
6
- constructor(options = { name: String(), title: String(), required: Boolean(), changeListener: () => {} }) {
7
- require('../../../modules/chui_functions').setStyles(__dirname + "/styles.css", 'chUiJS_Checkbox');
8
- this.#input.classList.add('checkbox');
9
- this.#input.type = 'checkbox';
10
- this.#input.classList.add('checkbox_input');
11
- this.#input.id = this.#id;
12
- this.#label.setAttribute('for', this.#id);
13
- this.#label.classList.add('labelz')
14
- // Установка опций
15
- if (options.name !== undefined) this.#input.name = options.name;
16
- if (options.title !== undefined) this.#label.innerText = options.title;
17
- if (options.required !== undefined) this.#input.required = options.required;
18
- if (options.changeListener !== undefined) this.#input.addEventListener('change', options.changeListener);
19
- }
20
- getName() { return this.#input.name; }
21
- getValue() { return this.#input.checked; }
22
- getTitle() { return this.#label.innerText; }
23
- setValue(value = Boolean()) { this.#input.checked = value; }
24
- addChangeListener(listener = () => {}) { this.#input.addEventListener('change', listener); }
25
- setDisabled(boolean = Boolean()) { this.#input.disabled = boolean; }
26
- set() {
27
- this.#checkBox.appendChild(this.#input);
28
- this.#checkBox.appendChild(this.#label);
29
- return this.#checkBox;
30
- }
31
- }
32
-
1
+ class CheckBox {
2
+ #id = require("randomstring").generate();
3
+ #checkBox = document.createElement('checkbox');
4
+ #input = document.createElement('input');
5
+ #label = document.createElement('label');
6
+ constructor(options = { name: String(), title: String(), required: Boolean(), changeListener: () => {} }) {
7
+ require('../../../modules/chui_functions').setStyles(__dirname + "/styles.css", 'chUiJS_Checkbox');
8
+ this.#input.classList.add('checkbox');
9
+ this.#input.type = 'checkbox';
10
+ this.#input.classList.add('checkbox_input');
11
+ this.#input.id = this.#id;
12
+ this.#label.setAttribute('for', this.#id);
13
+ this.#label.classList.add('labelz')
14
+ // Установка опций
15
+ if (options.name !== undefined) this.#input.name = options.name;
16
+ if (options.title !== undefined) this.#label.innerText = options.title;
17
+ if (options.required !== undefined) this.#input.required = options.required;
18
+ if (options.changeListener !== undefined) this.#input.addEventListener('change', options.changeListener);
19
+ }
20
+ getName() { return this.#input.name; }
21
+ getValue() { return this.#input.checked; }
22
+ getTitle() { return this.#label.innerText; }
23
+ setValue(value = Boolean()) { this.#input.checked = value; }
24
+ addChangeListener(listener = () => {}) { this.#input.addEventListener('change', listener); }
25
+ setDisabled(boolean = Boolean()) { this.#input.disabled = boolean; }
26
+ set() {
27
+ this.#checkBox.appendChild(this.#input);
28
+ this.#checkBox.appendChild(this.#label);
29
+ return this.#checkBox;
30
+ }
31
+ }
32
+
33
33
  exports.CheckBox = CheckBox
@@ -1,87 +1,92 @@
1
- checkbox {
2
- display: flex;
3
- align-items: center;
4
- justify-content: center;
5
- font-size: var(--font_default_size);
6
- margin: var(--margin);
7
- width: max-content
8
- }
9
-
10
- .checkbox {
11
- position: absolute;
12
- z-index: -1;
13
- opacity: 0
14
- }
15
-
16
- .checkbox+label {
17
- display: inline-flex;
18
- align-items: center;
19
- color:var(--text_color)
20
- }
21
-
22
- .checkbox+label::before {
23
- font-size: var(--font_default_size);
24
- content: '';
25
- display: flex;
26
- width: 1.2em;
27
- height: 1.2em;
28
- flex-shrink: 0;
29
- flex-grow: 0;
30
- border-radius: 25%;
31
- margin-right: 10px;
32
- align-items: center;
33
- justify-content: center;
34
- color: var(--element_background_2);
35
- font-family: 'chui_Ubuntu', serif;
36
- background: var(--element_background);
37
- border: none;
38
- box-shadow: 0 0 1px 0 var(--element_background_2);
39
- background-repeat: no-repeat;
40
- background-position: center center;
41
- background-size: 50% 50%;
42
- }
43
-
44
- .checkbox:not(:disabled):not(:checked):hover::before {}
45
-
46
- .checkbox:disabled:not(:checked)+label::before {
47
- cursor: not-allowed;
48
- background: var(--element_background_disabled);
49
- border: none;
50
- box-shadow: 0 0 1px 0 var(--element_background_disabled_2);
51
- color: var(--text_color_disabled);
52
- }
53
-
54
- .checkbox:disabled:checked+label::before {
55
- cursor: not-allowed;
56
- color: var(--text_color_disabled);
57
- background: var(--element_background_disabled);
58
- border: none;
59
- box-shadow: 0 0 1px 0 var(--element_background_disabled_2);
60
- }
61
-
62
- .checkbox:not(:disabled):active+label::before {
63
- background-color: var(--blue_prime_background);
64
- color:var(--text_color_disabled);
65
- border: none;
66
- box-shadow: 0 0 1px 0 var(--element_background_disabled_2);
67
- }
68
-
69
- .checkbox:focus+label::before {}
70
-
71
- .checkbox:checked+label::before {
72
- background-color: var(--blue_prime_background);
73
- color:var(--text_color_hover);
74
- border: none;
75
- box-shadow: 0 0 1px 0 var(--blue_prime_background);
76
- background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e");
77
- }
78
-
79
- .labelz {
80
- cursor: pointer;
81
- font-size: var(--font_default_size)
82
- }
83
-
84
- .checkbox:disabled+label {
85
- cursor: not-allowed;
86
- color: var(--text_color_disabled);
1
+ checkbox {
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ font-size: var(--font_default_size);
6
+ margin: var(--margin);
7
+ width: max-content
8
+ }
9
+
10
+ .checkbox {
11
+ position: absolute;
12
+ z-index: -1;
13
+ opacity: 0
14
+ }
15
+
16
+ .checkbox+label {
17
+ display: inline-flex;
18
+ align-items: center;
19
+ color:var(--text_color)
20
+ }
21
+
22
+ .checkbox+label::before {
23
+ font-size: var(--font_default_size);
24
+ content: '';
25
+ display: flex;
26
+ width: 1.2em;
27
+ height: 1.2em;
28
+ flex-shrink: 0;
29
+ flex-grow: 0;
30
+ border-radius: 25%;
31
+ margin-right: 10px;
32
+ align-items: center;
33
+ justify-content: center;
34
+ color: var(--element_background_2);
35
+ font-family: 'chui_I';
36
+ background: var(--element_background);
37
+ border: none;
38
+ box-shadow: 0 0 1px 0 var(--border_color);
39
+ background-repeat: no-repeat;
40
+ background-position: center center;
41
+ background-size: 50% 50%;
42
+ }
43
+
44
+ .checkbox:not(:disabled):not(:checked)+label:hover::before {
45
+ background: var(--element_background_hover);
46
+ }
47
+
48
+ .checkbox:disabled:not(:checked)+label::before {
49
+ cursor: not-allowed;
50
+ background: var(--element_background_disabled);
51
+ border: none;
52
+ box-shadow: 0 0 1px 0 var(--border_color);
53
+ color: var(--text_color_disabled);
54
+ }
55
+
56
+ .checkbox:disabled:checked+label::before {
57
+ cursor: not-allowed;
58
+ color: var(--text_color_disabled);
59
+ background: var(--element_background_disabled);
60
+ border: none;
61
+ box-shadow: 0 0 1px 0 var(--border_color);
62
+ }
63
+
64
+ .checkbox:not(:disabled):active+label::before {
65
+ background-color: var(--blue_prime_background);
66
+ color:var(--text_color_disabled);
67
+ border: none;
68
+ box-shadow: 0 0 1px 0 var(--border_color);
69
+ }
70
+
71
+ .checkbox:focus-visible+label::before {
72
+ outline: var(--focus_outline);
73
+ outline-offset: var(--focus_outline_offset);
74
+ }
75
+
76
+ .checkbox:checked+label::before {
77
+ background-color: var(--blue_prime_background);
78
+ color:var(--text_color_hover);
79
+ border: none;
80
+ box-shadow: 0 0 1px 0 var(--blue_prime_background);
81
+ background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e");
82
+ }
83
+
84
+ .labelz {
85
+ cursor: pointer;
86
+ font-size: var(--font_default_size)
87
+ }
88
+
89
+ .checkbox:disabled+label {
90
+ cursor: not-allowed;
91
+ color: var(--text_color_disabled);
87
92
  }
@@ -1,151 +1,167 @@
1
- const { Animation } = require('../../../modules/chui_animations/animations');
2
- const { Icon, Icons } = require('../../chui_icons/icons');
3
-
4
- class ComboBox {
5
- #id = require("randomstring").generate();
6
- #id_cb = require("randomstring").generate();
7
- #ComboBox_main = document.createElement('chui_combobox');
8
- #ComboBox_second = document.createElement('combobox');
9
- #label = document.createElement('label');
10
- #input = document.createElement('input');
11
- #button_open = document.createElement('combo_button_open');
12
- #button_open_disabled = document.createElement('combo_button_open');
13
- #dropdown = document.createElement('combobox_dropdown');
14
- constructor(options = {
15
- name: String(),
16
- title: String(),
17
- placeholder: String(),
18
- width: String(),
19
- required: Boolean(),
20
- optionsLen: String(),
21
- }) {
22
- require('../../../modules/chui_functions').setStyles(__dirname + "/styles.css", 'chUiJS_ComboBox');
23
- if (options.placeholder !== undefined) this.#input.placeholder = options.placeholder;
24
- if (options.width !== undefined) this.#ComboBox_main.style.width = options.width;
25
- if (options.title !== undefined) {
26
- this.#label.classList.add('combobox_label')
27
- this.#label.innerText = options.title;
28
- this.#label.setAttribute('for', this.#id_cb);
29
- this.#ComboBox_main.appendChild(this.#label);
30
- }
31
- if (options.optionsLen !== undefined) {
32
- this.#dropdown.style.height = (33 * options.optionsLen) + "px";
33
- } else {
34
- this.#dropdown.style.height = "max-content";
35
- }
36
- if (options.name !== undefined) this.#input.name = options.name;
37
- if (options.required !== undefined) this.#input.required = options.required;
38
- this.#input.setAttribute('id', this.#id_cb);
39
- this.#input.style.boxShadow = 'none';
40
- this.#input.classList.add('combobox_input');
41
- this.#input.type = 'text';
42
- this.#input.addEventListener('focus', () => {
43
- this.#ComboBox_second.style.border = '1px solid var(--blue_prime_background)';
44
- this.#label.style.color = 'var(--blue_prime_background)';
45
- })
46
- this.#input.addEventListener('blur', () => {
47
- this.#ComboBox_second.removeAttribute("style");
48
- this.#label.removeAttribute("style");
49
- })
50
- this.#button_open.innerHTML = new Icon(Icons.HARDWARE.KEYBOARD_ARROW_DOWN, undefined, "var(--blue_prime_background)").getHTML();
51
- this.#button_open_disabled.innerHTML = new Icon(Icons.HARDWARE.KEYBOARD_ARROW_DOWN, undefined, "var(--text_color_disabled)").getHTML();
52
- this.#button_open_disabled.style.cursor = "not-allowed";
53
- this.#dropdown.setAttribute('id', this.#id);
54
- this.#ComboBox_second.appendChild(this.#input)
55
- this.#ComboBox_second.appendChild(this.#button_open)
56
- this.#ComboBox_second.appendChild(this.#dropdown)
57
- //LISTENERS
58
- this.#input.addEventListener('focus', () => {
59
- this.#button_open.style.transform = 'rotate(180deg)'
60
- this.#ComboBox_second.style.border = '1px solid var(--blue_prime_background)';
61
- this.#dropdown.style.height = (33 * options.optionsLen) + "px"
62
- })
63
- this.#input.addEventListener('blur', () => {
64
- this.#button_open.style.transform = 'rotate(0deg)'
65
- this.#ComboBox_second.removeAttribute('style')
66
- this.#dropdown.style.height = (33 * options.optionsLen) + "px"
67
- })
68
- this.#ComboBox_second.addEventListener('click', (event) => {
69
- if (!this.#input.disabled) {
70
- if (event.target.parentNode === this.#ComboBox_second) {
71
- this.#input.focus()
72
- new Animation(this.#dropdown).fadeIn();
73
- setOptionDisplay(document.getElementById(this.#id));
74
- }
75
- }
76
- });
77
- window.addEventListener('click', (event) => {
78
- if (event.target.parentNode !== this.#ComboBox_second) {
79
- new Animation(this.#dropdown).fadeOut();
80
- }
81
- });
82
-
83
- this.#input.addEventListener('input', (event) => {
84
- let dropdown = document.getElementById(this.#id);
85
- for (let option of dropdown.childNodes) {
86
- if (!option.getAttribute('option_title').toLowerCase().includes(event.target.value.toLowerCase())) {
87
- option.style.display = 'none'
88
- dropdown.style.height = 'max-content'
89
- } else {
90
- option.style.display = 'block'
91
- dropdown.style.height = (33 * options.optionsLen) + "px"
92
- }
93
- }
94
- });
95
- this.#ComboBox_main.appendChild(this.#ComboBox_second)
96
- }
97
- addValueChangeListener(listener = () => {}) {
98
- this.#ComboBox_main.addEventListener("chui_combo_option_changed", listener)
99
- }
100
- addOptions(...options) {
101
- for (let opt of options) {
102
- let option = document.createElement(`combobox_option`);
103
- option.innerHTML = opt.title;
104
- option.setAttribute('option_title', opt.title);
105
- option.setAttribute('option_value', opt.value);
106
- option.addEventListener('click', () => {
107
- const eventAwesome = new CustomEvent("chui_combo_option_changed", {
108
- detail: {
109
- title: option.getAttribute('option_title'),
110
- value: option.getAttribute('option_value')
111
- },
112
- });
113
- this.#ComboBox_main.dispatchEvent(eventAwesome)
114
- this.#input.value = option.getAttribute('option_title');
115
- this.#ComboBox_main.setAttribute("option_title", option.getAttribute('option_title'));
116
- this.#ComboBox_main.setAttribute("option_value", option.getAttribute('option_value'));
117
- });
118
- this.#dropdown.appendChild(option);
119
- }
120
- }
121
- getName() { return this.#input.name; }
122
- getValue() { return this.#ComboBox_main.getAttribute("option_value"); }
123
- setDisabled(boolean = Boolean()) {
124
- this.#input.disabled = boolean
125
- if (boolean) {
126
- this.#ComboBox_second.classList.add("combobox_disabled")
127
- this.#input.className = "combobox_input_disabled"
128
- this.#label.className = "combobox_label_disabled"
129
- this.#button_open.remove();
130
- this.#ComboBox_second.appendChild(this.#button_open_disabled);
131
- } else {
132
- this.#ComboBox_second.classList.remove("combobox_disabled")
133
- this.#input.className = "combobox_input"
134
- this.#label.className = "combobox_label"
135
- this.#button_open_disabled.remove();
136
- this.#ComboBox_second.appendChild(this.#button_open);
137
- }
138
- }
139
- clear() {
140
- this.#ComboBox_main.removeAttribute("option_title");
141
- this.#ComboBox_main.removeAttribute("option_value");
142
- this.#input.value = ""
143
- }
144
- set() { return this.#ComboBox_main; }
145
- }
146
-
147
- function setOptionDisplay(element) {
148
- for (let option of element.childNodes) { option.style.display = 'block'; }
149
- }
150
-
1
+ const { Animation } = require('../../../modules/chui_animations/animations');
2
+ const { shouldOpenDropdownUp } = require('../../../modules/chui_functions');
3
+ const { Icon, Icons } = require('../../chui_icons/icons');
4
+
5
+ const OPTION_ROW_HEIGHT = 33;
6
+
7
+ class ComboBox {
8
+ #id = require("randomstring").generate();
9
+ #id_cb = require("randomstring").generate();
10
+ #ComboBox_main = document.createElement('chui_combobox');
11
+ #ComboBox_second = document.createElement('combobox');
12
+ #label = document.createElement('label');
13
+ #input = document.createElement('input');
14
+ #button_open = document.createElement('combo_button_open');
15
+ #button_open_disabled = document.createElement('combo_button_open');
16
+ #dropdown = document.createElement('combobox_dropdown');
17
+ #dropdown_height = "max-content";
18
+ constructor(options = {
19
+ name: String(),
20
+ title: String(),
21
+ placeholder: String(),
22
+ width: String(),
23
+ required: Boolean(),
24
+ optionsLen: String(),
25
+ }) {
26
+ require('../../../modules/chui_functions').setStyles(__dirname + "/styles.css", 'chUiJS_ComboBox');
27
+ if (options.placeholder !== undefined) this.#input.placeholder = options.placeholder;
28
+ if (options.width !== undefined) this.#ComboBox_main.style.width = options.width;
29
+ if (options.title !== undefined) {
30
+ this.#label.classList.add('combobox_label')
31
+ this.#label.innerText = options.title;
32
+ this.#label.setAttribute('for', this.#id_cb);
33
+ this.#ComboBox_main.appendChild(this.#label);
34
+ }
35
+ if (options.optionsLen !== undefined) {
36
+ this.#dropdown_height = (OPTION_ROW_HEIGHT * options.optionsLen) + "px";
37
+ }
38
+ this.#dropdown.style.height = this.#dropdown_height;
39
+ if (options.name !== undefined) this.#input.name = options.name;
40
+ if (options.required !== undefined) this.#input.required = options.required;
41
+ this.#input.setAttribute('id', this.#id_cb);
42
+ this.#input.style.boxShadow = 'none';
43
+ this.#input.classList.add('combobox_input');
44
+ this.#input.type = 'text';
45
+ this.#input.addEventListener('focus', () => {
46
+ this.#ComboBox_second.style.border = '1px solid var(--blue_prime_background)';
47
+ this.#label.style.color = 'var(--blue_prime_background)';
48
+ })
49
+ this.#input.addEventListener('blur', () => {
50
+ this.#ComboBox_second.removeAttribute("style");
51
+ this.#label.removeAttribute("style");
52
+ })
53
+ this.#button_open.innerHTML = new Icon(Icons.HARDWARE.KEYBOARD_ARROW_DOWN, undefined, "var(--blue_prime_background)").getHTML();
54
+ this.#button_open_disabled.innerHTML = new Icon(Icons.HARDWARE.KEYBOARD_ARROW_DOWN, undefined, "var(--text_color_disabled)").getHTML();
55
+ this.#button_open_disabled.style.cursor = "not-allowed";
56
+ this.#dropdown.setAttribute('id', this.#id);
57
+ this.#ComboBox_second.appendChild(this.#input)
58
+ this.#ComboBox_second.appendChild(this.#button_open)
59
+ this.#ComboBox_second.appendChild(this.#dropdown)
60
+ //LISTENERS
61
+ this.#input.addEventListener('focus', () => {
62
+ this.#button_open.style.transform = 'rotate(180deg)'
63
+ this.#ComboBox_second.style.border = '1px solid var(--blue_prime_background)';
64
+ this.#dropdown.style.height = this.#dropdown_height
65
+ })
66
+ this.#input.addEventListener('blur', () => {
67
+ this.#button_open.style.transform = 'rotate(0deg)'
68
+ this.#ComboBox_second.removeAttribute('style')
69
+ this.#dropdown.style.height = this.#dropdown_height
70
+ })
71
+ this.#ComboBox_second.addEventListener('click', (event) => {
72
+ if (!this.#input.disabled) {
73
+ if (event.target.parentNode === this.#ComboBox_second) {
74
+ this.#input.focus()
75
+ new Animation(this.#dropdown).fadeIn();
76
+ setOptionDisplay(document.getElementById(this.#id));
77
+ this.#setDropdownDirection();
78
+ window.addEventListener('click', this.#window_click_event);
79
+ }
80
+ }
81
+ });
82
+
83
+ this.#input.addEventListener('input', (event) => {
84
+ let dropdown = document.getElementById(this.#id);
85
+ let query = event.target.value.toLowerCase();
86
+ for (let option of dropdown.childNodes) {
87
+ if (typeof option.getAttribute !== "function") continue;
88
+ let title = option.getAttribute('option_title');
89
+ if (title === null) continue;
90
+ if (!title.toLowerCase().includes(query)) {
91
+ option.style.display = 'none'
92
+ dropdown.style.height = 'max-content'
93
+ } else {
94
+ option.style.display = 'block'
95
+ dropdown.style.height = this.#dropdown_height
96
+ }
97
+ }
98
+ });
99
+ this.#ComboBox_main.appendChild(this.#ComboBox_second)
100
+ }
101
+ addValueChangeListener(listener = () => {}) {
102
+ this.#ComboBox_main.addEventListener("chui_combo_option_changed", listener)
103
+ }
104
+ addOptions(...options) {
105
+ for (let opt of options) {
106
+ let option = document.createElement(`combobox_option`);
107
+ option.innerHTML = opt.title;
108
+ option.setAttribute('option_title', opt.title);
109
+ option.setAttribute('option_value', opt.value);
110
+ option.addEventListener('click', () => {
111
+ const eventAwesome = new CustomEvent("chui_combo_option_changed", {
112
+ detail: {
113
+ title: option.getAttribute('option_title'),
114
+ value: option.getAttribute('option_value')
115
+ },
116
+ });
117
+ this.#ComboBox_main.dispatchEvent(eventAwesome)
118
+ this.#input.value = option.getAttribute('option_title');
119
+ this.#ComboBox_main.setAttribute("option_title", option.getAttribute('option_title'));
120
+ this.#ComboBox_main.setAttribute("option_value", option.getAttribute('option_value'));
121
+ });
122
+ this.#dropdown.appendChild(option);
123
+ }
124
+ }
125
+ getName() { return this.#input.name; }
126
+ getValue() { return this.#ComboBox_main.getAttribute("option_value"); }
127
+ setDisabled(boolean = Boolean()) {
128
+ this.#input.disabled = boolean
129
+ if (boolean) {
130
+ this.#ComboBox_second.classList.add("combobox_disabled")
131
+ this.#input.className = "combobox_input_disabled"
132
+ this.#label.className = "combobox_label_disabled"
133
+ this.#button_open.remove();
134
+ this.#ComboBox_second.appendChild(this.#button_open_disabled);
135
+ } else {
136
+ this.#ComboBox_second.classList.remove("combobox_disabled")
137
+ this.#input.className = "combobox_input"
138
+ this.#label.className = "combobox_label"
139
+ this.#button_open_disabled.remove();
140
+ this.#ComboBox_second.appendChild(this.#button_open);
141
+ }
142
+ }
143
+ clear() {
144
+ this.#ComboBox_main.removeAttribute("option_title");
145
+ this.#ComboBox_main.removeAttribute("option_value");
146
+ this.#input.value = ""
147
+ }
148
+ #window_click_event = (event) => {
149
+ if (event.target.parentNode !== this.#ComboBox_second) {
150
+ window.removeEventListener('click', this.#window_click_event);
151
+ new Animation(this.#dropdown).fadeOut();
152
+ }
153
+ }
154
+ #setDropdownDirection() {
155
+ const openUp = shouldOpenDropdownUp(this.#dropdown, this.#ComboBox_second);
156
+ this.#dropdown.style.top = openUp ? 'auto' : '';
157
+ this.#dropdown.style.bottom = openUp ? '100%' : '';
158
+ this.#dropdown.style.marginTop = openUp ? '0' : '';
159
+ }
160
+ set() { return this.#ComboBox_main; }
161
+ }
162
+
163
+ function setOptionDisplay(element) {
164
+ for (let option of element.childNodes) { option.style.display = 'block'; }
165
+ }
166
+
151
167
  exports.ComboBox = ComboBox