@trackunit/react-form-components 0.0.1

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 (96) hide show
  1. package/README.md +24 -0
  2. package/index.cjs +1274 -0
  3. package/index.css +259 -0
  4. package/index.js +1210 -0
  5. package/package.json +21 -0
  6. package/src/components/ActionButton/ActionButton.d.ts +26 -0
  7. package/src/components/ActionButton/index.d.ts +1 -0
  8. package/src/components/BaseInput/BaseInput.d.ts +62 -0
  9. package/src/components/BaseInput/index.d.ts +1 -0
  10. package/src/components/Checkbox/CheckIcon.d.ts +12 -0
  11. package/src/components/Checkbox/Checkbox.d.ts +48 -0
  12. package/src/components/Checkbox/IndeterminateIcon.d.ts +10 -0
  13. package/src/components/Checkbox/index.d.ts +1 -0
  14. package/src/components/DateField/DateField.d.ts +19 -0
  15. package/src/components/DateInput/DateInput.d.ts +28 -0
  16. package/src/components/DropZone/DropZone.d.ts +34 -0
  17. package/src/components/EmailField/EmailField.d.ts +17 -0
  18. package/src/components/EmailInput/EmailInput.d.ts +13 -0
  19. package/src/components/EmailInput/index.d.ts +1 -0
  20. package/src/components/FormGroup/FormGroup.d.ts +39 -0
  21. package/src/components/Label/Label.d.ts +34 -0
  22. package/src/components/Label/index.d.ts +1 -0
  23. package/src/components/NumberField/NumberField.d.ts +19 -0
  24. package/src/components/NumberInput/NumberInput.d.ts +12 -0
  25. package/src/components/PhoneField/PhoneField.d.ts +28 -0
  26. package/src/components/PhoneInput/CountryCodeSelect.d.ts +16 -0
  27. package/src/components/PhoneInput/CountryCodes.d.ts +5 -0
  28. package/src/components/PhoneInput/PhoneInput.d.ts +25 -0
  29. package/src/components/PhoneInput/index.d.ts +1 -0
  30. package/src/components/RadioGroup/RadioGroup.d.ts +57 -0
  31. package/src/components/RadioGroup/RadioGroupContext.d.ts +11 -0
  32. package/src/components/RadioGroup/RadioItem.d.ts +23 -0
  33. package/src/components/RadioGroup/index.d.ts +2 -0
  34. package/src/components/Search/Search.d.ts +62 -0
  35. package/src/components/Search/index.d.ts +1 -0
  36. package/src/components/Select/CreatableSelect.d.ts +38 -0
  37. package/src/components/Select/FieldContainer.d.ts +20 -0
  38. package/src/components/Select/Select.d.ts +18 -0
  39. package/src/components/Select/SelectMenuItem/SelectMenuItem.d.ts +49 -0
  40. package/src/components/Select/TagWithWidth.d.ts +17 -0
  41. package/src/components/Select/TagsContainer.d.ts +45 -0
  42. package/src/components/Select/index.d.ts +7 -0
  43. package/src/components/Select/shared.d.ts +15 -0
  44. package/src/components/Select/useCustomComponents.d.ts +19 -0
  45. package/src/components/Select/useCustomStyles.d.ts +14 -0
  46. package/src/components/Select/useSelect.d.ts +143 -0
  47. package/src/components/TextArea/TextArea.d.ts +30 -0
  48. package/src/components/TextArea/index.d.ts +1 -0
  49. package/src/components/TextAreaField/TextAreaField.d.ts +18 -0
  50. package/src/components/TextAreaField/index.d.ts +1 -0
  51. package/src/components/TextField/TextField.d.ts +24 -0
  52. package/src/components/TextField/TextLenghtIndicator.d.ts +19 -0
  53. package/src/components/TextField/index.d.ts +1 -0
  54. package/src/components/TextInput/TextInput.d.ts +12 -0
  55. package/src/components/Toggle/Toggle.d.ts +57 -0
  56. package/src/components/Toggle/index.d.ts +1 -0
  57. package/src/components/UploadField/UploadField.d.ts +15 -0
  58. package/src/components/UploadInput/UploadInput.d.ts +33 -0
  59. package/src/index.d.ts +24 -0
  60. package/src/test-utils/hooks.d.ts +4 -0
  61. package/src/test-utils/test-utils.d.ts +5 -0
  62. package/src/translation.d.ts +34 -0
  63. package/translation.cjs +7 -0
  64. package/translation.js +5 -0
  65. package/translation10.cjs +7 -0
  66. package/translation10.js +5 -0
  67. package/translation11.cjs +7 -0
  68. package/translation11.js +5 -0
  69. package/translation12.cjs +7 -0
  70. package/translation12.js +5 -0
  71. package/translation13.cjs +7 -0
  72. package/translation13.js +5 -0
  73. package/translation14.cjs +7 -0
  74. package/translation14.js +5 -0
  75. package/translation15.cjs +7 -0
  76. package/translation15.js +5 -0
  77. package/translation16.cjs +7 -0
  78. package/translation16.js +5 -0
  79. package/translation17.cjs +7 -0
  80. package/translation17.js +5 -0
  81. package/translation2.cjs +7 -0
  82. package/translation2.js +5 -0
  83. package/translation3.cjs +7 -0
  84. package/translation3.js +5 -0
  85. package/translation4.cjs +7 -0
  86. package/translation4.js +5 -0
  87. package/translation5.cjs +7 -0
  88. package/translation5.js +5 -0
  89. package/translation6.cjs +7 -0
  90. package/translation6.js +5 -0
  91. package/translation7.cjs +7 -0
  92. package/translation7.js +5 -0
  93. package/translation8.cjs +7 -0
  94. package/translation8.js +5 -0
  95. package/translation9.cjs +7 -0
  96. package/translation9.js +5 -0
package/index.js ADDED
@@ -0,0 +1,1210 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { registerTranslations } from '@trackunit/i18n-library-translation';
3
+ import { IconButton, Icon, Tip, MenuItem, Tag, Spinner, Text } from '@trackunit/react-components';
4
+ import { tw, twx, tws } from '@trackunit/tailwind-styled-components';
5
+ import * as React from 'react';
6
+ import React__default, { forwardRef, useState, useEffect } from 'react';
7
+ import { v4 } from 'uuid';
8
+ import { format } from 'date-fns';
9
+ import ReactSelect, { components } from 'react-select';
10
+ export { default as ValueType } from 'react-select';
11
+ import ReactAsyncSelect from 'react-select/async';
12
+ import { getCountries, getCountryCallingCode } from 'libphonenumber-js';
13
+ import ReactAsyncCreatableSelect from 'react-select/async-creatable';
14
+ import ReactCreatableSelect from 'react-select/creatable';
15
+
16
+ var defaultTranslations = {
17
+
18
+ };
19
+
20
+ /** The translation namespace for this library */
21
+ const namespace = "react.form-components";
22
+ /**
23
+ * The TranslationResource for this Library.
24
+ * Holds lazy loaded imports for all languages supported by the library.
25
+ *
26
+ * This is used to register the translations for this library before initializing i18next.
27
+ */
28
+ const translations = {
29
+ ns: namespace,
30
+ default: defaultTranslations,
31
+ languages: {
32
+ de: () => import('./translation.js'),
33
+ da: () => import('./translation2.js'),
34
+ cs: () => import('./translation3.js'),
35
+ nl: () => import('./translation4.js'),
36
+ fr: () => import('./translation5.js'),
37
+ fi: () => import('./translation6.js'),
38
+ hu: () => import('./translation7.js'),
39
+ it: () => import('./translation8.js'),
40
+ nb: () => import('./translation9.js'),
41
+ pl: () => import('./translation10.js'),
42
+ pt: () => import('./translation11.js'),
43
+ ru: () => import('./translation12.js'),
44
+ ro: () => import('./translation13.js'),
45
+ es: () => import('./translation14.js'),
46
+ sv: () => import('./translation15.js'),
47
+ ja: () => import('./translation16.js'),
48
+ th: () => import('./translation17.js'),
49
+ },
50
+ };
51
+ /**
52
+ * Registers the translations for this library
53
+ */
54
+ const setupLibraryTranslations = () => {
55
+ registerTranslations(translations);
56
+ };
57
+
58
+ /**
59
+ * The ActionButton component is a wrapper over IconButton to perform an action when the onClick event is triggered.
60
+ *
61
+ * @param {ActionButtonProps} props - The props for the ActionButton component
62
+ * @returns {JSX.Element} ActionButton component
63
+ */
64
+ const ActionButton = ({ type, value, dataTestId, iconSize, disabled }) => {
65
+ const getIconName = () => {
66
+ switch (type) {
67
+ case "PHONE_NUMBER":
68
+ return "PhoneArrowUpRightIcon";
69
+ case "WEB_ADDRESS":
70
+ return "ArrowTopRightOnSquareIcon";
71
+ case "EMAIL":
72
+ default:
73
+ return "EnvelopeIcon";
74
+ }
75
+ };
76
+ const ButtonAction = () => {
77
+ switch (type) {
78
+ case "EMAIL":
79
+ return window.open(`mailto:${value}`);
80
+ case "WEB_ADDRESS":
81
+ if (value) {
82
+ return window.open(value, "_blank", "noopener,noreferrer");
83
+ }
84
+ return null;
85
+ case "PHONE_NUMBER":
86
+ default:
87
+ return window.open(`tel:${value}`);
88
+ }
89
+ };
90
+ return (jsx(ActionContainer, { children: jsx(StyledIconButton, { "$fieldSize": iconSize, disabled: disabled, dataTestId: dataTestId || "testIconButtonId", size: "small", color: "tertiary", icon: jsx(Icon, { size: "small", name: getIconName() }), onClick: ButtonAction }) }));
91
+ };
92
+ const ActionContainer = tw.div `
93
+ tu-action-container
94
+ `;
95
+ const StyledIconButton = twx(IconButton) `
96
+ tu-action-button
97
+ ${({ $fieldSize }) => $fieldSize === "small" && tws `tu-action-button--small`}
98
+ `;
99
+
100
+ /******************************************************************************
101
+ Copyright (c) Microsoft Corporation.
102
+
103
+ Permission to use, copy, modify, and/or distribute this software for any
104
+ purpose with or without fee is hereby granted.
105
+
106
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
107
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
108
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
109
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
110
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
111
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
112
+ PERFORMANCE OF THIS SOFTWARE.
113
+ ***************************************************************************** */
114
+
115
+ function __rest(s, e) {
116
+ var t = {};
117
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
118
+ t[p] = s[p];
119
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
120
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
121
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
122
+ t[p[i]] = s[p[i]];
123
+ }
124
+ return t;
125
+ }
126
+
127
+ function __awaiter(thisArg, _arguments, P, generator) {
128
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
129
+ return new (P || (P = Promise))(function (resolve, reject) {
130
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
131
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
132
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
133
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
134
+ });
135
+ }
136
+
137
+ /**
138
+ * A base input component that can be used for text inputs, password inputs, etc.
139
+ * A reference to the input element is provided as the `ref` prop.
140
+ * Extends props from [React.InputHTMLAttributes](https://reactjs.org/docs/dom-elements.html#input)
141
+ *
142
+ * For specific input types make sure to use the corresponding input component.
143
+ * This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
144
+ */
145
+ const BaseInput = React.forwardRef((_a, ref) => {
146
+ var { className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false } = _a, rest = __rest(_a, ["className", "isInvalid", "dataTestId", "prefix", "suffix", "addonBefore", "addonAfter", "actions", "fieldSize", "nonInteractive"]);
147
+ return (jsxs(InputContainer$1, Object.assign({ "$fieldSize": fieldSize, "$invalid": isInvalid, "$disabled": rest.disabled || rest.readOnly, className: className, "data-testid": dataTestId && `${dataTestId}-container` }, { children: [addonBefore && addonBefore !== undefined ? (jsx(AddonBefore, Object.assign({ "data-testid": dataTestId && `${dataTestId}-addonBefore` }, { children: addonBefore }))) : null, prefix && addonBefore !== prefix ? (jsx(InputPrefix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-prefix` }, { children: prefix }))) : null, jsx("input", Object.assign({ ref: ref, "data-testid": dataTestId, className: tws `tu-input__field` }, rest, { readOnly: rest.readOnly || nonInteractive })), suffix && addonBefore !== suffix ? (jsx(InputSuffix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-suffix` }, { children: suffix }))) : null, actions && addonBefore !== actions ? actions : null, addonAfter && addonAfter !== undefined && addonBefore !== addonAfter ? (jsx(AddonAfter, Object.assign({ "data-testid": dataTestId && `${dataTestId}-addonAfter` }, { children: addonAfter }))) : null] })));
148
+ });
149
+ const InputPrefix = tw.div `
150
+ tu-input__prefix
151
+ `;
152
+ const InputSuffix = tw.div `
153
+ tu-input__suffix
154
+ `;
155
+ const AddonBefore = tw.div `
156
+ tu-input__addon-before
157
+ `;
158
+ const AddonAfter = tw.div `
159
+ tu-input__addon-after
160
+ `;
161
+ const InputContainer$1 = tw.label `
162
+ tu-input
163
+ ${({ $invalid }) => ($invalid ? tws `tu-input--invalid` : null)}
164
+ ${({ $disabled }) => ($disabled ? tws `tu-input--disabled` : null)}
165
+ ${({ $fieldSize }) => ($fieldSize === "small" ? tws `tu-input--small` : null)}
166
+ `;
167
+
168
+ /**
169
+ * The Label component is used for labels for input fields.
170
+ * This component is **not used directly**, but is part of the FormGroup and Field components.
171
+ *
172
+ * @param {LabelProps} props - The props for the Label component
173
+ * @returns {JSX.Element} Label component
174
+ */
175
+ const Label = ({ id, htmlFor, children, className, dataTestId, disabled, isInvalid, }) => {
176
+ return (jsx(Root$2, Object.assign({ id: id || "", htmlFor: htmlFor || "", className: className, "data-testid": dataTestId, "$disabled": disabled, "$isInvalid": isInvalid }, { children: children })));
177
+ };
178
+ const Root$2 = tw.label `
179
+ tu-label
180
+ ${({ $disabled }) => $disabled && tws `tu-label--disabled`}
181
+ ${({ $isInvalid }) => $isInvalid && tws `tu-label--invalid`}
182
+ `;
183
+
184
+ /**
185
+ * The CheckIcon component is used by the checkbox to display the checked state.
186
+ *
187
+ * @param {CheckIconProps} props - The props for the CheckIcon component
188
+ * @returns {JSX.Element} CheckIcon component
189
+ */
190
+ const CheckIcon = ({ className, dataTestId }) => {
191
+ return (jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", className: className, "data-testid": dataTestId, fill: "none", viewBox: "0 0 10 10", stroke: "currentColor", strokeWidth: "2" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m2 5.5 2 2L8.5 3" }) })));
192
+ };
193
+
194
+ /**
195
+ * The IndeterminateIcon component is used by the checkbox to display the Indeterminate state.
196
+ *
197
+ * @param {IndeterminateIconProps} props - The props for the IndeterminateIcon component
198
+ * @returns {JSX.Element} IndeterminateIcon component
199
+ */
200
+ const IndeterminateIcon = ({ className }) => (jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", className: className, fill: "none", viewBox: "0 0 10 10", stroke: "currentColor", strokeWidth: "2" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 5h4" }) })));
201
+
202
+ /**
203
+ * Checkboxes are used when there are multiple items to select in a list. Users can select zero, one, or any number of items.
204
+ *
205
+ * Checkboxes are used for multiple choices, not for mutually exclusive choices. Each checkbox works independently from other checkboxes in the list, therefore checking an additional box does not affect any other selections.
206
+ *
207
+ * _**Do use** checkboxes to allow selection in a form, for filtering, terms and conditions to indicate agreement, and bulk actions in lists or tables._
208
+ *
209
+ * _**Do not use** checkboxes if the user can only select one option from a list, radio buttons should be used instead of checkboxes._
210
+ *
211
+ * @description A reference to the input element is provided as the `ref` prop.
212
+ * @augments props from [React.InputHTMLAttributes](https://reactjs.org/docs/dom-elements.html#input)
213
+ * @param {CheckboxProps} props - The props for the Checkbox component
214
+ * @returns {JSX.Element} Checkbox component
215
+ */
216
+ const Checkbox = React.forwardRef((_a, ref) => {
217
+ var { className, dataTestId, onChange, checked = false, disabled = false, isInvalid = false, readOnly, indeterminate = false, children, label, tabIndex = 0 } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "checked", "disabled", "isInvalid", "readOnly", "indeterminate", "children", "label", "tabIndex"]);
218
+ const icon = indeterminate ? jsx(StyledIndeterminateIcon, {}) : checked && jsx(StyledCheckIcon, {});
219
+ const internalRef = React.useRef(null);
220
+ const isReadonly = disabled || readOnly;
221
+ const onKeyPress = e => {
222
+ var _a;
223
+ if ("Space" === e.code) {
224
+ (_a = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _a === void 0 ? void 0 : _a.click();
225
+ }
226
+ };
227
+ const uuid = rest.id || dataTestId;
228
+ return (jsxs(CheckboxContainer, Object.assign({ "data-testid": dataTestId && `${dataTestId}Container`, htmlFor: uuid, className: className }, { children: [jsx(HiddenInput$1, Object.assign({ type: "checkbox", checked: !indeterminate && checked, onChange: onChange, disabled: disabled, "data-testid": dataTestId, readOnly: readOnly, "aria-checked": !indeterminate && checked, role: "checkbox", id: uuid }, rest, { ref: ref })), jsx(CheckboxWrapper, Object.assign({ id: uuid, "$disabled": isReadonly, "$checked": checked, "$indeterminate": indeterminate, "$isInvalid": isReadonly ? false : isInvalid, tabIndex: isReadonly ? -1 : tabIndex, onKeyPress: onKeyPress }, { children: icon })), label && (jsx(Label, Object.assign({ className: tws `cursor-pointer`, htmlFor: uuid, disabled: isReadonly, isInvalid: isReadonly ? false : isInvalid, dataTestId: dataTestId && `${dataTestId}-Label` }, { children: label }))), children] })));
229
+ });
230
+ const StyledCheckIcon = twx(CheckIcon) `tu-checkbox--icon`;
231
+ const StyledIndeterminateIcon = twx(IndeterminateIcon) `tu-checkbox--icon`;
232
+ const CheckboxContainer = tw.label `tu-checkbox--container group`;
233
+ const HiddenInput$1 = tw.input `tu-checkbox--input`;
234
+ const CheckboxWrapper = tw.span `
235
+ tu-checkbox
236
+ ${({ $checked, $disabled, $indeterminate }) => {
237
+ if ($disabled) {
238
+ return tws `tu-checkbox--disabled`;
239
+ }
240
+ return $indeterminate
241
+ ? tws `tu-checkbox--indeterminate`
242
+ : $checked
243
+ ? tws `tu-checkbox--selected`
244
+ : tws `tu-checkbox--deselected`;
245
+ }}
246
+
247
+ ${({ $isInvalid }) => $isInvalid && tws `tu-checkbox--invalid`}
248
+ `;
249
+
250
+ /**
251
+ * A wrapper around BaseInput with a pop-up day picker.
252
+ *
253
+ * NOTE: If shown with a label, please use the `DateField` component instead.
254
+ */
255
+ const DateInput = forwardRef((_a, ref) => {
256
+ var { min, max, defaultValue, value } = _a, rest = __rest(_a, ["min", "max", "defaultValue", "value"]);
257
+ const formatDateToInputString = (date) => date instanceof Date ? format(date, "yyyy-MM-dd") : date;
258
+ // @ts-ignore
259
+ // Chrome needs it's default icon to have datepicker functionality.
260
+ // window.chrome doesn't exist in TS but is available on chrome browsers.
261
+ // If it fails it will just show our icon.
262
+ const hideOnChrome = () => (window.chrome !== null && typeof window.chrome !== "undefined" ? "hidden" : "");
263
+ return (jsx(BaseInput, Object.assign({ type: "date", value: formatDateToInputString(value), defaultValue: formatDateToInputString(defaultValue), min: formatDateToInputString(min), max: formatDateToInputString(max), ref: ref, suffix: jsx(Icon, { dataTestId: "calendar", name: "CalendarIcon", size: "medium", type: "solid", className: hideOnChrome() }) }, rest)));
264
+ });
265
+
266
+ /**
267
+ * The FormGroup component should be used to wrap any Input element that needs a label.
268
+ * Besides a label the component supplies an optional Tip, HelpText and HelpAddon support.
269
+ *
270
+ * @param {FormGroupProps} props - The props for the FormGroup component
271
+ * @returns {JSX.Element} FormGroup component
272
+ */
273
+ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, disabled = false, }) => {
274
+ return (jsxs(FormGroupRoot, Object.assign({ className: className, "data-testid": dataTestId, "$disabled": disabled }, { children: [jsxs(ContainerBefore, { children: [jsx(FormGroupLabel, Object.assign({ dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label" }, { children: label })), tip && jsx(Tip, Object.assign({ dataTestId: dataTestId && `${dataTestId}-tip` }, { children: tip }))] }), children, jsxs(ContainerAfter, Object.assign({ "$isInvalid": isInvalid }, { children: [helpText && jsx("span", Object.assign({ "data-testid": dataTestId && `${dataTestId}-helpText` }, { children: helpText })), helpAddon && jsx(HelpAddon, Object.assign({ "data-testid": dataTestId && `${dataTestId}-helpAddon` }, { children: helpAddon }))] }))] })));
275
+ };
276
+ const FormGroupRoot = tw.div `
277
+ tu-form-group
278
+ ${({ $disabled }) => {
279
+ return $disabled ? "pointer-events-none" : null;
280
+ }}
281
+ `;
282
+ const ContainerBefore = tw.div `
283
+ tu-form-group__container-before
284
+ `;
285
+ const FormGroupLabel = twx(Label) `
286
+ component-formGroup-font
287
+ `;
288
+ const ContainerAfter = tw.div `
289
+ tu-form-group__container-after
290
+ ${({ $isInvalid }) => ($isInvalid ? tws `tu-form-group__container-after--invalid` : null)}
291
+ `;
292
+ const HelpAddon = tw.span `
293
+ tu-form-group__help-addon
294
+ `;
295
+
296
+ /**
297
+ * The date field component is used for entering date values.
298
+ *
299
+ * _**Do use**_ the DateField for date input.
300
+ *
301
+ * _**Do not use**_ this fields for non-serialized dates. Use TextField instead.
302
+ */
303
+ const DateField = forwardRef((_a, ref) => {
304
+ var { label, id, tip, helpText, errorMessage, helpAddon, isInvalid, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "className", "defaultValue", "dataTestId"]);
305
+ const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
306
+ const htmlForId = id ? id : "dateField-" + v4();
307
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(DateInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, defaultValue: defaultValue, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
308
+ });
309
+
310
+ /**
311
+ * The Drop Zone can be used to drag and drop files
312
+ *
313
+ * @param {DropZoneProps} props - The props for the DropZone component
314
+ * @returns {JSX.Element} DropZone component
315
+ */
316
+ const DropZone = (_a) => {
317
+ var { className, dataTestId, filesSelected, label, size = "large", isInvalid = false, disabled = false } = _a, rest = __rest(_a, ["className", "dataTestId", "filesSelected", "label", "size", "isInvalid", "disabled"]);
318
+ const [dragActive, setDragActive] = React__default.useState(false);
319
+ const [fileDropped, setFileDropped] = React__default.useState(false);
320
+ // function that handles drag enter, drag leave and drag over
321
+ const handleDrag = (e) => {
322
+ e.preventDefault();
323
+ e.stopPropagation();
324
+ if ((e.type === "dragenter" || e.type === "dragover") && !disabled) {
325
+ setDragActive(true);
326
+ }
327
+ else if (e.type === "dragleave") {
328
+ setDragActive(false);
329
+ }
330
+ };
331
+ //function to handle when user clicks on dropzone to upload
332
+ const handleChange = (e) => {
333
+ e.preventDefault();
334
+ e.stopPropagation();
335
+ if (e.target.files && !disabled) {
336
+ filesSelected(e.target.files);
337
+ }
338
+ };
339
+ //funtion to handle drop
340
+ const handleDrop = (e) => {
341
+ e.preventDefault();
342
+ e.stopPropagation();
343
+ setDragActive(false);
344
+ if (e.dataTransfer.files && e.dataTransfer.files[0] && !disabled) {
345
+ filesSelected(e.dataTransfer.files);
346
+ setFileDropped(true);
347
+ }
348
+ };
349
+ return (jsxs(Root$1, Object.assign({ "$disabled": disabled, "$isInvalid": isInvalid, "$dragActive": dragActive, "$fileDropped": fileDropped, "$size": size, className: className, "data-testid": dataTestId, onDragEnter: handleDrag, onDragLeave: handleDrag, onDragOver: handleDrag, onDrop: handleDrop, onClick: e => {
350
+ if (disabled) {
351
+ e.preventDefault();
352
+ e.stopPropagation();
353
+ }
354
+ } }, rest, { children: [jsx("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxs(DropZoneLabel, Object.assign({ htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label` }, { children: [jsx(Icon, { type: "solid", name: "ArrowUpCircleIcon", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsx("span", { children: label })] }))] })));
355
+ };
356
+ const Root$1 = tw.div `
357
+ tu-drop-zone
358
+ ${({ $size }) => ($size === "small" ? tws `tu-drop-zone--small` : null)}
359
+ ${({ $size }) => ($size === "medium" ? tws `tu-drop-zone--medium` : null)}
360
+ ${({ $size }) => ($size === "large" ? tws `tu-drop-zone--large` : null)}
361
+ ${({ $dragActive }) => ($dragActive ? tws `tu-drop-zone--drag-active` : null)}
362
+ ${({ $fileDropped }) => ($fileDropped ? tws `tu-drop-zone--drop-complete` : null)}
363
+ ${({ $isInvalid }) => ($isInvalid ? tws `tu-drop-zone--invalid` : null)}
364
+ ${({ $disabled }) => ($disabled ? tws `tu-drop-zone--disabled` : null)}
365
+ `;
366
+ const DropZoneLabel = tw.label `
367
+ tu-drop-zone__label
368
+ `;
369
+
370
+ /**
371
+ * A Email Input component is used for input of the type Email.
372
+ *
373
+ * It has an ActionButton which sends an email to the specified address using "mailto:" link.
374
+ *
375
+ * Extends props of BaseInput.
376
+ *
377
+ * A reference to the input element is provided as the `ref` prop.
378
+ * For specific input types make sure to use the corresponding input component.
379
+ */
380
+ const EmailInput = React.forwardRef((_a, ref) => {
381
+ var { fieldSize = "medium", disabled = false, dataTestId } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId"]);
382
+ const [email, setEmail] = React.useState("");
383
+ const sendEmail = () => {
384
+ return window.open(`mailto:${email}`);
385
+ };
386
+ return (jsx(BaseInput, Object.assign({ dataTestId: dataTestId, fieldSize: fieldSize, ref: ref, type: "email", placeholder: rest.placeholder || "mail@example.com", onChange: e => setEmail(e.target.value) }, rest, { actions: jsx(ActionButton, { disabled: disabled, value: email, type: "EMAIL", onClick: sendEmail, dataTestId: dataTestId && `${dataTestId}-emailIcon`, iconSize: fieldSize }) })));
387
+ });
388
+
389
+ /**
390
+ * The EmailField component is used to enter email.
391
+ * EmailField validates that user enters a valid email address.
392
+ *
393
+ */
394
+ const EmailField = forwardRef((_a, ref) => {
395
+ var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId"]);
396
+ const [value, setValue] = useState(defaultValue);
397
+ const htmlForId = id ? id : "emailField-" + v4();
398
+ // Type guard to check if value is a string
399
+ function isString(inputValue) {
400
+ return typeof inputValue === "string";
401
+ }
402
+ // Check the regular expression only if value is a string
403
+ const renderAsInvalid = !!errorMessage || (isString(value) && !/^\S+@\S+\.\S+$/.test(value));
404
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(EmailInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, value: value, onChange: e => setValue(e.target.value), isInvalid: renderAsInvalid, disabled: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
405
+ });
406
+
407
+ /**
408
+ * A thin wrapper around the `BaseInput` component for number input fields.
409
+ *
410
+ * NOTE: If shown with a label, please use the `NumberField` component instead.
411
+ */
412
+ const NumberInput = forwardRef((props, ref) => (jsx(BaseInput, Object.assign({ ref: ref, type: "number" }, props))));
413
+
414
+ /**
415
+ * The number field component is used for entering numeric values and includes controls for incrementally increasing or decreasing the value.
416
+ *
417
+ * _**Do use**_ the NumberField when the controls to incrementally increase or decrease makes the task easier for the user.
418
+ *
419
+ * _**Do not use**_ this fields for non-serialized numbers. Use TextField instead.
420
+ */
421
+ const NumberField = forwardRef((_a, ref) => {
422
+ var { label, id, tip, helpText, errorMessage, helpAddon, isInvalid, maxLength, className, value, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "maxLength", "className", "value", "dataTestId"]);
423
+ const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
424
+ const htmlForId = id ? id : "numberField-" + v4();
425
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(NumberInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
426
+ });
427
+
428
+ /**
429
+ * @param {MultiValue<Option> | SingleValue<Option>} arg option to check type
430
+ * @returns {arg is MultiValue<Option> } is Multivalue
431
+ */
432
+ function isMultiValue(arg) {
433
+ return Array.isArray(arg);
434
+ }
435
+ function isGroupBase(arg) {
436
+ return arg.options !== undefined;
437
+ }
438
+ const isSelectedOption = (option, selected) => {
439
+ if (isGroupBase(option)) {
440
+ return false;
441
+ }
442
+ return isMultiValue(selected)
443
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
444
+ selected.some(v => v.value === option.value)
445
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
446
+ option.value === (selected === null || selected === void 0 ? void 0 : selected.value);
447
+ };
448
+ const removeSelectedFromGroups = (group, selected) => {
449
+ if (isGroupBase(group)) {
450
+ return Object.assign(Object.assign({}, group), { options: group.options.filter(option => !isSelectedOption(option, selected)) });
451
+ }
452
+ return group;
453
+ };
454
+ /**
455
+ * @template IsMulti
456
+ * @template Group
457
+ * @param {OptionsOrGroups<Option, Group> | undefined} options An array of options to select from
458
+ * @param {PropsValue<Option> | undefined} value Selected values
459
+ * @returns {OptionsOrGroups<Option, Group>} An array of ordered options with selected on top
460
+ */
461
+ const getOrderedOptions = (options, value) => {
462
+ if (value && options) {
463
+ const orderedValues = isMultiValue(value)
464
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
465
+ [...value].sort((a, b) => a.label.localeCompare(b.label))
466
+ : [value];
467
+ const selectableOptions = options
468
+ .filter(option => !isSelectedOption(option, value))
469
+ .map(option => removeSelectedFromGroups(option, value));
470
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
471
+ return orderedValues.concat(selectableOptions) || [];
472
+ }
473
+ return options || [];
474
+ };
475
+ const SelectPrefix = tw.div `
476
+ tu-select__prefix
477
+ `;
478
+
479
+ /**
480
+ * A single select menu item is a basic wrapper around Menu item designed to be used as a single value render in Select list
481
+ *
482
+ * @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
483
+ * @returns {JSX.Element} SingleSelectMenuItem
484
+ */
485
+ const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, focused, disabled, }) => {
486
+ return (jsx(MenuItem, { dataTestId: dataTestId, label: label, prefix: icon, onClick: onClick, selected: selected, disabled: disabled, focused: focused, suffix: selected ? jsx(Icon, { name: "CheckIcon", size: "small" }) : undefined }));
487
+ };
488
+ /**
489
+ * A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
490
+ *
491
+ * @param {SelectMenuItemProps} props - The props for the MultiSelectMenuItem
492
+ * @returns {JSX.Element} multi select menu item
493
+ */
494
+ const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, focused, disabled, }) => {
495
+ return (jsx(MenuItem, { dataTestId: dataTestId, label: label, disabled: disabled, prefix: jsx(Checkbox, { checked: selected, readOnly: false, onChange: () => null, disabled: disabled, onClick: e => {
496
+ e.stopPropagation();
497
+ } }), onClick: e => {
498
+ e.stopPropagation();
499
+ onClick && onClick(e);
500
+ }, selected: selected, focused: focused }));
501
+ };
502
+
503
+ /**
504
+ * Extended Tag component with information about its own width.
505
+ * Used in the select component.
506
+ *
507
+ * @param {TagProps} props - The props for the tag component
508
+ * @returns {JSX.Element} TagWithWidth component
509
+ */
510
+ const TagWithWidth = (_a) => {
511
+ var { onWidthKnown, children } = _a, rest = __rest(_a, ["onWidthKnown", "children"]);
512
+ const ref = React__default.useRef(null);
513
+ React__default.useLayoutEffect(() => {
514
+ var _a;
515
+ onWidthKnown && onWidthKnown({ width: ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0 });
516
+ }, [ref, onWidthKnown]);
517
+ return (jsx(Tag, Object.assign({ ref: ref }, rest, { children: children })));
518
+ };
519
+
520
+ /**
521
+ * TagsContainer component to display tags in limited space when children can't fit space it displays counter
522
+ *
523
+ * @param {TagsContainerProps} props - The props for the TagContainer
524
+ * @returns {JSX.Element} TagsContainer
525
+ */
526
+ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix }) => {
527
+ const [isReady, setIsReady] = React__default.useState(false);
528
+ const [counterWidth, setCounterWidth] = React__default.useState(0);
529
+ const containerRef = React__default.useRef(null);
530
+ const availableWidth = React__default.useRef();
531
+ const childrenWidth = React__default.useRef([]);
532
+ const itemsCount = items.length;
533
+ React__default.useLayoutEffect(() => {
534
+ var _a;
535
+ availableWidth.current = ((_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
536
+ }, [containerRef]);
537
+ const onWidthKnownHandler = ({ width: reportedWidth }) => {
538
+ childrenWidth.current.push({ width: reportedWidth + itemsGap });
539
+ if (childrenWidth.current.length === itemsCount) {
540
+ setIsReady(true);
541
+ }
542
+ };
543
+ const requiredSpace = childrenWidth.current.reduce((previous, current) => {
544
+ return previous + current.width;
545
+ }, 0);
546
+ let counter = 0;
547
+ const availableSpace = ((availableWidth === null || availableWidth === void 0 ? void 0 : availableWidth.current) || 0) - counterWidth;
548
+ const renderedElements = items
549
+ .concat({ text: "", onClick: () => null, disabled: false }) // reserved element for a potential counter
550
+ .map((item, index) => {
551
+ const spaceNeeded = childrenWidth.current.slice(0, index + 1).reduce((previous, current) => {
552
+ return previous + current.width;
553
+ }, 0);
554
+ const isLast = index === items.length;
555
+ const counterRequired = requiredSpace > availableSpace && counter !== 0;
556
+ if (isLast && counterRequired) {
557
+ return (jsx(TagWithWidth, Object.assign({ onWidthKnown: ({ width: reportedWidth }) => setCounterWidth(reportedWidth), color: "neutral" }, { children: jsxs(Counter, { children: ["+", counter] }) }), item.text + index));
558
+ }
559
+ if (isLast) {
560
+ return null;
561
+ }
562
+ const itemCanFit = spaceNeeded <= availableSpace;
563
+ if (itemCanFit) {
564
+ return (jsx(TagWithWidth, Object.assign({ onWidthKnown: onWidthKnownHandler, className: tws `shrink-0 inline-flex`, onClose: e => {
565
+ e.stopPropagation();
566
+ item.onClick();
567
+ }, color: item.disabled ? "unknown" : "primary", dataTestId: item.text }, { children: item.text }), item.text + index));
568
+ }
569
+ const fromTheItems = item.text !== "";
570
+ if (fromTheItems) {
571
+ counter = counter + 1;
572
+ }
573
+ return null;
574
+ })
575
+ .filter(element => element !== null);
576
+ return (jsxs(Container$2, Object.assign({ style: {
577
+ width: `${width}`,
578
+ }, "$ready": isReady, ref: containerRef }, { children: [renderedElements, postFix] })));
579
+ };
580
+ const Container$2 = tw.div `
581
+ tu-select__dynamic-tag--container
582
+ ${({ $ready }) => {
583
+ return $ready ? tws `visible` : tws `invisible`;
584
+ }}
585
+ `;
586
+ const Counter = tw.div `
587
+ tu-select__counter
588
+ `;
589
+
590
+ /**
591
+ * A hook to retrieve components override object.
592
+ * This complex object includes all the compositional components that are used in react-select. If you wish to overwrite a component, pass in an object with the appropriate namespace.
593
+ *
594
+ * @template IsMulti
595
+ * @template Group
596
+ * @param {Partial<SelectComponents<Option, IsMulti, Group>> | undefined} componentsProps a custom component prop that you can to override defaults
597
+ * @param {boolean} disabled decide to override disabled variant
598
+ * @param {boolean} menuIsOpen menu is open state
599
+ * @param {React.MutableRefObject<boolean>} refMenuIsEnabled a flag to block menu from open
600
+ * @param {string} dataTestId a test id
601
+ * @param {number} maxSelectedDisplayCount a number of max display count
602
+ * @param {JSX.Element} dropdownIcon an custom dropdown icon
603
+ * @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
604
+ */
605
+ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon) => {
606
+ // perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
607
+ const customComponents = React.useMemo(() => {
608
+ return Object.assign({ ValueContainer: props => {
609
+ if (props.isMulti) {
610
+ const PLACEHOLDER_KEY = "placeholder";
611
+ const key = props && props.children && props.children[0] ? props.children[0].key : "";
612
+ const values = props && props.children ? props.children[0] : [];
613
+ const tags = key === PLACEHOLDER_KEY ? [] : values;
614
+ const searchInput = props && props.children && props.children[1];
615
+ return (jsx(components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled }, { children: maxSelectedDisplayCount === undefined ? (jsx(TagsContainer, { width: "100%", items: tags
616
+ ? tags.map(({ props: tagProps }) => {
617
+ return {
618
+ text: tagProps.children,
619
+ onClick: disabled
620
+ ? undefined
621
+ : (e) => {
622
+ var _a, _b;
623
+ refMenuIsEnabled.current = false;
624
+ ((_a = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _a === void 0 ? void 0 : _a.onClick) && ((_b = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _b === void 0 ? void 0 : _b.onClick(e));
625
+ },
626
+ disabled: disabled,
627
+ };
628
+ })
629
+ : [], postFix: searchInput })) : (jsxs(Fragment, { children: [tags &&
630
+ tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
631
+ var _a, _b;
632
+ return (jsx(Tag, Object.assign({ className: tws `shrink-0 inline-flex`, onClose: e => {
633
+ var _a, _b;
634
+ e.stopPropagation();
635
+ refMenuIsEnabled.current = false;
636
+ ((_a = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _a === void 0 ? void 0 : _a.onClick) && ((_b = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _b === void 0 ? void 0 : _b.onClick(e));
637
+ }, color: disabled ? "unknown" : "primary", dataTestId: (_a = tagProps.children) === null || _a === void 0 ? void 0 : _a.toString() }, { children: tagProps.children }), (_b = tagProps.children) === null || _b === void 0 ? void 0 : _b.toString()));
638
+ }), tags && tags.length > maxSelectedDisplayCount && (jsxs(Tag, Object.assign({ color: "neutral", dataTestId: "counter" }, { children: ["+", tags.length - maxSelectedDisplayCount] }))), searchInput] })) })));
639
+ }
640
+ return (jsx(components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled }, { children: props.children })));
641
+ }, LoadingIndicator: props => {
642
+ return jsx(Spinner, { size: "small", className: tws `mt-1.5 mr-1` });
643
+ }, DropdownIndicator: props => {
644
+ const icon = props.selectProps.menuIsOpen ? (jsx(Icon, { name: "ChevronUpIcon", size: "medium" })) : (jsx(Icon, { name: "ChevronDownIcon", size: "medium" }));
645
+ return props.selectProps.isLoading ? null : (jsx(components.DropdownIndicator, Object.assign({}, props, { children: jsx(StyledIcon, { children: dropdownIcon ? dropdownIcon : icon }) })));
646
+ }, IndicatorSeparator: () => null, ClearIndicator: props => {
647
+ if (disabled) {
648
+ return null;
649
+ }
650
+ return (jsx(components.ClearIndicator, Object.assign({}, props, { children: jsx(XMarkIcon, Object.assign({ onClick: props.clearValue, "data-testid": dataTestId && `${dataTestId}-XMarkIcon` }, { children: jsx(Icon, { name: "XCircleIcon", size: "medium" }) })) })));
651
+ }, Control: props => {
652
+ return (jsx(components.Control, Object.assign({}, props, { className: props.isDisabled ? tws `tu-select__control--disabled` : "" })));
653
+ }, SingleValue: props => {
654
+ return (jsx(components.SingleValue, Object.assign({}, props, { className: props.isDisabled ? tws `tu-select__single-value--disabled` : "" }, { children: jsx("div", Object.assign({ "data-testid": dataTestId + "-singleValue" }, { children: props.children })) })));
655
+ }, Menu: props => {
656
+ return (jsx(components.Menu, Object.assign({}, props, { className: props.selectProps.menuIsOpen
657
+ ? tws `tu-select__menu-list animate-fade-in-fast`
658
+ : tws `tu-select__menu-list animate-fade-out-fast` })));
659
+ }, Option: props => {
660
+ const componentProps = {
661
+ label: props.label,
662
+ focused: props.isFocused,
663
+ selected: props.isSelected,
664
+ onClick: props.innerProps.onClick,
665
+ };
666
+ return (jsx(components.Option, Object.assign({}, props, { innerProps: Object.assign(Object.assign({}, props.innerProps), { role: "option", onClick: () => { } }) }, { children: props.isMulti ? (jsx(MultiSelectMenuItem, Object.assign({}, componentProps, { disabled: disabled, dataTestId: props.label }))) : (jsx(SingleSelectMenuItem, Object.assign({}, componentProps, { disabled: disabled || props.isDisabled, dataTestId: props.label }))) })));
667
+ } }, componentsProps);
668
+ // eslint-disable-next-line react-hooks/exhaustive-deps
669
+ }, [componentsProps, disabled, maxSelectedDisplayCount]); // do not add dropdownIcon (it will cause issue with opening/closing list for selects with custom icon)
670
+ return customComponents;
671
+ };
672
+ const StyledIcon = tw.div `
673
+ tu-select--icon
674
+ `;
675
+ const XMarkIcon = tw.div `
676
+ tu-select--icon
677
+ tu-select__x-icon
678
+ `;
679
+
680
+ /**
681
+ * @template IsMulti
682
+ * @template Group
683
+ * @param {React.RefObject<HTMLDivElement>} refContainer react ref to container element
684
+ * @param {React.RefObject<HTMLDivElement>} refPrefix react ref to prefix element
685
+ * @param {number | undefined} maxSelectedDisplayCount a number of max display count
686
+ * @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
687
+ * @returns {StylesConfig<Option, boolean>} styles to override in select
688
+ */
689
+ const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles) => {
690
+ const customStyles = React.useMemo(() => {
691
+ return Object.assign({ control: base => {
692
+ return Object.assign(Object.assign({}, base), { border: "0", boxShadow: "0", "&:hover": {
693
+ border: "0",
694
+ }, marginRight: "2px", backgroundColor: "" });
695
+ }, singleValue: base => (Object.assign({}, base)), multiValue: base => (Object.assign({}, base)), multiValueLabel: base => (Object.assign({}, base)), indicatorsContainer: base => (Object.assign({}, base)), indicatorSeparator: () => ({
696
+ width: "0px",
697
+ }), menu: base => {
698
+ return Object.assign(Object.assign({}, base), { width: "100%", marginTop: "4px", marginBottom: "18px", transition: "all 1s ease-in-out" });
699
+ }, input: base => (Object.assign(Object.assign({}, base), { marginLeft: "0px" })), placeholder: base => (Object.assign({}, base)), option: () => ({}), menuPortal: base => (Object.assign(Object.assign({}, base), { width: (refContainer === null || refContainer === void 0 ? void 0 : refContainer.current) ? `${refContainer.current.clientWidth}px` : base.width, transform: (refPrefix === null || refPrefix === void 0 ? void 0 : refPrefix.current) ? `translate(-${refPrefix.current.clientWidth + 2}px)` : "translate(-2px)", backgroundColor: "#ffffff", borderRadius: "var(--border-radius-lg)", zIndex: 20, borderColor: "rgb(var(--color-slate-300))", boxShadow: "var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)" })), menuList: base => {
700
+ return Object.assign(Object.assign({}, base), { position: "relative", padding: "var(--spacing-1)", display: "grid", gap: "var(--spacing-1)", width: "100%", borderRadius: "0px", boxShadow: "none", paddingTop: "0px" });
701
+ }, valueContainer: base => {
702
+ return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
703
+ }, container: base => (Object.assign(Object.assign({}, base), { border: "none", width: "calc(100% - 2px)", paddingLeft: "2px" })), dropdownIndicator: base => (Object.assign(Object.assign({}, base), { padding: "0px" })), clearIndicator: base => {
704
+ return Object.assign(Object.assign({}, base), { padding: "0px" });
705
+ } }, styles);
706
+ // eslint-disable-next-line react-hooks/exhaustive-deps
707
+ }, [refContainer, refPrefix]);
708
+ return { customStyles };
709
+ };
710
+
711
+ /**
712
+ * A hook used by selects to share the common code
713
+ *
714
+ * @param {SelectProps} props - The props for the Select component
715
+ * @returns {IUseSelect} Select component
716
+ */
717
+ const useSelect = (_a) => {
718
+ var _b;
719
+ var { id, className, dataTestId = "select", prefix, async, dropdownIcon, maxMenuHeight = 200, label, hasError, disabled, isMulti, components, value, options, onChange, isLoading, classNamePrefix = "", onMenuOpen, onMenuClose, maxSelectedDisplayCount = undefined, isClearable = false, isSearchable = true, onMenuScrollToBottom, styles, filterOption, onInputChange } = _a, props = __rest(_a, ["id", "className", "dataTestId", "prefix", "async", "dropdownIcon", "maxMenuHeight", "label", "hasError", "disabled", "isMulti", "components", "value", "options", "onChange", "isLoading", "classNamePrefix", "onMenuOpen", "onMenuClose", "maxSelectedDisplayCount", "isClearable", "isSearchable", "onMenuScrollToBottom", "styles", "filterOption", "onInputChange"]);
720
+ const refContainer = React__default.useRef(null);
721
+ const refPrefix = React__default.useRef(null);
722
+ const { customStyles } = useCustomStyles(refContainer, refPrefix, maxSelectedDisplayCount, styles);
723
+ const [menuIsOpen, setMenuIsOpen] = React__default.useState((_b = props.menuIsOpen) !== null && _b !== void 0 ? _b : false);
724
+ const refMenuIsEnabled = React__default.useRef(true);
725
+ const customComponents = useCustomComponents(components, disabled || false, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon);
726
+ const menuPlacement = "auto";
727
+ const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
728
+ onMenuOpen && onMenuOpen();
729
+ if (refMenuIsEnabled.current) {
730
+ setMenuIsOpen(true);
731
+ }
732
+ else {
733
+ refMenuIsEnabled.current = true;
734
+ }
735
+ });
736
+ const closeMenuHandler = () => {
737
+ setMenuIsOpen(false);
738
+ onMenuClose && onMenuClose();
739
+ };
740
+ const orderedOptions = React__default.useMemo(() => {
741
+ return disabled
742
+ ? getOrderedOptions(options, value).map(option => {
743
+ return Object.assign(Object.assign({}, option), { disabled: true });
744
+ })
745
+ : getOrderedOptions(options, value);
746
+ }, [options, value, disabled]);
747
+ return {
748
+ refContainer,
749
+ refPrefix,
750
+ customStyles,
751
+ menuIsOpen,
752
+ customComponents,
753
+ menuPlacement,
754
+ openMenuHandler,
755
+ closeMenuHandler,
756
+ orderedOptions,
757
+ };
758
+ };
759
+
760
+ /**
761
+ * Selects are input components used to choose a value from a set.
762
+ *
763
+ * @param {SelectProps} props - The props for the Select component
764
+ * @returns {JSX.Element} Select component
765
+ */
766
+ const Select = (props) => {
767
+ const { className } = props, propsNoClassName = __rest(props, ["className"]);
768
+ const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable, } = props;
769
+ const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
770
+ const selectProps = {
771
+ value,
772
+ menuPlacement,
773
+ maxMenuHeight,
774
+ onChange,
775
+ "aria-label": label,
776
+ "data-testid": dataTestId,
777
+ components: customComponents,
778
+ styles: customStyles,
779
+ tabSelectsValue: false,
780
+ blurInputOnSelect: !isMulti,
781
+ menuPortalTarget: props.menuPortalTarget || document.body,
782
+ isSearchable: disabled ? false : isSearchable,
783
+ menuShouldBlockScroll: true,
784
+ menuShouldScrollIntoView: true,
785
+ openMenuOnFocus: true,
786
+ menuIsOpen,
787
+ openMenuOnClick: true,
788
+ closeMenuOnSelect: false,
789
+ isMulti,
790
+ classNamePrefix,
791
+ isLoading,
792
+ isClearable,
793
+ id,
794
+ onMenuScrollToBottom,
795
+ onInputChange,
796
+ };
797
+ return (jsxs(SelectContainer$1, Object.assign({ ref: refContainer, className: className, "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": disabled }, { children: [prefix !== undefined && (jsx(SelectPrefix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix }, { children: prefix }))), async ? (jsx(ReactAsyncSelect, Object.assign({}, propsNoClassName, selectProps, async, { onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler }))) : (jsx(ReactSelect, Object.assign({}, propsNoClassName, selectProps, { options: filterOption ? orderedOptions : options, hideSelectedOptions: false, isMulti: isMulti, onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler })))] })));
798
+ };
799
+ const SelectContainer$1 = tw.div `
800
+ tu-select
801
+ ${({ $hasError }) => ($hasError ? tws `tu-select--invalid` : null)}
802
+ ${({ $isDisabled }) => ($isDisabled ? tws `tu-select--disabled` : null)}
803
+ `;
804
+ Select.displayName = "Select";
805
+
806
+ const COUNTRY_CODES_NOT_SUPPORTED_BY_BACKEND = ["53", "98", "211", "247", "249", "383", "850", "963"];
807
+ const ADDITIONAL_COUNTRY_CODES_SUPPORTED_BY_BACKEND = [
808
+ "1242",
809
+ "1246",
810
+ "1264",
811
+ "1268",
812
+ "1284",
813
+ "1340",
814
+ "1345",
815
+ "1441",
816
+ "1473",
817
+ "1649",
818
+ "1664",
819
+ "1670",
820
+ "1671",
821
+ "1684",
822
+ "1721",
823
+ "1758",
824
+ "1767",
825
+ "1784",
826
+ "1809",
827
+ "1868",
828
+ "1869",
829
+ "1876",
830
+ "379",
831
+ "5999",
832
+ "881",
833
+ "882",
834
+ "883",
835
+ ];
836
+ const countryCodesSet = [
837
+ ...new Set(getCountries().map(code => getCountryCallingCode(code))),
838
+ ...ADDITIONAL_COUNTRY_CODES_SUPPORTED_BY_BACKEND,
839
+ ]
840
+ .filter(code => !COUNTRY_CODES_NOT_SUPPORTED_BY_BACKEND.includes(code))
841
+ .sort((a, b) => Number(a) - Number(b));
842
+ const countryCodes = countryCodesSet.map(code => ({ label: `+${code}`, value: code }));
843
+
844
+ /**
845
+ * The CountryCodeSelect component is used to select a country code for a phone number.
846
+ *
847
+ * @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
848
+ * @returns {JSX.Element} CountryCodeSelect component
849
+ */
850
+ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, setCountryCode, }) => {
851
+ const [isCountryCodeMissing, setIsCountryCodeMissing] = useState(false);
852
+ useEffect(() => {
853
+ countryCode && setIsCountryCodeMissing(false);
854
+ }, [countryCode]);
855
+ const filteredCodes = countryCodes.filter(code => {
856
+ return !(excludedCountries === null || excludedCountries === void 0 ? void 0 : excludedCountries.some(excludedCode => excludedCode.value === code.value));
857
+ });
858
+ return (jsx(Select, { className: "w-28", "aria-invalid": isCountryCodeMissing, options: filteredCodes.map(code => code), value: filteredCodes.find(({ value: currentValue }) => currentValue === countryCode), onChange: input => {
859
+ setCountryCode(input === null || input === void 0 ? void 0 : input.value);
860
+ }, placeholder: "+45", hasError: isCountryCodeMissing || isInvalid, maxMenuHeight: 200 }));
861
+ };
862
+
863
+ /**
864
+ * A component for inputting phone numbers with an optional action button for initiating a phone call.
865
+ *
866
+ * @param {string} [dataTestId] - The data test ID for the component.
867
+ * @param {boolean} [disabled=false] - Whether the component is disabled or not.
868
+ * @param {string} [fieldSize="medium"] - The size of the input field.
869
+ * @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
870
+ * @returns {JSX.Element} - The PhoneInput component.
871
+ */
872
+ const PhoneInput = forwardRef((_a, ref) => {
873
+ var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction"]);
874
+ const [phoneNumber, setPhoneNumber] = useState();
875
+ const [renderAsInvalid, setRenderAsInvalid] = useState(false);
876
+ const [countryCode, setCountryCode] = useState(undefined);
877
+ const [isPhoneNumberInvalid, setIsPhoneNumberInvalid] = useState(false);
878
+ const handlePhoneNumberChange = (e) => {
879
+ const input = e.target.value;
880
+ setIsPhoneNumberInvalid(!Boolean(input));
881
+ setPhoneNumber(input);
882
+ };
883
+ useEffect(() => {
884
+ setRenderAsInvalid(isInvalid || isPhoneNumberInvalid);
885
+ }, [isInvalid, isPhoneNumberInvalid]);
886
+ return (jsxs(Container$1, { children: [jsx(CountryCodeSelect, { isInvalid: renderAsInvalid, countryCode: countryCode, setCountryCode: setCountryCode }), jsx(BaseInput, Object.assign({ ref: ref, dataTestId: dataTestId, isInvalid: renderAsInvalid, fieldSize: fieldSize, type: "tel", value: phoneNumber, onChange: handlePhoneNumberChange, disabled: disabled, actions: !disableAction && (jsx(ActionButton, { disabled: !countryCode || !phoneNumber || disabled || renderAsInvalid, value: `${countryCode}${phoneNumber}`, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
887
+ });
888
+ const Container$1 = tw.div `
889
+ grid
890
+ grid-cols-min-fr
891
+ gap-2
892
+ `;
893
+
894
+ /**
895
+ * The PhoneField component is used to enter phone number.
896
+ * It is a wrapper around the PhoneInput component and the FormGroup component.
897
+ * It is used to render a phone number field with a label, a tip, a help text, a help addon and an error message.
898
+ *
899
+ * @param {string} [label] - The label for the component.
900
+ * @param {string} [tip] - The tip for the component.
901
+ * @param {string} [helpText] - The help text for the component.
902
+ * @param {string} [helpAddon] - The help addon for the component.
903
+ * @param {string} [errorMessage] - The error message for the component.
904
+ * @param {string} [defaultValue] - The default value for the component.
905
+ * @param {boolean} [disabled=false] - Whether the component is disabled or not.
906
+ * @param {string} [fieldSize="medium"] - The size of the input field.
907
+ * @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
908
+ * @returns {JSX.Element} - The PhoneField component.
909
+ */
910
+ const PhoneField = forwardRef((_a, ref) => {
911
+ var { label, id, tip, helpText, isInvalid, errorMessage, value, helpAddon, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "isInvalid", "errorMessage", "value", "helpAddon", "className", "defaultValue", "dataTestId"]);
912
+ const renderAsInvalid = isInvalid || Boolean(errorMessage);
913
+ const htmlForId = id ? id : "phoneField-" + v4();
914
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: value || defaultValue, isInvalid: renderAsInvalid }, rest)) })));
915
+ });
916
+
917
+ const RadioGroupContext = React.createContext(null);
918
+
919
+ /**
920
+ * Use radio buttons when you have a group of mutually exclusive choices and only one selection from the group is allowed.
921
+ *
922
+ * Radio buttons are used for mutually exclusive choices, not for multiple choices. Only one radio button can be selected at a time. When a user chooses a new item, the previous choice is automatically deselected.
923
+ *
924
+ * _**Do use** Radio buttons in forms, settings, or selections in a list._
925
+ *
926
+ * _**Do not use** Radio buttons if a user can select many option from a list, use checkboxes instead of radio buttons._
927
+ *
928
+ * @param {RadioGroupProps} props - The props for the RadioGroup component
929
+ * @returns {JSX.Element} RadioGroup component
930
+ */
931
+ const RadioGroup = ({ children, id, name, value, disabled, onChange, label, inline, className, dataTestId, isInvalid, }) => {
932
+ return (jsx(FormGroup, Object.assign({ label: label, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(Flex, Object.assign({ "$inline": inline, className: className, "data-testid": dataTestId }, { children: jsx(RadioGroupContext.Provider, Object.assign({ value: {
933
+ id,
934
+ value,
935
+ name: name || id,
936
+ onChange,
937
+ disabled,
938
+ isInvalid,
939
+ } }, { children: children })) })) })));
940
+ };
941
+ RadioGroup.displayName = "RadioGroup";
942
+ const Flex = tw.div `
943
+ ${({ $inline }) => ($inline ? tws `tu-radiogroup--inline` : tws `tu-radiogroup`)}
944
+ `;
945
+
946
+ /**
947
+ * The RadioItem component.
948
+ *
949
+ * @param {RadioItemProps} props - The props for the RadioItem component
950
+ * @returns {JSX.Element} RadioItem component
951
+ */
952
+ const RadioItem = ({ label, value, dataTestId, className, description }) => {
953
+ const groupCtx = React.useContext(RadioGroupContext);
954
+ const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
955
+ return (jsxs(InputWrapper, Object.assign({ className: className, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, "data-testid": dataTestId && `${dataTestId}-Wrapper` }, { children: [jsx(Input, { id: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, type: "radio", role: "radio", value: value, checked: isChecked, "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled, "$isInvalid": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, "data-testid": dataTestId, "$checked": isChecked }), jsxs(LabelContainer$1, { children: [jsx(Label, Object.assign({ htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, dataTestId: dataTestId && `${dataTestId}-Label`, disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled, isInvalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid }, { children: label })), description && (jsx(Description$1, Object.assign({ htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, "data-testid": dataTestId && `${dataTestId}-Description`, "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }, { children: description })))] })] })));
956
+ };
957
+ const InputWrapper = tw.label `tu-radioitem__wrapper`;
958
+ const Input = tw.input `
959
+ tu-radioitem
960
+ ${({ $checked }) => $checked && tws `tu-radioitem--checked`}
961
+ ${({ $disabled }) => $disabled && tws `tu-radioitem--disabled`}
962
+ ${({ $isInvalid }) => $isInvalid && tws `tu-radioitem--invalid`}
963
+ `;
964
+ const LabelContainer$1 = tw.div `tu-radioitem__label-container`;
965
+ const Description$1 = tw.label `
966
+ tu-radioitem__description
967
+ ${({ $disabled }) => $disabled && tws `tu-radioitem__description--disabled`}
968
+ `;
969
+
970
+ /**
971
+ * A thin wrapper around the `BaseInput` component for text input fields.
972
+ *
973
+ * NOTE: If shown with a label, please use the `TextField` component instead.
974
+ */
975
+ const TextInput = forwardRef((props, ref) => (jsx(BaseInput, Object.assign({ ref: ref, type: "text" }, props))));
976
+
977
+ /**
978
+ * The Search component is used to render a search input field.
979
+ *
980
+ * @param {SearchProps} props - The props for the Search component
981
+ * @returns {JSX.Element} Search component
982
+ */
983
+ const Search = (_a) => {
984
+ var { className, placeholder = "Search", value, widenInputOnFocus, showBorderWhenNotInFocus = false, disabled, onKeyUp, onChange, onFocus, onBlur, name, onClear, dataTestId, autoComplete = "on", ref } = _a, rest = __rest(_a, ["className", "placeholder", "value", "widenInputOnFocus", "showBorderWhenNotInFocus", "disabled", "onKeyUp", "onChange", "onFocus", "onBlur", "name", "onClear", "dataTestId", "autoComplete", "ref"]);
985
+ return (jsx(StyledTextInput, Object.assign({}, rest, { ref: ref, dataTestId: dataTestId, name: name, className: className, "$widenOnFocus": widenInputOnFocus, "$showBorderWhenNotInFocus": showBorderWhenNotInFocus, placeholder: placeholder, prefix: jsx(Icon, { name: "MagnifyingGlassIcon", size: "medium" }), suffix: onClear ? (jsx("button", Object.assign({ "data-testid": dataTestId && `${dataTestId}_suffix_component`, onClick: () => {
986
+ onClear();
987
+ } }, { children: jsx(Icon, { name: "XMarkIcon", size: "small" }) }))) : undefined, value: value, disabled: disabled, onChange: onChange, onKeyUp: onKeyUp, onFocus: onFocus, onBlur: onBlur, autoComplete: autoComplete })));
988
+ };
989
+ const StyledTextInput = twx(TextInput) `
990
+ tu-search
991
+ ${({ $showBorderWhenNotInFocus }) => $showBorderWhenNotInFocus && tws `tu-search--border`}
992
+ ${({ $widenOnFocus }) => $widenOnFocus && tws `tu-search--widen-on-focus`}
993
+ `;
994
+
995
+ /**
996
+ * The SelectContainer component.
997
+ *
998
+ * @param {SelectContainerProps} props - The props for the SelectContainer component
999
+ * @returns {JSX.Element} SelectContainer component
1000
+ */
1001
+ const SelectContainer = ({ children, label, hideLabel, id, hasError, error, description, info, dataTestId, isDisabled, }) => {
1002
+ return (jsxs(Container, Object.assign({ "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": isDisabled }, { children: [label && !hideLabel && jsx(Label, Object.assign({ htmlFor: id }, { children: label })), children, (hasError || info) && (jsx(InformativeText, Object.assign({ size: "small", "$hasError": hasError !== null && hasError !== void 0 ? hasError : false }, { children: hasError ? error : info })))] })));
1003
+ };
1004
+ const Container = tw.label `
1005
+ tu-select__container
1006
+ tu-select
1007
+ ${({ $hasError }) => ($hasError ? tws `tu-select--invalid` : null)}
1008
+ ${({ $isDisabled }) => ($isDisabled ? tws `tu-select--disabled` : null)}
1009
+ `;
1010
+ const InformativeText = twx(Text) `
1011
+ tu-informative-text
1012
+ ${p => (p.$hasError ? `tu-informative-text--error` : null)}
1013
+ `;
1014
+
1015
+ /**
1016
+ * The CreatableSelect component.
1017
+ *
1018
+ * @param {CreateableSelectProps} props - The props for the CreatableSelect component
1019
+ * @returns {JSX.Element} CreatableSelect component
1020
+ */
1021
+ const CreatableSelect = (props) => {
1022
+ const { id, dataTestId = "select", async, maxMenuHeight = 200, label, error, disabled, isMulti, value, hideLabel, description, info, options, onChange, isLoading, classNamePrefix = "", filterOption, prefix, } = props;
1023
+ const hasError = !!error;
1024
+ const { refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
1025
+ const selectProps = {
1026
+ value,
1027
+ menuPlacement,
1028
+ maxMenuHeight,
1029
+ onChange,
1030
+ "aria-label": label,
1031
+ "data-testid": dataTestId,
1032
+ components: customComponents,
1033
+ styles: customStyles,
1034
+ tabSelectsValue: false,
1035
+ blurInputOnSelect: !isMulti,
1036
+ menuPortalTarget: document.body,
1037
+ isSearchable: disabled ? false : true,
1038
+ menuShouldBlockScroll: true,
1039
+ menuShouldScrollIntoView: true,
1040
+ openMenuOnFocus: disabled ? false : true,
1041
+ menuIsOpen: disabled ? false : menuIsOpen,
1042
+ openMenuOnClick: true,
1043
+ closeMenuOnSelect: false,
1044
+ isMulti: isMulti,
1045
+ classNamePrefix,
1046
+ isLoading,
1047
+ id,
1048
+ };
1049
+ return (jsx(SelectContainer, Object.assign({ label: label, hideLabel: hideLabel, id: id, hasError: hasError, error: error, description: description, info: info, dataTestId: dataTestId, isDisabled: disabled }, { children: jsxs(Fragment, { children: [prefix !== undefined && (jsx(SelectPrefix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix }, { children: prefix }))), async ? (jsx(ReactAsyncCreatableSelect, Object.assign({ "aria-label": label, maxMenuHeight: maxMenuHeight, "data-testid": dataTestId, components: customComponents }, props, { onMenuOpen: () => {
1050
+ !disabled && openMenuHandler();
1051
+ }, onMenuClose: () => {
1052
+ closeMenuHandler();
1053
+ } }))) : (jsx(ReactCreatableSelect, Object.assign({}, selectProps, { options: filterOption ? orderedOptions : options, isMulti: isMulti, onMenuOpen: () => {
1054
+ !disabled && openMenuHandler();
1055
+ }, onMenuClose: () => {
1056
+ closeMenuHandler();
1057
+ } })))] }) })));
1058
+ };
1059
+
1060
+ /**
1061
+ * The TextArea is a base component, and should not be used very often.
1062
+ * For most cases the TextAreaField is the correct component.
1063
+ */
1064
+ const TextArea = React.forwardRef((_a, ref) => {
1065
+ var { id, name, value, rows, disabled, placeholder, readOnly, tabIndex, onChange, onFocus, onBlur, maxLength, resize = "vertical", defaultValue, className, required, dataTestId, isInvalid } = _a, rest = __rest(_a, ["id", "name", "value", "rows", "disabled", "placeholder", "readOnly", "tabIndex", "onChange", "onFocus", "onBlur", "maxLength", "resize", "defaultValue", "className", "required", "dataTestId", "isInvalid"]);
1066
+ return (jsx(StyledTextArea, Object.assign({ id: id, name: name, value: value, rows: rows, disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, onFocus: onFocus, onBlur: onBlur, maxLength: maxLength, "$resize": resize, "$invalid": isInvalid, ref: ref, defaultValue: defaultValue, required: required }, rest, { onChange: onChange, "data-testid": dataTestId })));
1067
+ });
1068
+ const StyledTextArea = tw.textarea `
1069
+ tu-textarea
1070
+ ${({ $invalid }) => ($invalid ? tws `tu-textarea--invalid` : null)}
1071
+ ${({ disabled }) => (disabled ? tws `tu-textarea--disabled` : null)}
1072
+ ${({ $resize }) => {
1073
+ switch ($resize) {
1074
+ case "both":
1075
+ return tws `resize`;
1076
+ case "horizontal":
1077
+ return tws `resize-x`;
1078
+ case "vertical":
1079
+ return tws `resize-y`;
1080
+ case "none":
1081
+ return tws `resize-none`;
1082
+ default:
1083
+ return null;
1084
+ }
1085
+ }};
1086
+ `;
1087
+
1088
+ /**
1089
+ * The TextLengthIndicator component shows a `{length}/{maxLength}` label.
1090
+ * Used for TextFields to communicate a maximum allowed input length.
1091
+ *
1092
+ * @param {TextLengthIndicatorProps} props - The props for the TextLengthIndicator component
1093
+ * @returns {JSX.Element} TextLengthIndicator component
1094
+ */
1095
+ const TextLengthIndicator = ({ length, maxLength }) => {
1096
+ return (jsxs(Root, { children: [length, "/", maxLength] }));
1097
+ };
1098
+ const Root = tw.span `
1099
+ font-mono
1100
+ `;
1101
+
1102
+ const TextAreaField = React.forwardRef((_a, ref) => {
1103
+ var { id, label, tip, helpText, helpAddon, errorMessage, isInvalid, maxLength, onChange, className, value, dataTestId } = _a, rest = __rest(_a, ["id", "label", "tip", "helpText", "helpAddon", "errorMessage", "isInvalid", "maxLength", "onChange", "className", "value", "dataTestId"]);
1104
+ const [valueLength, setValueLength] = React.useState(value ? `${value}`.length : 0);
1105
+ const renderAsInvalid = isInvalid || Boolean(errorMessage);
1106
+ const htmlForId = id ? id : "textAreaField-" + v4();
1107
+ const handleChange = React.useCallback((event) => {
1108
+ setValueLength(event.target.value.length);
1109
+ if (onChange) {
1110
+ onChange(event);
1111
+ }
1112
+ }, [onChange]);
1113
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon ||
1114
+ (maxLength !== null && maxLength !== undefined && (jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength }))), className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(TextArea, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, onChange: handleChange, dataTestId: dataTestId })) })));
1115
+ });
1116
+
1117
+ /**
1118
+ * Text fields enable the user to interact with and input content and data. This component can be used for long and short form entries. Allow the size of the text input box to reflect the length of the content you expect the user to enter.
1119
+ *
1120
+ * _**Do use** when the user has to input or edit simple text based information, such as metadata._
1121
+ *
1122
+ * _**Do not use** to confirm user actions, such as deleting. Use a checkbox for such flows._
1123
+ */
1124
+ const TextField = React.forwardRef((_a, ref) => {
1125
+ var { id, label, tip, helpText, helpAddon, errorMessage, isInvalid, maxLength, onChange, className, value, dataTestId } = _a, rest = __rest(_a, ["id", "label", "tip", "helpText", "helpAddon", "errorMessage", "isInvalid", "maxLength", "onChange", "className", "value", "dataTestId"]);
1126
+ const [valueLength, setValueLength] = React.useState(value ? `${value}`.length : 0);
1127
+ const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
1128
+ const htmlFor = id ? id : "textField-" + v4();
1129
+ const handleChange = React.useCallback((event) => {
1130
+ setValueLength(event.target.value.length);
1131
+ if (onChange) {
1132
+ onChange(event);
1133
+ }
1134
+ }, [onChange]);
1135
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlFor, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon ||
1136
+ (maxLength !== null && maxLength !== undefined && (jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength }))), dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.readOnly }, { children: jsx(TextInput, Object.assign({ id: htmlFor, "aria-labelledby": htmlFor + "-label", ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, onChange: handleChange, dataTestId: dataTestId })) })));
1137
+ });
1138
+
1139
+ /**
1140
+ * Use Toggle when you have to only enable/disable a feature.
1141
+ *
1142
+ * _**Do use** Toggle in forms or settings._
1143
+ *
1144
+ * _**Do not use** Toggle if a user can select many option from a list, use checkboxes instead of toggle._
1145
+ *
1146
+ * @param {ToggleProps} props - The props for the Toggle component
1147
+ * @returns {JSX.Element} Toggle component
1148
+ */
1149
+ const Toggle = React.forwardRef(({ toggled = false, onChange, disabled, size = "medium", id, tabIndex, required, className, dataTestId, onBlur, name, description = "", }, ref) => {
1150
+ return (jsxs(ToggleWrapper, { children: [jsxs(InputContainer, Object.assign({ htmlFor: id }, { children: [jsx(HiddenInput, { name: name, type: "checkbox", checked: toggled, disabled: disabled, onChange: e => {
1151
+ e.stopPropagation();
1152
+ onChange(!toggled, e);
1153
+ }, id: id, "aria-checked": toggled, role: "checkbox", tabIndex: tabIndex, required: required, ref: ref, "data-testid": dataTestId && `${dataTestId}-Input`, onBlur: onBlur }), jsx(SwitchContainer, Object.assign({ "$toggled": toggled, htmlFor: id, "$disabled": disabled, "$size": size }, { children: jsx(Switch, { "$toggled": toggled, htmlFor: id, "data-testid": dataTestId && `${dataTestId}-Switch` }) }))] })), jsxs(LabelContainer, { children: [jsx(Label, Object.assign({ htmlFor: id, dataTestId: dataTestId && `${dataTestId}-Label`, disabled: disabled }, { children: name })), description && (jsx(Description, Object.assign({ htmlFor: id, "data-testid": dataTestId && `${dataTestId}-Description`, "$disabled": disabled }, { children: description })))] })] }));
1154
+ });
1155
+ Toggle.displayName = "Toggle";
1156
+ const ToggleWrapper = tw.div `tu-toggle__wrapper`;
1157
+ const InputContainer = tw.label `tu-toggle__input-container `;
1158
+ const HiddenInput = tw.input `tu-toggle__input`;
1159
+ const Switch = tw.label `
1160
+ ${({ $toggled }) => ($toggled ? tws `tu-toggle__switch` : tws `tu-toggle`)}`;
1161
+ const SwitchContainer = tw.label `
1162
+ tu-toggle__switch-container
1163
+ ${({ $disabled }) => $disabled && tws `tu-toggle--disabled`};
1164
+ ${({ $size }) => ($size === "small" ? tws `tu-toggle--small` : tws `tu-toggle--medium`)};
1165
+ ${({ $toggled }) => $toggled && tws `tu-toggle--toggled`}`;
1166
+ const LabelContainer = tw.div `tu-toggle__label-container`;
1167
+ const Description = tw.label `
1168
+ tu-toggle__description
1169
+ ${({ $disabled }) => $disabled && tws `tu-toggle__description--disabled`}
1170
+ `;
1171
+
1172
+ /**
1173
+ * A thin wrapper around the `BaseInput` component for upload input fields.
1174
+ *
1175
+ * NOTE: If shown with a label, please use the `UploadField` component instead.
1176
+ */
1177
+ const UploadInput = forwardRef((_a, ref) => {
1178
+ var { disabled, acceptedTypes, nonInteractive, uploadLabel, multipleFiles } = _a, rest = __rest(_a, ["disabled", "acceptedTypes", "nonInteractive", "uploadLabel", "multipleFiles"]);
1179
+ return (jsx(UploadInputContainer, { children: jsx(BaseInput, Object.assign({ addonBefore: uploadLabel, ref: ref, disabled: disabled, accept: acceptedTypes, multiple: multipleFiles, type: "file", nonInteractive: nonInteractive,
1180
+ // onClick used to work with nonInteractive option
1181
+ onClick: event => {
1182
+ if (nonInteractive) {
1183
+ event.preventDefault();
1184
+ event.stopPropagation();
1185
+ }
1186
+ } }, rest)) }));
1187
+ });
1188
+ const UploadInputContainer = tw.label `
1189
+ tu-upload-input`;
1190
+
1191
+ /**
1192
+ * Upload fields enable the user to upload Files.
1193
+ */
1194
+ const UploadField = forwardRef((_a, ref) => {
1195
+ var { label, id, tip, helpText, errorMessage, isInvalid, className, value, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "isInvalid", "className", "value", "dataTestId"]);
1196
+ const renderAsInvalid = isInvalid || Boolean(errorMessage);
1197
+ const htmlForId = id ? id : "uploadField-" + v4();
1198
+ return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, dataTestId: `${dataTestId}-FormGroup` }, { children: jsx(UploadInput, Object.assign({ ref: ref, id: htmlForId, "aria-labelledby": htmlForId + "-label", isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
1199
+ });
1200
+
1201
+ /*
1202
+ * ----------------------------
1203
+ * | SETUP TRANSLATIONS START |
1204
+ * ----------------------------
1205
+ * This import and function call is needed to register translations for this library.
1206
+ * Do not remove this if this library has translations.
1207
+ */
1208
+ setupLibraryTranslations();
1209
+
1210
+ export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, PhoneField, PhoneInput, RadioGroup, RadioItem, Search, Select, SelectPrefix, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, Toggle, UploadField, UploadInput, getOrderedOptions, isMultiValue, useCustomComponents };