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