@db-ux/react-core-components 2.0.0-0-6589a60 → 2.0.0-0-custom-select-16b8cce

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 (54) hide show
  1. package/dist/components/checkbox/checkbox.d.ts +1 -1
  2. package/dist/components/checkbox/checkbox.js +2 -2
  3. package/dist/components/custom-select/custom-select.d.ts +3 -0
  4. package/dist/components/custom-select/custom-select.js +543 -0
  5. package/dist/components/custom-select/index.d.ts +1 -0
  6. package/dist/components/custom-select/index.js +1 -0
  7. package/dist/components/custom-select/model.d.ts +173 -0
  8. package/dist/components/custom-select/model.js +1 -0
  9. package/dist/components/custom-select-dropdown/custom-select-dropdown.d.ts +3 -0
  10. package/dist/components/custom-select-dropdown/custom-select-dropdown.js +12 -0
  11. package/dist/components/custom-select-dropdown/index.d.ts +1 -0
  12. package/dist/components/custom-select-dropdown/index.js +1 -0
  13. package/dist/components/custom-select-dropdown/model.d.ts +15 -0
  14. package/dist/components/custom-select-dropdown/model.js +1 -0
  15. package/dist/components/custom-select-form-field/custom-select-form-field.d.ts +3 -0
  16. package/dist/components/custom-select-form-field/custom-select-form-field.js +11 -0
  17. package/dist/components/custom-select-form-field/index.d.ts +1 -0
  18. package/dist/components/custom-select-form-field/index.js +1 -0
  19. package/dist/components/custom-select-form-field/model.d.ts +5 -0
  20. package/dist/components/custom-select-form-field/model.js +1 -0
  21. package/dist/components/custom-select-list/custom-select-list.d.ts +3 -0
  22. package/dist/components/custom-select-list/custom-select-list.js +12 -0
  23. package/dist/components/custom-select-list/index.d.ts +1 -0
  24. package/dist/components/custom-select-list/index.js +1 -0
  25. package/dist/components/custom-select-list/model.d.ts +8 -0
  26. package/dist/components/custom-select-list/model.js +1 -0
  27. package/dist/components/custom-select-list-item/custom-select-list-item.d.ts +6 -0
  28. package/dist/components/custom-select-list-item/custom-select-list-item.js +40 -0
  29. package/dist/components/custom-select-list-item/index.d.ts +1 -0
  30. package/dist/components/custom-select-list-item/index.js +1 -0
  31. package/dist/components/custom-select-list-item/model.d.ts +29 -0
  32. package/dist/components/custom-select-list-item/model.js +1 -0
  33. package/dist/components/input/input.d.ts +1 -1
  34. package/dist/components/input/input.js +4 -4
  35. package/dist/components/radio/radio.d.ts +1 -1
  36. package/dist/components/select/model.d.ts +3 -3
  37. package/dist/components/select/select.d.ts +1 -1
  38. package/dist/components/select/select.js +6 -6
  39. package/dist/components/switch/switch.d.ts +1 -1
  40. package/dist/components/tag/model.d.ts +3 -3
  41. package/dist/components/tag/tag.d.ts +1 -1
  42. package/dist/components/tag/tag.js +5 -4
  43. package/dist/components/textarea/textarea.d.ts +1 -1
  44. package/dist/components/textarea/textarea.js +2 -2
  45. package/dist/index.d.ts +5 -0
  46. package/dist/index.js +5 -0
  47. package/dist/shared/constants.d.ts +5 -0
  48. package/dist/shared/constants.js +6 -1
  49. package/dist/shared/model.d.ts +31 -14
  50. package/dist/shared/model.js +3 -1
  51. package/dist/utils/index.d.ts +2 -0
  52. package/dist/utils/index.js +2 -0
  53. package/dist/utils/react.d.ts +4 -4
  54. package/package.json +3 -3
@@ -1,3 +1,3 @@
1
1
  import * as React from "react";
2
- declare const DBCheckbox: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "checked" | keyof import("../../shared/model").GlobalProps | "indeterminate" | keyof import("../../shared/model").ChangeEventProps<HTMLInputElement> | keyof import("../../shared/model").FocusEventProps<HTMLInputElement> | keyof import("../../shared/model").FormProps | keyof import("../../shared/model").FormMessageProps> & import("./model").DBCheckboxDefaultProps & import("../../shared/model").GlobalProps & import("../../shared/model").ChangeEventProps<HTMLInputElement> & import("../../shared/model").FocusEventProps<HTMLInputElement> & import("../../shared/model").FormProps & import("../../shared/model").FormCheckProps & import("../../shared/model").FormMessageProps & import("../../shared/model").SizeProps & React.RefAttributes<HTMLInputElement>>;
2
+ declare const DBCheckbox: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "required" | "value" | "size" | "checked" | keyof import("../../shared/model").GlobalProps | "indeterminate" | keyof import("../../shared/model").ChangeEventProps<HTMLInputElement> | keyof import("../../shared/model").FocusEventProps<HTMLInputElement> | keyof import("../../shared/model").CustomFormProps | keyof import("../../shared/model").BaseFormProps | "showLabel" | keyof import("../../shared/model").FormMessageProps> & import("./model").DBCheckboxDefaultProps & import("../../shared/model").GlobalProps & import("../../shared/model").ChangeEventProps<HTMLInputElement> & import("../../shared/model").FocusEventProps<HTMLInputElement> & import("../../shared/model").CustomFormProps & import("../../shared/model").BaseFormProps & import("../../shared/model").RequiredProps & import("../../shared/model").ShowLabelProps & import("../../shared/model").ValueProps & import("../../shared/model").FormCheckProps & import("../../shared/model").FormMessageProps & import("../../shared/model").SizeProps & React.RefAttributes<HTMLInputElement>>;
3
3
  export default DBCheckbox;
@@ -6,7 +6,7 @@ import { DEFAULT_INVALID_MESSAGE, DEFAULT_INVALID_MESSAGE_ID_SUFFIX, DEFAULT_MES
6
6
  import DBInfotext from "../infotext/infotext";
7
7
  import { cls, delay, getHideProp, hasVoiceOver, stringPropVisible, uuid, } from "../../utils";
8
8
  function DBCheckboxFn(props, component) {
9
- var _a, _b, _c, _d;
9
+ var _a, _b, _c;
10
10
  const _ref = component || useRef(component);
11
11
  const [initialized, setInitialized] = useState(() => false);
12
12
  const [_id, set_id] = useState(() => undefined);
@@ -106,7 +106,7 @@ function DBCheckboxFn(props, component) {
106
106
  props.label ? React.createElement(React.Fragment, null, props.label) : React.createElement(React.Fragment, null, props.children)),
107
107
  stringPropVisible(props.message, props.showMessage) ? (React.createElement(DBInfotext, { size: "small", icon: props.messageIcon, id: _messageId }, props.message)) : null,
108
108
  React.createElement(DBInfotext, { size: "small", semantic: "successful", id: _validMessageId }, (_a = props.validMessage) !== null && _a !== void 0 ? _a : DEFAULT_VALID_MESSAGE),
109
- React.createElement(DBInfotext, { size: "small", semantic: "critical", id: _invalidMessageId }, (_d = (_b = props.invalidMessage) !== null && _b !== void 0 ? _b : (_c = _ref.current) === null || _c === void 0 ? void 0 : _c.validationMessage) !== null && _d !== void 0 ? _d : DEFAULT_INVALID_MESSAGE),
109
+ React.createElement(DBInfotext, { size: "small", semantic: "critical", id: _invalidMessageId }, (_b = props.invalidMessage) !== null && _b !== void 0 ? _b : (((_c = _ref.current) === null || _c === void 0 ? void 0 : _c.validationMessage) || DEFAULT_INVALID_MESSAGE)),
110
110
  React.createElement("span", { "data-visually-hidden": "true", role: "status" }, _voiceOverFallback)));
111
111
  }
112
112
  const DBCheckbox = forwardRef(DBCheckboxFn);
@@ -0,0 +1,3 @@
1
+ import * as React from "react";
2
+ declare const DBCustomSelect: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "required" | "width" | "icon" | keyof import("../../shared/model").GlobalProps | "showIcon" | keyof import("../../shared/model").CustomFormProps | keyof import("../../shared/model").BaseFormProps | "showLabel" | keyof import("../../shared/model").FormMessageProps | keyof import("./model").DBCustomSelectDefaultProps> & import("../../shared/model").GlobalProps & import("../../shared/model").CustomFormProps & import("../../shared/model").BaseFormProps & import("../../shared/model").RequiredProps & import("../../shared/model").FormMessageProps & import("./model").DBCustomSelectDefaultProps & import("../../shared/model").WidthProps & import("../../shared/model").IconProps & import("../../shared/model").ShowIconProps & import("../../shared/model").ShowLabelProps & React.RefAttributes<HTMLDivElement>>;
3
+ export default DBCustomSelect;
@@ -0,0 +1,543 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { filterPassingProps, getRootProps } from "../../utils/react";
4
+ import { useState, useRef, useEffect, forwardRef } from "react";
5
+ import { cls, delay, getBooleanAsString, getHideProp, getSearchInput, handleDataOutside, hasVoiceOver, stringPropVisible, uuid, } from "../../utils";
6
+ import { DEFAULT_CLOSE_BUTTON, DEFAULT_INVALID_MESSAGE, DEFAULT_INVALID_MESSAGE_ID_SUFFIX, DEFAULT_LABEL, DEFAULT_LABEL_ID_SUFFIX, DEFAULT_MESSAGE, DEFAULT_MESSAGE_ID_SUFFIX, DEFAULT_PLACEHOLDER_ID_SUFFIX, DEFAULT_REMOVE, DEFAULT_SELECT_ID_SUFFIX, DEFAULT_SELECTED, DEFAULT_VALID_MESSAGE, DEFAULT_VALID_MESSAGE_ID_SUFFIX, } from "../../shared/constants";
7
+ import DBCustomSelectList from "../custom-select-list/custom-select-list";
8
+ import DBCustomSelectListItem from "../custom-select-list-item/custom-select-list-item";
9
+ import DBCustomSelectDropdown from "../custom-select-dropdown/custom-select-dropdown";
10
+ import DBInfotext from "../infotext/infotext";
11
+ import DBTag from "../tag/tag";
12
+ import DBButton from "../button/button";
13
+ import DBTooltip from "../tooltip/tooltip";
14
+ import DBInput from "../input/input";
15
+ function DBCustomSelectFn(props, component) {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
17
+ props = Object.assign({ clearSelectionLabel: "Clear selection", showClearSelection: true }, props);
18
+ const _ref = component || useRef(component);
19
+ const detailsRef = useRef(null);
20
+ const selectRef = useRef(null);
21
+ const selectAllRef = useRef(null);
22
+ const [_name, set_name] = useState(() => undefined);
23
+ const [_id, set_id] = useState(() => undefined);
24
+ const [_messageId, set_messageId] = useState(() => undefined);
25
+ const [_validMessageId, set_validMessageId] = useState(() => undefined);
26
+ const [_invalidMessageId, set_invalidMessageId] = useState(() => undefined);
27
+ const [_selectId, set_selectId] = useState(() => undefined);
28
+ const [_labelId, set_labelId] = useState(() => undefined);
29
+ const [_summaryId, set_summaryId] = useState(() => undefined);
30
+ const [_placeholderId, set_placeholderId] = useState(() => undefined);
31
+ const [_infoTextId, set_infoTextId] = useState(() => undefined);
32
+ const [_validity, set_validity] = useState(() => "no-validation");
33
+ const [_descByIds, set_descByIds] = useState(() => "");
34
+ const [_selectedLabels, set_selectedLabels] = useState(() => "");
35
+ const [_selectedLabelsId, set_selectedLabelsId] = useState(() => undefined);
36
+ const [_voiceOverFallback, set_voiceOverFallback] = useState(() => "");
37
+ const [_selectedOptions, set_selectedOptions] = useState(() => []);
38
+ const [selectAllEnabled, setSelectAllEnabled] = useState(() => false);
39
+ const [searchEnabled, setSearchEnabled] = useState(() => false);
40
+ const [amountOptions, setAmountOptions] = useState(() => 0);
41
+ const [_values, set_values] = useState(() => []);
42
+ const [_options, set_options] = useState(() => []);
43
+ const [_hasNoOptions, set_hasNoOptions] = useState(() => false);
44
+ const [_internalChangeTimestamp, set_internalChangeTimestamp] = useState(() => -1);
45
+ const [_externalChangeTimestamp, set_externalChangeTimestamp] = useState(() => -1);
46
+ function handleDropdownToggle(event) {
47
+ if (props.onDropdownToggle) {
48
+ props.onDropdownToggle(event);
49
+ }
50
+ }
51
+ function getNativeSelectValue() {
52
+ var _a;
53
+ if (_values === null || _values === void 0 ? void 0 : _values.length) {
54
+ return (_a = _values.at(0)) !== null && _a !== void 0 ? _a : "";
55
+ }
56
+ return "";
57
+ }
58
+ function setDescById(descId) {
59
+ const descByIds = [];
60
+ if (descId) {
61
+ descByIds.push(descId);
62
+ }
63
+ if (_selectedLabelsId && (_selectedLabels === null || _selectedLabels === void 0 ? void 0 : _selectedLabels.length)) {
64
+ descByIds.push(_selectedLabelsId);
65
+ }
66
+ set_descByIds(descByIds.join(" "));
67
+ }
68
+ function getSelectAllLabel() {
69
+ var _a, _b, _c;
70
+ if (!selectAllRef.current)
71
+ return (_a = props.selectAllLabel) !== null && _a !== void 0 ? _a : DEFAULT_LABEL;
72
+ if (selectAllRef.current.indeterminate || !selectAllChecked) {
73
+ return (_b = props.selectAllLabel) !== null && _b !== void 0 ? _b : DEFAULT_LABEL;
74
+ }
75
+ else {
76
+ return (_c = props.deSelectAllLabel) !== null && _c !== void 0 ? _c : DEFAULT_LABEL;
77
+ }
78
+ }
79
+ function getOptionLabel(option) {
80
+ var _a, _b, _c;
81
+ return (_c = (_a = option.label) !== null && _a !== void 0 ? _a : (_b = option.value) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "";
82
+ }
83
+ function getOptionChecked(value) {
84
+ if (value && _values && _values.includes) {
85
+ return _values === null || _values === void 0 ? void 0 : _values.includes(value);
86
+ }
87
+ return false;
88
+ }
89
+ function getOptionKey(option) {
90
+ var _a, _b;
91
+ return ((_b = (_a = option.id) !== null && _a !== void 0 ? _a : option.value) !== null && _b !== void 0 ? _b : uuid()).toString();
92
+ }
93
+ function getTagRemoveLabel(index) {
94
+ return props.removeTagsTexts && props.removeTagsTexts.length > index
95
+ ? props.removeTagsTexts.at(index)
96
+ : `${DEFAULT_REMOVE} ${_selectedOptions ? getOptionLabel(_selectedOptions[index]) : ""}`;
97
+ }
98
+ function handleTagRemove(option, event) {
99
+ event.stopPropagation();
100
+ handleSelect(option.value);
101
+ handleSummaryFocus();
102
+ }
103
+ function handleAutoPlacement() {
104
+ if (detailsRef.current) {
105
+ const dropdown = detailsRef.current.querySelector("article");
106
+ if (dropdown) {
107
+ delay(() => {
108
+ handleDataOutside(dropdown);
109
+ }, 100);
110
+ }
111
+ }
112
+ }
113
+ function handleArrowDownUp(event) {
114
+ var _a, _b, _c, _d, _e;
115
+ if ((_a = detailsRef.current) === null || _a === void 0 ? void 0 : _a.open) {
116
+ if (document) {
117
+ const activeElement = document.activeElement;
118
+ if (activeElement) {
119
+ // 1. we check if we are currently focusing a checkbox in the dropdown
120
+ const isCheckbox = activeElement.getAttribute("type") === "checkbox" ||
121
+ activeElement.getAttribute("type") === "radio";
122
+ if (isCheckbox) {
123
+ const listElement = activeElement === null || activeElement === void 0 ? void 0 : activeElement.closest("li");
124
+ if (event.key === "ArrowDown" || event.key === "ArrowRight") {
125
+ if (listElement === null || listElement === void 0 ? void 0 : listElement.nextElementSibling) {
126
+ (_b = listElement === null || listElement === void 0 ? void 0 : listElement.nextElementSibling.querySelector("input")) === null || _b === void 0 ? void 0 : _b.focus();
127
+ }
128
+ else {
129
+ // We are on the last checkbox we move to the top checkbox
130
+ handleFocusFirstDropdownCheckbox(activeElement);
131
+ }
132
+ }
133
+ else {
134
+ if (listElement === null || listElement === void 0 ? void 0 : listElement.previousElementSibling) {
135
+ (_c = listElement === null || listElement === void 0 ? void 0 : listElement.previousElementSibling.querySelector("input")) === null || _c === void 0 ? void 0 : _c.focus();
136
+ }
137
+ else if (detailsRef.current.querySelector(`input[type="checkbox"]`) !==
138
+ activeElement) {
139
+ // We are on the top list checkbox but there is a select all checkbox as well
140
+ handleFocusFirstDropdownCheckbox(activeElement);
141
+ }
142
+ else {
143
+ // We are on the top checkbox, we need to move to the search
144
+ // or to the last checkbox
145
+ const search = getSearchInput(detailsRef.current);
146
+ if (search) {
147
+ delay(() => {
148
+ search.focus();
149
+ }, 100);
150
+ }
151
+ else {
152
+ const checkboxList = Array.from((_d = detailsRef.current) === null || _d === void 0 ? void 0 : _d.querySelectorAll(`input[type="checkbox"],input[type="radio"]`));
153
+ if (checkboxList.length) {
154
+ (_e = checkboxList.at(-1)) === null || _e === void 0 ? void 0 : _e.focus();
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ else {
161
+ // 2. If we are on the search, and press up we go back to summary and close
162
+ if (activeElement.getAttribute("type") === "search" &&
163
+ (event.key === "ArrowUp" || event.key === "ArrowLeft")) {
164
+ handleClose("close");
165
+ handleSummaryFocus();
166
+ }
167
+ else {
168
+ // 3. Otherwise, we need to move to the first checkbox
169
+ handleFocusFirstDropdownCheckbox(activeElement);
170
+ }
171
+ }
172
+ }
173
+ }
174
+ event.stopPropagation();
175
+ event.preventDefault();
176
+ }
177
+ else if (event.key === "ArrowDown" || event.key === "ArrowRight") {
178
+ // Open dropdown with arrows see https://www.w3.org/WAI/ARIA/apg/patterns/combobox/#keyboardinteraction
179
+ handleAutoPlacement();
180
+ if (detailsRef.current) {
181
+ detailsRef.current.open = true;
182
+ }
183
+ handleOpenByKeyboardFocus();
184
+ event.stopPropagation();
185
+ event.preventDefault();
186
+ }
187
+ }
188
+ function handleKeyboardPress(event) {
189
+ var _a;
190
+ if (event.key === "Escape" &&
191
+ detailsRef.current &&
192
+ ((_a = detailsRef.current) === null || _a === void 0 ? void 0 : _a.open)) {
193
+ handleClose("close");
194
+ handleSummaryFocus();
195
+ }
196
+ else if (event.key === "ArrowDown" ||
197
+ event.key === "ArrowUp" ||
198
+ event.key === "ArrowLeft" ||
199
+ event.key === "ArrowRight") {
200
+ handleArrowDownUp(event);
201
+ }
202
+ }
203
+ function handleClose(event) {
204
+ if (detailsRef.current) {
205
+ if (event === "close") {
206
+ detailsRef.current.open = false;
207
+ handleSummaryFocus();
208
+ }
209
+ else if (detailsRef.current.open && (event === null || event === void 0 ? void 0 : event.relatedTarget)) {
210
+ const relatedTarget = event.relatedTarget;
211
+ if (!detailsRef.current.contains(relatedTarget)) {
212
+ detailsRef.current.open = false;
213
+ }
214
+ }
215
+ }
216
+ }
217
+ function handleDocumentClose(event) {
218
+ var _a;
219
+ if (((_a = detailsRef.current) === null || _a === void 0 ? void 0 : _a.open) &&
220
+ !detailsRef.current.contains(event.target)) {
221
+ detailsRef.current.open = false;
222
+ }
223
+ }
224
+ function handleSelect(value) {
225
+ if (value) {
226
+ if (props.multiple) {
227
+ if (_values === null || _values === void 0 ? void 0 : _values.includes(value)) {
228
+ set_values(_values === null || _values === void 0 ? void 0 : _values.filter((v) => v !== value));
229
+ }
230
+ else {
231
+ set_values([...(_values || []), value]);
232
+ }
233
+ }
234
+ else {
235
+ set_values([value]);
236
+ handleClose("close");
237
+ }
238
+ set_internalChangeTimestamp(new Date().getTime());
239
+ }
240
+ }
241
+ function handleSelectAll() {
242
+ if ((_values === null || _values === void 0 ? void 0 : _values.length) === amountOptions) {
243
+ set_values([]);
244
+ }
245
+ else {
246
+ set_values(props.options
247
+ ? props.options
248
+ .filter((option) => !option.isGroupTitle)
249
+ .map((option) => { var _a; return (_a = option.value) !== null && _a !== void 0 ? _a : ""; })
250
+ : []);
251
+ }
252
+ set_internalChangeTimestamp(new Date().getTime());
253
+ }
254
+ function handleFocusFirstDropdownCheckbox(activeElement) {
255
+ if (detailsRef.current) {
256
+ const checkboxes = Array.from(detailsRef.current.querySelectorAll(`input[type="checkbox"],input[type="radio"]`));
257
+ if (checkboxes.length) {
258
+ const first = checkboxes.at(0);
259
+ const checkbox = first === activeElement && checkboxes.length > 1
260
+ ? checkboxes.at(1)
261
+ : first;
262
+ if (checkbox) {
263
+ delay(() => {
264
+ // Takes some time until element can be focused
265
+ checkbox.focus();
266
+ }, 100);
267
+ }
268
+ }
269
+ }
270
+ }
271
+ function handleOpenByKeyboardFocus(onlySearch) {
272
+ if (detailsRef.current) {
273
+ // Focus search if possible
274
+ const search = getSearchInput(detailsRef.current);
275
+ if (search) {
276
+ delay(() => {
277
+ // Takes some time until element can be focused
278
+ search.focus();
279
+ }, 100);
280
+ }
281
+ else if (!onlySearch) {
282
+ // Focus first checkbox otherwise
283
+ handleFocusFirstDropdownCheckbox();
284
+ }
285
+ }
286
+ }
287
+ function handleSearch(event) {
288
+ const filterText = event.target.value;
289
+ set_options(!props.options || !filterText || filterText.length === 0
290
+ ? props.options
291
+ : props.options.filter((option) => !option.isGroupTitle &&
292
+ getOptionLabel(option)
293
+ .toLowerCase()
294
+ .includes(filterText.toLowerCase())));
295
+ }
296
+ function handleClearAll() {
297
+ set_values([]);
298
+ handleSummaryFocus();
299
+ }
300
+ function handleSummaryFocus() {
301
+ var _a, _b;
302
+ (_b = (_a = detailsRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("summary")) === null || _b === void 0 ? void 0 : _b.focus();
303
+ }
304
+ const [selectAllChecked, setSelectAllChecked] = useState(() => false);
305
+ const [selectAllIndeterminate, setSelectAllIndeterminate] = useState(() => false);
306
+ useEffect(() => {
307
+ var _a;
308
+ const mId = (_a = props.id) !== null && _a !== void 0 ? _a : `custom-select-${uuid()}`;
309
+ set_id(mId);
310
+ set_messageId(mId + DEFAULT_MESSAGE_ID_SUFFIX);
311
+ set_validMessageId(mId + DEFAULT_VALID_MESSAGE_ID_SUFFIX);
312
+ set_invalidMessageId(mId + DEFAULT_INVALID_MESSAGE_ID_SUFFIX);
313
+ set_selectId(mId + DEFAULT_SELECT_ID_SUFFIX);
314
+ set_labelId(mId + DEFAULT_LABEL_ID_SUFFIX);
315
+ set_summaryId(mId + "-summary");
316
+ set_placeholderId(mId + DEFAULT_PLACEHOLDER_ID_SUFFIX);
317
+ set_selectedLabelsId(mId + "-selected-labels");
318
+ set_infoTextId(mId + "-info");
319
+ if (document) {
320
+ document.addEventListener("click", handleDocumentClose);
321
+ }
322
+ }, []);
323
+ useEffect(() => {
324
+ var _a;
325
+ set_name((_a = props.name) !== null && _a !== void 0 ? _a : _id);
326
+ }, [props.name, _id]);
327
+ useEffect(() => {
328
+ if (_id) {
329
+ const messageId = _id + DEFAULT_MESSAGE_ID_SUFFIX;
330
+ set_labelId(_id + DEFAULT_LABEL_ID_SUFFIX);
331
+ set_selectId(_id + DEFAULT_SELECT_ID_SUFFIX);
332
+ set_validMessageId(_id + DEFAULT_VALID_MESSAGE_ID_SUFFIX);
333
+ set_invalidMessageId(_id + DEFAULT_INVALID_MESSAGE_ID_SUFFIX);
334
+ set_placeholderId(_id + DEFAULT_PLACEHOLDER_ID_SUFFIX);
335
+ if (stringPropVisible(props.message, props.showMessage)) {
336
+ setDescById(messageId);
337
+ }
338
+ else {
339
+ setDescById();
340
+ }
341
+ }
342
+ }, [_id]);
343
+ useEffect(() => {
344
+ if (detailsRef.current) {
345
+ const summary = detailsRef.current.querySelector("summary");
346
+ if (summary) {
347
+ summary.setAttribute("aria-describedby", _descByIds || "");
348
+ }
349
+ }
350
+ }, [detailsRef.current, _descByIds]);
351
+ useEffect(() => {
352
+ if (detailsRef.current) {
353
+ const summary = detailsRef.current.querySelector("summary");
354
+ if (summary) {
355
+ summary.addEventListener("click", () => {
356
+ handleAutoPlacement();
357
+ handleOpenByKeyboardFocus(true);
358
+ });
359
+ summary.addEventListener("keydown", (event) => {
360
+ var _a;
361
+ if (event.code === "Space" && !((_a = detailsRef.current) === null || _a === void 0 ? void 0 : _a.open)) {
362
+ handleOpenByKeyboardFocus();
363
+ }
364
+ });
365
+ }
366
+ detailsRef.current.addEventListener("focusout", (event) => handleClose(event));
367
+ }
368
+ }, [detailsRef.current]);
369
+ useEffect(() => {
370
+ if (props.showNoResults !== undefined) {
371
+ set_hasNoOptions(props.showNoResults);
372
+ }
373
+ else if (_options) {
374
+ set_hasNoOptions(_options.length === 0);
375
+ }
376
+ }, [props.showNoResults, _options]);
377
+ useEffect(() => {
378
+ setSelectAllEnabled(Boolean(props.multiple && (props.showSelectAll || amountOptions > 5)));
379
+ }, [props.showSelectAll, amountOptions, props.multiple]);
380
+ useEffect(() => {
381
+ setSearchEnabled(props.showSearch || amountOptions > 9);
382
+ }, [props.showSearch, amountOptions]);
383
+ useEffect(() => {
384
+ if (props.onSelect &&
385
+ (_externalChangeTimestamp || _internalChangeTimestamp)) {
386
+ const onlyInternalChange = _internalChangeTimestamp && !_externalChangeTimestamp;
387
+ const bothChangeButInternalNew = _internalChangeTimestamp &&
388
+ _externalChangeTimestamp &&
389
+ _internalChangeTimestamp > _externalChangeTimestamp;
390
+ if (onlyInternalChange || bothChangeButInternalNew) {
391
+ props.onSelect(_values !== null && _values !== void 0 ? _values : []);
392
+ const fakeEvent = {
393
+ target: {
394
+ values: _values,
395
+ },
396
+ };
397
+ }
398
+ }
399
+ }, [_externalChangeTimestamp, _internalChangeTimestamp, props.onSelect]);
400
+ useEffect(() => {
401
+ var _a;
402
+ if (props.values && Array.isArray(props.values)) {
403
+ set_values((_a = props.values) !== null && _a !== void 0 ? _a : []);
404
+ set_externalChangeTimestamp(new Date().getTime());
405
+ }
406
+ }, [props.values]);
407
+ useEffect(() => {
408
+ var _a, _b, _c, _d, _e, _f;
409
+ if (selectRef.current) {
410
+ selectRef.current.value = getNativeSelectValue();
411
+ }
412
+ /* For a11y reasons we need to map the correct message with the select */
413
+ if (!((_a = selectRef.current) === null || _a === void 0 ? void 0 : _a.validity.valid) || props.validation === "invalid") {
414
+ set_validity("invalid");
415
+ setDescById(_invalidMessageId);
416
+ if (hasVoiceOver()) {
417
+ set_voiceOverFallback((_d = (_b = props.invalidMessage) !== null && _b !== void 0 ? _b : (_c = selectRef.current) === null || _c === void 0 ? void 0 : _c.validationMessage) !== null && _d !== void 0 ? _d : DEFAULT_INVALID_MESSAGE);
418
+ delay(() => set_voiceOverFallback(""), 1000);
419
+ }
420
+ }
421
+ else if (props.validation === "valid" ||
422
+ (((_e = selectRef.current) === null || _e === void 0 ? void 0 : _e.validity.valid) && props.required)) {
423
+ set_validity("valid");
424
+ setDescById(_validMessageId);
425
+ if (hasVoiceOver()) {
426
+ set_voiceOverFallback((_f = props.validMessage) !== null && _f !== void 0 ? _f : DEFAULT_VALID_MESSAGE);
427
+ delay(() => set_voiceOverFallback(""), 1000);
428
+ }
429
+ }
430
+ else if (props.message) {
431
+ set_validity("no-validation");
432
+ setDescById(_messageId);
433
+ }
434
+ else {
435
+ set_validity("no-validation");
436
+ setDescById(_placeholderId);
437
+ }
438
+ }, [_values]);
439
+ useEffect(() => {
440
+ set_validity(props.validation);
441
+ }, [props.validation]);
442
+ useEffect(() => {
443
+ if ((_values === null || _values === void 0 ? void 0 : _values.length) === 0) {
444
+ setSelectAllChecked(false);
445
+ setSelectAllIndeterminate(false);
446
+ }
447
+ else if ((_values === null || _values === void 0 ? void 0 : _values.length) === amountOptions) {
448
+ setSelectAllIndeterminate(false);
449
+ setSelectAllChecked(true);
450
+ }
451
+ else if (_values) {
452
+ setSelectAllIndeterminate(true);
453
+ }
454
+ }, [_values, amountOptions]);
455
+ useEffect(() => {
456
+ var _a, _b;
457
+ set_options(props.options);
458
+ setAmountOptions((_b = (_a = props.options) === null || _a === void 0 ? void 0 : _a.filter((option) => !option.isGroupTitle).length) !== null && _b !== void 0 ? _b : 0);
459
+ }, [props.options]);
460
+ useEffect(() => {
461
+ if (_options === null || _options === void 0 ? void 0 : _options.length) {
462
+ set_selectedOptions(_options === null || _options === void 0 ? void 0 : _options.filter((option) => {
463
+ if (!option.value || !(_values === null || _values === void 0 ? void 0 : _values["includes"])) {
464
+ return false;
465
+ }
466
+ return !option.isGroupTitle && (_values === null || _values === void 0 ? void 0 : _values.includes(option.value));
467
+ }));
468
+ }
469
+ }, [_options, _values]);
470
+ useEffect(() => {
471
+ if (_selectedOptions === null || _selectedOptions === void 0 ? void 0 : _selectedOptions.length) {
472
+ if (props.selectedType === "amount") {
473
+ set_selectedLabels(props.amountText
474
+ ? props.amountText
475
+ : `${_selectedOptions === null || _selectedOptions === void 0 ? void 0 : _selectedOptions.length} ${DEFAULT_SELECTED}`);
476
+ }
477
+ else {
478
+ set_selectedLabels(_selectedOptions === null || _selectedOptions === void 0 ? void 0 : _selectedOptions.map((option) => getOptionLabel(option)).join(", "));
479
+ }
480
+ }
481
+ else {
482
+ set_selectedLabels("");
483
+ }
484
+ }, [_selectedOptions, props.selectedType, props.amountText]);
485
+ useEffect(() => {
486
+ var _a;
487
+ if (props.onAmountChange) {
488
+ props.onAmountChange((_a = _selectedOptions === null || _selectedOptions === void 0 ? void 0 : _selectedOptions.length) !== null && _a !== void 0 ? _a : 0);
489
+ }
490
+ }, [_selectedOptions]);
491
+ useEffect(() => {
492
+ if (selectAllRef.current) {
493
+ selectAllRef.current.indeterminate = Boolean(selectAllIndeterminate);
494
+ }
495
+ }, [selectAllIndeterminate, selectAllRef.current]);
496
+ useEffect(() => {
497
+ return () => {
498
+ if (document) {
499
+ document.removeEventListener("click", handleDocumentClose);
500
+ }
501
+ };
502
+ }, []);
503
+ return (React.createElement("div", Object.assign({ id: _id, ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), { className: cls("db-custom-select", props.className), "aria-invalid": _validity === "invalid", "data-custom-validity": _validity, "data-width": props.width, "data-variant": props.variant, "data-required": getBooleanAsString(props.required), "data-placement": props.placement, "data-selected-type": props.multiple ? props.selectedType : "text", "data-hide-label": getHideProp(props.showLabel), "data-icon": props.icon, "data-hide-icon": getHideProp(props.showIcon) }),
504
+ React.createElement("label", { id: _labelId }, (_a = props.label) !== null && _a !== void 0 ? _a : DEFAULT_LABEL,
505
+ React.createElement("select", { role: "none", hidden: true, id: _selectId, tabIndex: -1, ref: selectRef, form: props.form, disabled: props.disabled, multiple: props.multiple, required: props.required, onChange: (event) => { } }, _options === null || _options === void 0 ? void 0 : _options.map((option) => (React.createElement("option", { disabled: option.disabled, value: option.value, key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option) }, getOptionLabel(option)))))),
506
+ React.createElement("details", { ref: detailsRef, open: props.open, "aria-disabled": props.disabled, onToggle: (event) => handleDropdownToggle(event), onKeyDown: (event) => handleKeyboardPress(event) },
507
+ props.children,
508
+ props.options ? (React.createElement(React.Fragment, null,
509
+ React.createElement("summary", { className: "db-custom-select-form-field", id: _summaryId, "aria-labelledby": _labelId },
510
+ (_selectedLabels === null || _selectedLabels === void 0 ? void 0 : _selectedLabels.length) ? (React.createElement("span", { "data-visually-hidden": getBooleanAsString(props.selectedType === "tag"), id: _selectedLabelsId }, _selectedLabels)) : null,
511
+ props.selectedType === "tag" ? (React.createElement("div", null, _selectedOptions === null || _selectedOptions === void 0 ? void 0 : _selectedOptions.map((option, index) => (React.createElement(DBTag, { emphasis: "strong", behavior: "removable", removeButton: getTagRemoveLabel(index), onRemove: (event) => {
512
+ handleTagRemove(option, event);
513
+ }, key: "tag-" + getOptionKey(option) }, getOptionLabel(option)))))) : null),
514
+ React.createElement(DBCustomSelectDropdown, { width: props.dropdownWidth },
515
+ searchEnabled ? (React.createElement("div", null,
516
+ React.createElement(DBInput, { type: "search", showLabel: false, label: (_b = props.searchLabel) !== null && _b !== void 0 ? _b : DEFAULT_LABEL, placeholder: (_c = props.searchPlaceholder) !== null && _c !== void 0 ? _c : props.searchLabel, ariaDescribedBy: _hasNoOptions || props.showLoading
517
+ ? _infoTextId
518
+ : undefined, onInput: (event) => handleSearch(event) }))) : null,
519
+ _hasNoOptions || props.showLoading ? (React.createElement(DBInfotext, { id: _infoTextId, icon: _hasNoOptions ? undefined : "circular_arrows", semantic: _hasNoOptions ? "warning" : "informational" }, (_d = (_hasNoOptions ? props.noResultsText : props.loadingText)) !== null && _d !== void 0 ? _d : DEFAULT_MESSAGE)) : (React.createElement(React.Fragment, null,
520
+ React.createElement(React.Fragment, null,
521
+ selectAllEnabled ? (React.createElement("div", null,
522
+ React.createElement("div", { className: "db-checkbox db-custom-select-list-item" },
523
+ React.createElement("label", null,
524
+ React.createElement("input", { type: "checkbox", value: "select-all", ref: selectAllRef, form: _id, checked: selectAllChecked, onChange: (event) => handleSelectAll() }),
525
+ getSelectAllLabel())))) : null,
526
+ React.createElement(DBCustomSelectList, { multiple: props.multiple, label: (_e = props.label) !== null && _e !== void 0 ? _e : DEFAULT_LABEL }, _options === null || _options === void 0 ? void 0 : _options.map((option) => (React.createElement(DBCustomSelectListItem, { type: props.multiple ? "checkbox" : "radio", showDivider: option.showDivider, icon: option.icon, isGroupTitle: option.isGroupTitle, groupTitle: getOptionLabel(option), name: _name, checked: getOptionChecked(option.value), disabled: option.disabled, value: option.value, onChange: (event) => {
527
+ handleSelect(option.value);
528
+ }, key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option) }, !option.isGroupTitle ? (React.createElement(React.Fragment, null, getOptionLabel(option))) : null))))))),
529
+ React.createElement("div", null,
530
+ React.createElement(DBButton, { variant: "ghost", width: "full", icon: "cross", size: "small", onClick: (event) => {
531
+ handleClose("close");
532
+ } }, (_f = props.mobileCloseButtonText) !== null && _f !== void 0 ? _f : DEFAULT_CLOSE_BUTTON))))) : null),
533
+ ((_g = props.showClearSelection) !== null && _g !== void 0 ? _g : true) && (_values === null || _values === void 0 ? void 0 : _values.length) ? (React.createElement(DBButton, { icon: "cross", variant: "ghost", size: "small", noText: true, onClick: (event) => handleClearAll() },
534
+ props.clearSelectionLabel,
535
+ React.createElement(DBTooltip, { placement: "top" }, props.clearSelectionLabel))) : null,
536
+ React.createElement("span", { "aria-hidden": getBooleanAsString(true), id: _placeholderId }, (_h = props.placeholder) !== null && _h !== void 0 ? _h : props.label),
537
+ props.message ? (React.createElement(DBInfotext, { size: "small", icon: props.messageIcon, id: _messageId }, props.message)) : null,
538
+ React.createElement(DBInfotext, { size: "small", semantic: "successful", id: _validMessageId }, (_j = props.validMessage) !== null && _j !== void 0 ? _j : DEFAULT_VALID_MESSAGE),
539
+ React.createElement(DBInfotext, { size: "small", semantic: "critical", id: _invalidMessageId }, (_k = props.invalidMessage) !== null && _k !== void 0 ? _k : (((_l = selectRef.current) === null || _l === void 0 ? void 0 : _l.validationMessage) || DEFAULT_INVALID_MESSAGE)),
540
+ React.createElement("span", { "data-visually-hidden": "true", role: "status" }, _voiceOverFallback)));
541
+ }
542
+ const DBCustomSelect = forwardRef(DBCustomSelectFn);
543
+ export default DBCustomSelect;
@@ -0,0 +1 @@
1
+ export { default as DBCustomSelect } from './custom-select';
@@ -0,0 +1 @@
1
+ export { default as DBCustomSelect } from './custom-select';