@trackunit/react-components 0.1.76 → 0.1.77
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 +1 -1
- package/index.cjs +116 -1278
- package/index.css +0 -260
- package/index.js +118 -1241
- package/package.json +2 -5
- package/src/components/index.d.ts +0 -24
- package/src/components/ActionButton/ActionButton.d.ts +0 -27
- package/src/components/ActionButton/index.d.ts +0 -1
- package/src/components/BaseInput/BaseInput.d.ts +0 -62
- package/src/components/BaseInput/index.d.ts +0 -1
- package/src/components/Checkbox/CheckIcon.d.ts +0 -12
- package/src/components/Checkbox/Checkbox.d.ts +0 -48
- package/src/components/Checkbox/IndeterminateIcon.d.ts +0 -10
- package/src/components/Checkbox/index.d.ts +0 -1
- package/src/components/DateField/DateField.d.ts +0 -19
- package/src/components/DateInput/DateInput.d.ts +0 -28
- package/src/components/DropZone/DropZone.d.ts +0 -34
- package/src/components/EmailField/EmailField.d.ts +0 -17
- package/src/components/EmailInput/EmailInput.d.ts +0 -13
- package/src/components/EmailInput/index.d.ts +0 -1
- package/src/components/FormGroup/FormGroup.d.ts +0 -39
- package/src/components/Label/Label.d.ts +0 -34
- package/src/components/Label/index.d.ts +0 -1
- package/src/components/NumberField/NumberField.d.ts +0 -19
- package/src/components/NumberInput/NumberInput.d.ts +0 -12
- package/src/components/PhoneField/PhoneField.d.ts +0 -28
- package/src/components/PhoneInput/CountryCodeSelect.d.ts +0 -16
- package/src/components/PhoneInput/CountryCodes.d.ts +0 -5
- package/src/components/PhoneInput/PhoneInput.d.ts +0 -25
- package/src/components/PhoneInput/index.d.ts +0 -1
- package/src/components/RadioGroup/RadioGroup.d.ts +0 -57
- package/src/components/RadioGroup/RadioGroupContext.d.ts +0 -11
- package/src/components/RadioGroup/RadioItem.d.ts +0 -23
- package/src/components/RadioGroup/index.d.ts +0 -2
- package/src/components/Search/Search.d.ts +0 -62
- package/src/components/Search/index.d.ts +0 -1
- package/src/components/Select/CreatableSelect.d.ts +0 -38
- package/src/components/Select/FieldContainer.d.ts +0 -20
- package/src/components/Select/Select.d.ts +0 -18
- package/src/components/Select/SelectMenuItem/SelectMenuItem.d.ts +0 -49
- package/src/components/Select/TagWithWidth.d.ts +0 -17
- package/src/components/Select/TagsContainer.d.ts +0 -45
- package/src/components/Select/index.d.ts +0 -7
- package/src/components/Select/shared.d.ts +0 -15
- package/src/components/Select/useCustomComponents.d.ts +0 -19
- package/src/components/Select/useCustomStyles.d.ts +0 -14
- package/src/components/Select/useSelect.d.ts +0 -143
- package/src/components/TextArea/TextArea.d.ts +0 -30
- package/src/components/TextArea/index.d.ts +0 -1
- package/src/components/TextAreaField/TextAreaField.d.ts +0 -18
- package/src/components/TextAreaField/index.d.ts +0 -1
- package/src/components/TextField/TextField.d.ts +0 -24
- package/src/components/TextField/TextLenghtIndicator.d.ts +0 -19
- package/src/components/TextField/index.d.ts +0 -1
- package/src/components/TextInput/TextInput.d.ts +0 -12
- package/src/components/Toggle/Toggle.d.ts +0 -57
- package/src/components/Toggle/index.d.ts +0 -1
- package/src/components/UploadField/UploadField.d.ts +0 -15
- package/src/components/UploadInput/UploadInput.d.ts +0 -33
package/index.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { tw, tws, twx } from '@trackunit/tailwind-styled-components';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import React__default, { useState,
|
|
4
|
+
import React__default, { useState, useMemo, createContext, useContext, forwardRef, isValidElement, cloneElement, useCallback, useEffect, Children, useRef, memo } from 'react';
|
|
5
5
|
import { HeroIconsArray, heroIconLookup, TrackunitSolidIconsArray, TrackunitOutlineIconsArray, trackunitIconLookup } from '@trackunit/ui-icons';
|
|
6
6
|
import { useMeasure, useCopyToClipboard } from 'react-use';
|
|
7
|
-
import { v4 } from 'uuid';
|
|
8
|
-
import { format, formatDistance } from 'date-fns';
|
|
9
|
-
import { useFloating, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover, useRole, useInteractions, useMergeRefs, FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
|
|
10
7
|
import { DayPicker as DayPicker$1 } from 'react-day-picker';
|
|
11
8
|
import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
|
|
9
|
+
import { useFloating, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover, useRole, useInteractions, useMergeRefs, FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
|
|
12
10
|
import usePortal from 'react-useportal';
|
|
13
|
-
import ReactSelect, { components } from 'react-select';
|
|
14
|
-
export { default as ValueType } from 'react-select';
|
|
15
|
-
import ReactAsyncCreatableSelect from 'react-select/async-creatable';
|
|
16
|
-
import ReactCreatableSelect from 'react-select/creatable';
|
|
17
|
-
import ReactAsyncSelect from 'react-select/async';
|
|
18
|
-
import { getCountries, getCountryCallingCode } from 'libphonenumber-js';
|
|
19
11
|
import { UNSAFE_NavigationContext } from 'react-router-dom';
|
|
20
12
|
import { HelmetProvider, Helmet } from 'react-helmet-async';
|
|
13
|
+
import { format, formatDistance } from 'date-fns';
|
|
21
14
|
import { color } from '@trackunit/ui-design-tokens';
|
|
22
15
|
|
|
23
16
|
const docs = {
|
|
@@ -71,16 +64,6 @@ function __rest(s, e) {
|
|
|
71
64
|
t[p[i]] = s[p[i]];
|
|
72
65
|
}
|
|
73
66
|
return t;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
77
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
78
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
79
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
80
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
81
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
82
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
83
|
-
});
|
|
84
67
|
}
|
|
85
68
|
|
|
86
69
|
/**
|
|
@@ -98,7 +81,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
98
81
|
* @returns {JSX.Element} Spinner component
|
|
99
82
|
*/
|
|
100
83
|
const Spinner = ({ mode = "light", size = "medium", centering = "centered", className, containerClassName, dataTestId, }) => {
|
|
101
|
-
return (jsx(Container$
|
|
84
|
+
return (jsx(Container$7, Object.assign({ "$mode": mode, "$centering": centering, className: containerClassName }, { children: jsx(StyledSpinner$1, { "$size": size, "$mode": mode, role: "spinbutton", className: className, "data-testid": dataTestId }) })));
|
|
102
85
|
};
|
|
103
86
|
const getSpinnerStyles = () => ({ $size }) => {
|
|
104
87
|
switch ($size) {
|
|
@@ -128,7 +111,7 @@ const StyledSpinner$1 = tw.span `
|
|
|
128
111
|
${p => (p.$mode === "dark" ? tws `tu-spinner--dark` : null)}
|
|
129
112
|
${getSpinnerStyles()}
|
|
130
113
|
`;
|
|
131
|
-
const Container$
|
|
114
|
+
const Container$7 = tw.div `
|
|
132
115
|
tu-spinner--container
|
|
133
116
|
${getCenteringStyles()}
|
|
134
117
|
|
|
@@ -238,12 +221,12 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, fil
|
|
|
238
221
|
if (!IconComponent) {
|
|
239
222
|
return null;
|
|
240
223
|
}
|
|
241
|
-
return (jsx(React.Suspense, Object.assign({ fallback: jsx(LoadingDot, { className: iconSizeClassName }) }, { children: jsx(Root$
|
|
224
|
+
return (jsx(React.Suspense, Object.assign({ fallback: jsx(LoadingDot, { className: iconSizeClassName }) }, { children: jsx(Root$6, Object.assign({ "$color": color, onClick: onClick, "data-testid": dataTestId, ref: forwardedRef }, { children: jsx(IconComponent, { "data-testid": dataTestId ? `${dataTestId}-${name}` : name, className: `${iconSizeClassName} ${colorClassNames} ${className !== null && className !== void 0 ? className : ""} ${name} aspect-square`, style: fillColor ? Object.assign(Object.assign({}, style), { fill: fillColor }) : Object.assign({}, style) }) })) })));
|
|
242
225
|
};
|
|
243
226
|
const LoadingDot = tw.span `
|
|
244
227
|
tu-loading-dot
|
|
245
228
|
`;
|
|
246
|
-
const Root$
|
|
229
|
+
const Root$6 = tw.span `
|
|
247
230
|
tu-icon
|
|
248
231
|
${({ $color }) => {
|
|
249
232
|
switch ($color) {
|
|
@@ -287,48 +270,6 @@ const Root$9 = tw.span `
|
|
|
287
270
|
}}
|
|
288
271
|
`;
|
|
289
272
|
|
|
290
|
-
/**
|
|
291
|
-
* The ActionButton component is a wrapper over IconButton to perform an action when the onClick event is triggered.
|
|
292
|
-
*
|
|
293
|
-
* @param {ActionButtonProps} props - The props for the ActionButton component
|
|
294
|
-
* @returns {JSX.Element} ActionButton component
|
|
295
|
-
*/
|
|
296
|
-
const ActionButton = ({ type, value, dataTestId, iconSize, disabled }) => {
|
|
297
|
-
const getIconName = () => {
|
|
298
|
-
switch (type) {
|
|
299
|
-
case "PHONE_NUMBER":
|
|
300
|
-
return "PhoneArrowUpRightIcon";
|
|
301
|
-
case "WEB_ADDRESS":
|
|
302
|
-
return "ArrowTopRightOnSquareIcon";
|
|
303
|
-
case "EMAIL":
|
|
304
|
-
default:
|
|
305
|
-
return "EnvelopeIcon";
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
const ButtonAction = () => {
|
|
309
|
-
switch (type) {
|
|
310
|
-
case "EMAIL":
|
|
311
|
-
return window.open(`mailto:${value}`);
|
|
312
|
-
case "WEB_ADDRESS":
|
|
313
|
-
if (value) {
|
|
314
|
-
return window.open(value, "_blank", "noopener,noreferrer");
|
|
315
|
-
}
|
|
316
|
-
return null;
|
|
317
|
-
case "PHONE_NUMBER":
|
|
318
|
-
default:
|
|
319
|
-
return window.open(`tel:${value}`);
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
return (jsx(ActionContainer, { children: jsx(StyledIconButton, { "$fieldSize": iconSize, disabled: disabled, dataTestId: dataTestId || "testIconButtonId", size: "small", color: "tertiary", icon: jsx(Icon, { size: "small", name: getIconName() }), onClick: ButtonAction }) }));
|
|
323
|
-
};
|
|
324
|
-
const ActionContainer = tw.div `
|
|
325
|
-
tu-action-container
|
|
326
|
-
`;
|
|
327
|
-
const StyledIconButton = twx(IconButton) `
|
|
328
|
-
tu-action-button
|
|
329
|
-
${({ $fieldSize }) => $fieldSize === "small" && tws `tu-action-button--small`}
|
|
330
|
-
`;
|
|
331
|
-
|
|
332
273
|
/**
|
|
333
274
|
* The StarButton component is used for favorite actions or similar.
|
|
334
275
|
*
|
|
@@ -336,9 +277,9 @@ ${({ $fieldSize }) => $fieldSize === "small" && tws `tu-action-button--small`}
|
|
|
336
277
|
* @returns {JSX.Element} StarButton component
|
|
337
278
|
*/
|
|
338
279
|
const StarButton = ({ starred, onClick }) => {
|
|
339
|
-
return (jsx(Flex$
|
|
280
|
+
return (jsx(Flex$1, Object.assign({ onClick: onClick, "data-test-id": "starred-filter" }, { children: jsx(CustomIcon, { name: "StarIcon", "$starred": starred }) })));
|
|
340
281
|
};
|
|
341
|
-
const Flex$
|
|
282
|
+
const Flex$1 = tw.div `
|
|
342
283
|
flex
|
|
343
284
|
items-center
|
|
344
285
|
`;
|
|
@@ -434,13 +375,13 @@ const Alert = ({ color = "info", title, className, children, primaryAction, seco
|
|
|
434
375
|
return "primary";
|
|
435
376
|
}
|
|
436
377
|
};
|
|
437
|
-
const body = inline ? (jsxs("div", { children: [title && jsx(Text$1, Object.assign({ weight: "bold" }, { children: title !== null && title !== void 0 ? title : children })), children && (jsx(Description
|
|
378
|
+
const body = inline ? (jsxs("div", { children: [title && jsx(Text$1, Object.assign({ weight: "bold" }, { children: title !== null && title !== void 0 ? title : children })), children && (jsx(Description, Object.assign({ weight: !title ? "bold" : "normal", "$hasTitle": !!title }, { children: children })))] })) : (jsxs(Fragment, { children: [title && jsx(Text$1, Object.assign({ weight: "bold" }, { children: title !== null && title !== void 0 ? title : children })), children && (jsx(Description, Object.assign({ weight: !title ? "bold" : "normal", "$hasTitle": !!title }, { children: children })))] }));
|
|
438
379
|
React.useEffect(() => {
|
|
439
380
|
if (autoScroll) {
|
|
440
381
|
ref && ref.current && ref.current.scrollIntoView && ref.current.scrollIntoView();
|
|
441
382
|
}
|
|
442
383
|
}, [ref, autoScroll]);
|
|
443
|
-
return (jsxs(Container$
|
|
384
|
+
return (jsxs(Container$6, Object.assign({ "$color": color, className: className, "data-testid": dataTestId, "$inline": inline, ref: ref, role: "alert" }, { children: [jsx(IconContainer$1, Object.assign({ "$inline": inline }, { children: getIconFromColor() })), jsxs(Content$1, Object.assign({ "$inline": inline }, { children: [jsxs(ContentDetails, { children: [jsx(ContentBody, { children: body }), onClose && !inline ? (jsx(CloseButtonContainer, Object.assign({ "$inline": inline }, { children: jsx(IconButton, { size: "small", variant: "transparent", color: "secondary", onClick: onClose, icon: jsx(Icon, { name: "XMarkIcon", size: "small" }), title: "Close Alert", circular: true }) }))) : null] }), (primaryAction || secondaryAction || onClose) && (jsxs(RightAligned, Object.assign({ "$inline": inline }, { children: [secondaryAction && (jsx(Button, Object.assign({ size: "small", variant: "transparent", color: getButtonColor(), onClick: secondaryAction.onClick, loading: secondaryAction === null || secondaryAction === void 0 ? void 0 : secondaryAction.loading }, { children: secondaryAction.label }))), primaryAction && (jsx(Button, Object.assign({ size: "small", color: getButtonColor(), onClick: primaryAction.onClick, loading: primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction.loading }, { children: primaryAction.label }))), onClose && inline ? (jsx(CloseButtonContainer, Object.assign({ "$inline": inline }, { children: jsx(IconButton, { size: "small", variant: "transparent", color: "secondary", onClick: onClose, icon: jsx(Icon, { name: "XMarkIcon", size: "small" }), title: "Close Alert", circular: true }) }))) : null] })))] }))] })));
|
|
444
385
|
};
|
|
445
386
|
const CloseButtonContainer = tw.div `
|
|
446
387
|
${p => (p.$inline ? tws `tu-alert__close-button-container--inline` : tws `tu-alert__close-button-container`)}
|
|
@@ -454,7 +395,7 @@ const getBackgroundColor = () => ({ $color }) => {
|
|
|
454
395
|
};
|
|
455
396
|
return colors[$color];
|
|
456
397
|
};
|
|
457
|
-
const Container$
|
|
398
|
+
const Container$6 = tw.div `
|
|
458
399
|
tu-alert
|
|
459
400
|
${p => (p.$inline ? tws `tu-alert--inline` : null)}
|
|
460
401
|
${getBackgroundColor()}
|
|
@@ -468,7 +409,7 @@ const ContentDetails = tw.div `
|
|
|
468
409
|
const ContentBody = tw.div `
|
|
469
410
|
tu-alert__content-body
|
|
470
411
|
`;
|
|
471
|
-
const Description
|
|
412
|
+
const Description = twx(Text$1) `
|
|
472
413
|
${p => (p.$hasTitle ? tws `tu-alert__description` : null)}
|
|
473
414
|
`;
|
|
474
415
|
const RightAligned = tw.div `
|
|
@@ -507,37 +448,6 @@ const StyledText$2 = tw.text `
|
|
|
507
448
|
${getBadgeModifierClass()}
|
|
508
449
|
`;
|
|
509
450
|
|
|
510
|
-
/**
|
|
511
|
-
* A base input component that can be used for text inputs, password inputs, etc.
|
|
512
|
-
* A reference to the input element is provided as the `ref` prop.
|
|
513
|
-
* Extends props from [React.InputHTMLAttributes](https://reactjs.org/docs/dom-elements.html#input)
|
|
514
|
-
*
|
|
515
|
-
* For specific input types make sure to use the corresponding input component.
|
|
516
|
-
* This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
|
|
517
|
-
*/
|
|
518
|
-
const BaseInput = React.forwardRef((_a, ref) => {
|
|
519
|
-
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"]);
|
|
520
|
-
return (jsxs(InputContainer$1, Object.assign({ "$fieldSize": fieldSize, "$invalid": isInvalid, "$disabled": rest.disabled || rest.readOnly, className: className, "data-testid": dataTestId && `${dataTestId}-container` }, { children: [addonBefore && addonBefore !== undefined ? (jsx(AddonBefore, Object.assign({ "data-testid": dataTestId && `${dataTestId}-addonBefore` }, { children: addonBefore }))) : null, prefix && addonBefore !== prefix ? (jsx(InputPrefix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-prefix` }, { children: prefix }))) : null, jsx("input", Object.assign({ ref: ref, "data-testid": dataTestId, className: tws `tu-input__field` }, rest, { readOnly: rest.readOnly || nonInteractive })), suffix && addonBefore !== suffix ? (jsx(InputSuffix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-suffix` }, { children: suffix }))) : null, actions && addonBefore !== actions ? actions : null, addonAfter && addonAfter !== undefined && addonBefore !== addonAfter ? (jsx(AddonAfter, Object.assign({ "data-testid": dataTestId && `${dataTestId}-addonAfter` }, { children: addonAfter }))) : null] })));
|
|
521
|
-
});
|
|
522
|
-
const InputPrefix = tw.div `
|
|
523
|
-
tu-input__prefix
|
|
524
|
-
`;
|
|
525
|
-
const InputSuffix = tw.div `
|
|
526
|
-
tu-input__suffix
|
|
527
|
-
`;
|
|
528
|
-
const AddonBefore = tw.div `
|
|
529
|
-
tu-input__addon-before
|
|
530
|
-
`;
|
|
531
|
-
const AddonAfter = tw.div `
|
|
532
|
-
tu-input__addon-after
|
|
533
|
-
`;
|
|
534
|
-
const InputContainer$1 = tw.label `
|
|
535
|
-
tu-input
|
|
536
|
-
${({ $invalid }) => ($invalid ? tws `tu-input--invalid` : null)}
|
|
537
|
-
${({ $disabled }) => ($disabled ? tws `tu-input--disabled` : null)}
|
|
538
|
-
${({ $fieldSize }) => ($fieldSize === "small" ? tws `tu-input--small` : null)}
|
|
539
|
-
`;
|
|
540
|
-
|
|
541
451
|
const ROLE_CARD = "region";
|
|
542
452
|
/**
|
|
543
453
|
* The Card component is a container for UI elements, and is the main component of the modal.
|
|
@@ -655,9 +565,9 @@ const StyledDensityContainer = twx(DensityContainer) `
|
|
|
655
565
|
* @returns {JSX.Element} CardFooter component
|
|
656
566
|
*/
|
|
657
567
|
const CardFooter = ({ dataTestId, className, children, density, hideSeparator = false }) => {
|
|
658
|
-
return (jsx(Container$
|
|
568
|
+
return (jsx(Container$5, Object.assign({ dataTestId: dataTestId, className: className, "$hideSeparator": hideSeparator, density: density, direction: "row" }, { children: children })));
|
|
659
569
|
};
|
|
660
|
-
const Container$
|
|
570
|
+
const Container$5 = twx(DensityContainer) `
|
|
661
571
|
tu-card__footer-density-container
|
|
662
572
|
${p => p.$hideSeparator && tws `tu-card__footer-density-container--borderless`}
|
|
663
573
|
`;
|
|
@@ -704,101 +614,19 @@ const StyledHeading = tw.div `
|
|
|
704
614
|
* @returns {JSX.Element} CardHeader component
|
|
705
615
|
*/
|
|
706
616
|
const CardHeader = ({ heading, headingVariant = "primary", subHeading, onClose, dataTestId, className, children, accessories, density, extraClassName, hideSeparator = false, }) => {
|
|
707
|
-
return (jsx(Root$
|
|
617
|
+
return (jsx(Root$5, Object.assign({ dataTestId: dataTestId, className: className, "$hideSeparator": hideSeparator, density: density }, { children: jsxs(Container$4, { children: [jsxs("div", Object.assign({ className: extraClassName }, { children: [jsxs(HeadingContainer$1, { children: [jsx(Heading$1, Object.assign({ className: "self-center", variant: headingVariant }, { children: heading })), accessories] }), subHeading && (jsx(Heading$1, Object.assign({ subtle: true, variant: "subtitle" }, { children: subHeading }))), children] })), onClose && (jsx(IconButton, { dataTestId: "card-header-close-button", variant: "transparent", color: "secondary", onClick: onClose, icon: jsx(Icon, { name: "XMarkIcon", size: "small" }), className: "!h-min" }))] }) })));
|
|
708
618
|
};
|
|
709
|
-
const Root$
|
|
619
|
+
const Root$5 = twx(DensityContainer) `
|
|
710
620
|
tu-card__header-density-container
|
|
711
621
|
${p => p.$hideSeparator && tws `tu-card__header-density-container--borderless`}
|
|
712
622
|
`;
|
|
713
|
-
const Container$
|
|
623
|
+
const Container$4 = tw.div `
|
|
714
624
|
tu-card__header
|
|
715
625
|
`;
|
|
716
626
|
const HeadingContainer$1 = tw.div `
|
|
717
627
|
tu-card__header-heading-container
|
|
718
628
|
`;
|
|
719
629
|
|
|
720
|
-
/**
|
|
721
|
-
* The Label component is used for labels for input fields.
|
|
722
|
-
* This component is **not used directly**, but is part of the FormGroup and Field components.
|
|
723
|
-
*
|
|
724
|
-
* @param {LabelProps} props - The props for the Label component
|
|
725
|
-
* @returns {JSX.Element} Label component
|
|
726
|
-
*/
|
|
727
|
-
const Label$2 = ({ id, htmlFor, children, className, dataTestId, disabled, isInvalid, }) => {
|
|
728
|
-
return (jsx(Root$7, Object.assign({ id: id || "", htmlFor: htmlFor || "", className: className, "data-testid": dataTestId, "$disabled": disabled, "$isInvalid": isInvalid }, { children: children })));
|
|
729
|
-
};
|
|
730
|
-
const Root$7 = tw.label `
|
|
731
|
-
tu-label
|
|
732
|
-
${({ $disabled }) => $disabled && tws `tu-label--disabled`}
|
|
733
|
-
${({ $isInvalid }) => $isInvalid && tws `tu-label--invalid`}
|
|
734
|
-
`;
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* The CheckIcon component is used by the checkbox to display the checked state.
|
|
738
|
-
*
|
|
739
|
-
* @param {CheckIconProps} props - The props for the CheckIcon component
|
|
740
|
-
* @returns {JSX.Element} CheckIcon component
|
|
741
|
-
*/
|
|
742
|
-
const CheckIcon = ({ className, dataTestId }) => {
|
|
743
|
-
return (jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", className: className, "data-testid": dataTestId, fill: "none", viewBox: "0 0 10 10", stroke: "currentColor", strokeWidth: "2" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m2 5.5 2 2L8.5 3" }) })));
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* The IndeterminateIcon component is used by the checkbox to display the Indeterminate state.
|
|
748
|
-
*
|
|
749
|
-
* @param {IndeterminateIconProps} props - The props for the IndeterminateIcon component
|
|
750
|
-
* @returns {JSX.Element} IndeterminateIcon component
|
|
751
|
-
*/
|
|
752
|
-
const IndeterminateIcon = ({ className }) => (jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", className: className, fill: "none", viewBox: "0 0 10 10", stroke: "currentColor", strokeWidth: "2" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 5h4" }) })));
|
|
753
|
-
|
|
754
|
-
/**
|
|
755
|
-
* Checkboxes are used when there are multiple items to select in a list. Users can select zero, one, or any number of items.
|
|
756
|
-
*
|
|
757
|
-
* 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.
|
|
758
|
-
*
|
|
759
|
-
* _**Do use** checkboxes to allow selection in a form, for filtering, terms and conditions to indicate agreement, and bulk actions in lists or tables._
|
|
760
|
-
*
|
|
761
|
-
* _**Do not use** checkboxes if the user can only select one option from a list, radio buttons should be used instead of checkboxes._
|
|
762
|
-
*
|
|
763
|
-
* @description A reference to the input element is provided as the `ref` prop.
|
|
764
|
-
* @augments props from [React.InputHTMLAttributes](https://reactjs.org/docs/dom-elements.html#input)
|
|
765
|
-
* @param {CheckboxProps} props - The props for the Checkbox component
|
|
766
|
-
* @returns {JSX.Element} Checkbox component
|
|
767
|
-
*/
|
|
768
|
-
const Checkbox = React.forwardRef((_a, ref) => {
|
|
769
|
-
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"]);
|
|
770
|
-
const icon = indeterminate ? jsx(StyledIndeterminateIcon, {}) : checked && jsx(StyledCheckIcon, {});
|
|
771
|
-
const internalRef = React.useRef(null);
|
|
772
|
-
const isReadonly = disabled || readOnly;
|
|
773
|
-
const onKeyPress = e => {
|
|
774
|
-
var _a;
|
|
775
|
-
if ("Space" === e.code) {
|
|
776
|
-
(_a = internalRef === null || internalRef === void 0 ? void 0 : internalRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
const uuid = rest.id || dataTestId;
|
|
780
|
-
return (jsxs(CheckboxContainer, Object.assign({ "data-testid": dataTestId && `${dataTestId}Container`, htmlFor: uuid, className: className }, { children: [jsx(HiddenInput$1, Object.assign({ type: "checkbox", checked: !indeterminate && checked, onChange: onChange, disabled: disabled, "data-testid": dataTestId, readOnly: readOnly, "aria-checked": !indeterminate && checked, role: "checkbox", id: uuid }, rest, { ref: ref })), jsx(CheckboxWrapper, Object.assign({ id: uuid, "$disabled": isReadonly, "$checked": checked, "$indeterminate": indeterminate, "$isInvalid": isReadonly ? false : isInvalid, tabIndex: isReadonly ? -1 : tabIndex, onKeyPress: onKeyPress }, { children: icon })), label && (jsx(Label$2, Object.assign({ className: tws `cursor-pointer`, htmlFor: uuid, disabled: isReadonly, isInvalid: isReadonly ? false : isInvalid, dataTestId: dataTestId && `${dataTestId}-Label` }, { children: label }))), children] })));
|
|
781
|
-
});
|
|
782
|
-
const StyledCheckIcon = twx(CheckIcon) `tu-checkbox--icon`;
|
|
783
|
-
const StyledIndeterminateIcon = twx(IndeterminateIcon) `tu-checkbox--icon`;
|
|
784
|
-
const CheckboxContainer = tw.label `tu-checkbox--container group`;
|
|
785
|
-
const HiddenInput$1 = tw.input `tu-checkbox--input`;
|
|
786
|
-
const CheckboxWrapper = tw.span `
|
|
787
|
-
tu-checkbox
|
|
788
|
-
${({ $checked, $disabled, $indeterminate }) => {
|
|
789
|
-
if ($disabled) {
|
|
790
|
-
return tws `tu-checkbox--disabled`;
|
|
791
|
-
}
|
|
792
|
-
return $indeterminate
|
|
793
|
-
? tws `tu-checkbox--indeterminate`
|
|
794
|
-
: $checked
|
|
795
|
-
? tws `tu-checkbox--selected`
|
|
796
|
-
: tws `tu-checkbox--deselected`;
|
|
797
|
-
}}
|
|
798
|
-
|
|
799
|
-
${({ $isInvalid }) => $isInvalid && tws `tu-checkbox--invalid`}
|
|
800
|
-
`;
|
|
801
|
-
|
|
802
630
|
/**
|
|
803
631
|
* The Collapse component is used to condense non-important information.
|
|
804
632
|
*
|
|
@@ -813,7 +641,7 @@ const Collapse = ({ id, initialExpanded = false, onToggle, label, children, clas
|
|
|
813
641
|
}
|
|
814
642
|
setExpanded(!expanded);
|
|
815
643
|
}, [expanded, onToggle]);
|
|
816
|
-
return (jsxs(StyledCollapse, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsx(CollapseLabel, Object.assign({ role: "button", "aria-expanded": expanded, "aria-controls": id, onClick: handleClick }, { children: jsxs(LabelContainer
|
|
644
|
+
return (jsxs(StyledCollapse, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsx(CollapseLabel, Object.assign({ role: "button", "aria-expanded": expanded, "aria-controls": id, onClick: handleClick }, { children: jsxs(LabelContainer, { children: [jsx(Text$1, Object.assign({ weight: "bold" }, { children: label })), jsx(IconButton, { icon: jsx(Rotate, { name: "ChevronDownIcon", size: "small", "$expanded": expanded }), size: "medium", variant: "transparent", color: "secondary" })] }) })), jsx(Collapsible, Object.assign({ expanded: expanded, id: id }, { children: children }))] })));
|
|
817
645
|
};
|
|
818
646
|
const Rotate = twx(Icon) `
|
|
819
647
|
${p => (p.$expanded ? tws `tu-icon--animated-rotate-expanded` : null)}
|
|
@@ -825,7 +653,7 @@ const StyledCollapse = tw.div `
|
|
|
825
653
|
const CollapseLabel = tw.div `
|
|
826
654
|
tu-collapse__label
|
|
827
655
|
`;
|
|
828
|
-
const LabelContainer
|
|
656
|
+
const LabelContainer = tw.div `
|
|
829
657
|
tu-collapse__label__container
|
|
830
658
|
`;
|
|
831
659
|
const Collapsible = ({ children, expanded, id }) => {
|
|
@@ -860,21 +688,48 @@ const StyledCopyableText = tw.span `
|
|
|
860
688
|
tu-copyable-text
|
|
861
689
|
${p => (p.$animating ? tws `tu-copyable-text--animating` : null)}`;
|
|
862
690
|
|
|
691
|
+
const localeLookup = {
|
|
692
|
+
en: enGB,
|
|
693
|
+
"en-US": enUS,
|
|
694
|
+
"en-GB": enGB,
|
|
695
|
+
da,
|
|
696
|
+
de,
|
|
697
|
+
cs,
|
|
698
|
+
nl,
|
|
699
|
+
fr,
|
|
700
|
+
fi,
|
|
701
|
+
hu,
|
|
702
|
+
it,
|
|
703
|
+
nb,
|
|
704
|
+
pl,
|
|
705
|
+
pt,
|
|
706
|
+
ru,
|
|
707
|
+
ro,
|
|
708
|
+
es,
|
|
709
|
+
sv,
|
|
710
|
+
ja,
|
|
711
|
+
th,
|
|
712
|
+
};
|
|
713
|
+
/**
|
|
714
|
+
* A helper function to get the matching Locale object for a given language.
|
|
715
|
+
*
|
|
716
|
+
* @param {string} language The language to match
|
|
717
|
+
* @returns {Locale} The corresponding Locale object
|
|
718
|
+
*/
|
|
719
|
+
const useLocale = (language) => {
|
|
720
|
+
return localeLookup[language] || localeLookup.en;
|
|
721
|
+
};
|
|
722
|
+
|
|
863
723
|
/**
|
|
864
|
-
*
|
|
724
|
+
* The DayPicker component is used when the user needs to select a date.
|
|
865
725
|
*
|
|
866
|
-
*
|
|
726
|
+
* @param {DayPickerProps} props - The props for the DayPicker component
|
|
727
|
+
* @returns {JSX.Element} DayPicker component
|
|
867
728
|
*/
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
// Chrome needs it's default icon to have datepicker functionality.
|
|
873
|
-
// window.chrome doesn't exist in TS but is available on chrome browsers.
|
|
874
|
-
// If it fails it will just show our icon.
|
|
875
|
-
const hideOnChrome = () => (window.chrome !== null && typeof window.chrome !== "undefined" ? "hidden" : "");
|
|
876
|
-
return (jsx(BaseInput, Object.assign({ type: "date", value: formatDateToInputString(value), defaultValue: formatDateToInputString(defaultValue), min: formatDateToInputString(min), max: formatDateToInputString(max), ref: ref, suffix: jsx(Icon, { dataTestId: "calendar", name: "CalendarIcon", size: "medium", type: "solid", className: hideOnChrome() }) }, rest)));
|
|
877
|
-
});
|
|
729
|
+
const DayPicker = ({ onDaySelect, disabledDays, selectedDays, language, className, dataTestId, max, }) => {
|
|
730
|
+
const locale = useLocale(language);
|
|
731
|
+
return (jsx(DayPicker$1, { onDayClick: onDaySelect, selected: selectedDays, locale: locale, disabled: disabledDays, className: `custom-day-picker ${className !== null && className !== void 0 ? className : ""}`, max: max, footer: jsx("div", { "data-testid": dataTestId }) }));
|
|
732
|
+
};
|
|
878
733
|
|
|
879
734
|
/**
|
|
880
735
|
* The hook that powers the Popover component.
|
|
@@ -977,9 +832,9 @@ const PopoverContent = React__default.forwardRef(function PopoverContent(_a, pro
|
|
|
977
832
|
* @returns {JSX.Element} PopoverTitle component
|
|
978
833
|
*/
|
|
979
834
|
const PopoverTitle = ({ children, action, divider = false, className, dataTestId }) => {
|
|
980
|
-
return (jsxs(Container$
|
|
835
|
+
return (jsxs(Container$3, Object.assign({ "$divider": divider, className: className, "data-testid": dataTestId }, { children: [jsx(StyledText$1, Object.assign({ type: "div", subtle: true, size: "small", weight: "bold", uppercase: true }, { children: children })), action] })));
|
|
981
836
|
};
|
|
982
|
-
const Container$
|
|
837
|
+
const Container$3 = tw.div `
|
|
983
838
|
tu-popover-title-container
|
|
984
839
|
${p => p.$divider && `tu-popover-title-container--divider`}
|
|
985
840
|
`;
|
|
@@ -1001,134 +856,6 @@ const PopoverTrigger = forwardRef(function PopoverTrigger(_a, propRef) {
|
|
|
1001
856
|
}
|
|
1002
857
|
});
|
|
1003
858
|
|
|
1004
|
-
/**
|
|
1005
|
-
* The Tooltip component is used to show helpful tips or contextual information to the users.
|
|
1006
|
-
*
|
|
1007
|
-
* @param {TooltipProps} props - The props for the Tooltip component
|
|
1008
|
-
* @returns {JSX.Element} Tooltip component
|
|
1009
|
-
*/
|
|
1010
|
-
const Tooltip = (_a) => {
|
|
1011
|
-
var { children, dataTestId, disabled, className } = _a, rest = __rest(_a, ["children", "dataTestId", "disabled", "className"]);
|
|
1012
|
-
const wrappedChildren = (jsx(Flex$1, Object.assign({ className: className, "data-testid": dataTestId && `${dataTestId}-parent` }, { children: children })));
|
|
1013
|
-
if (disabled) {
|
|
1014
|
-
return wrappedChildren;
|
|
1015
|
-
}
|
|
1016
|
-
return (jsx(TooltipContainer, Object.assign({ dataTestId: dataTestId }, rest, { children: wrappedChildren })));
|
|
1017
|
-
};
|
|
1018
|
-
const TooltipContainer = ({ label, placement = "bottom", mode = "dark", contentTextType = "p", children, dataTestId, }) => (jsxs(StyledPopover, Object.assign({ className: "tu-tooltip__container", placement: placement, activation: { hover: true }, dataTestId: dataTestId !== null && dataTestId !== void 0 ? dataTestId : "" }, { children: [jsx(PopoverTrigger, { children: children }), jsx(PopoverContent, { children: jsx(Content, Object.assign({ "$mode": mode }, { children: jsx(Text$1, Object.assign({ inverted: mode === "dark", type: contentTextType }, { children: label })) })) })] })));
|
|
1019
|
-
const Flex$1 = tw.div `
|
|
1020
|
-
inline-flex
|
|
1021
|
-
`;
|
|
1022
|
-
const StyledPopover = twx(Popover) `
|
|
1023
|
-
tu-tooltip__container
|
|
1024
|
-
`;
|
|
1025
|
-
const Content = tw.div `
|
|
1026
|
-
tu-tooltip__content
|
|
1027
|
-
${p => (p.$mode === "light" ? tws `tu-tooltip--light` : null)}
|
|
1028
|
-
`;
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* The Tip component is used to show helpful tips or contextual information to the users.
|
|
1032
|
-
* The tip can optionally be rendered as an anchor tag, which redirects to users to an external link on click.
|
|
1033
|
-
*
|
|
1034
|
-
* @param {TipProps} props - The props for the Tip component
|
|
1035
|
-
* @returns {JSX.Element} Tip component
|
|
1036
|
-
*/
|
|
1037
|
-
const Tip = ({ children, iconProps, dataTestId, link, renderAs = "span", className, placement = "bottom", mode, }) => {
|
|
1038
|
-
const ifAnchorTag = renderAs === "a";
|
|
1039
|
-
return (jsx(TipContainer, Object.assign({ "data-testid": dataTestId, "$as": renderAs, href: ifAnchorTag ? link : undefined, target: ifAnchorTag ? "_blank" : undefined, className: className }, { children: jsx(Tooltip, Object.assign({ label: children, dataTestId: dataTestId && `${dataTestId}-tooltip`, mode: mode, className: "tu-tip-tooltip", placement: placement }, { children: jsx(Icon, Object.assign({ name: "QuestionMarkCircleIcon", size: "medium", dataTestId: dataTestId && `${dataTestId}-icon` }, iconProps)) })) })));
|
|
1040
|
-
};
|
|
1041
|
-
const TipContainer = tw.text `
|
|
1042
|
-
tu-tip
|
|
1043
|
-
`;
|
|
1044
|
-
|
|
1045
|
-
/**
|
|
1046
|
-
* The FormGroup component should be used to wrap any Input element that needs a label.
|
|
1047
|
-
* Besides a label the component supplies an optional Tip, HelpText and HelpAddon support.
|
|
1048
|
-
*
|
|
1049
|
-
* @param {FormGroupProps} props - The props for the FormGroup component
|
|
1050
|
-
* @returns {JSX.Element} FormGroup component
|
|
1051
|
-
*/
|
|
1052
|
-
const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, disabled = false, }) => {
|
|
1053
|
-
return (jsxs(FormGroupRoot, Object.assign({ className: className, "data-testid": dataTestId, "$disabled": disabled }, { children: [jsxs(ContainerBefore, { children: [jsx(FormGroupLabel, Object.assign({ dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label" }, { children: label })), tip && jsx(Tip, Object.assign({ dataTestId: dataTestId && `${dataTestId}-tip` }, { children: tip }))] }), children, jsxs(ContainerAfter, Object.assign({ "$isInvalid": isInvalid }, { children: [helpText && jsx("span", Object.assign({ "data-testid": dataTestId && `${dataTestId}-helpText` }, { children: helpText })), helpAddon && jsx(HelpAddon, Object.assign({ "data-testid": dataTestId && `${dataTestId}-helpAddon` }, { children: helpAddon }))] }))] })));
|
|
1054
|
-
};
|
|
1055
|
-
const FormGroupRoot = tw.div `
|
|
1056
|
-
tu-form-group
|
|
1057
|
-
${({ $disabled }) => {
|
|
1058
|
-
return $disabled ? "pointer-events-none" : null;
|
|
1059
|
-
}}
|
|
1060
|
-
`;
|
|
1061
|
-
const ContainerBefore = tw.div `
|
|
1062
|
-
tu-form-group__container-before
|
|
1063
|
-
`;
|
|
1064
|
-
const FormGroupLabel = twx(Label$2) `
|
|
1065
|
-
component-formGroup-font
|
|
1066
|
-
`;
|
|
1067
|
-
const ContainerAfter = tw.div `
|
|
1068
|
-
tu-form-group__container-after
|
|
1069
|
-
${({ $isInvalid }) => ($isInvalid ? tws `tu-form-group__container-after--invalid` : null)}
|
|
1070
|
-
`;
|
|
1071
|
-
const HelpAddon = tw.span `
|
|
1072
|
-
tu-form-group__help-addon
|
|
1073
|
-
`;
|
|
1074
|
-
|
|
1075
|
-
/**
|
|
1076
|
-
* The date field component is used for entering date values.
|
|
1077
|
-
*
|
|
1078
|
-
* _**Do use**_ the DateField for date input.
|
|
1079
|
-
*
|
|
1080
|
-
* _**Do not use**_ this fields for non-serialized dates. Use TextField instead.
|
|
1081
|
-
*/
|
|
1082
|
-
const DateField = forwardRef((_a, ref) => {
|
|
1083
|
-
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"]);
|
|
1084
|
-
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1085
|
-
const htmlForId = id ? id : "dateField-" + v4();
|
|
1086
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(DateInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, defaultValue: defaultValue, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1087
|
-
});
|
|
1088
|
-
|
|
1089
|
-
const localeLookup = {
|
|
1090
|
-
en: enGB,
|
|
1091
|
-
"en-US": enUS,
|
|
1092
|
-
"en-GB": enGB,
|
|
1093
|
-
da,
|
|
1094
|
-
de,
|
|
1095
|
-
cs,
|
|
1096
|
-
nl,
|
|
1097
|
-
fr,
|
|
1098
|
-
fi,
|
|
1099
|
-
hu,
|
|
1100
|
-
it,
|
|
1101
|
-
nb,
|
|
1102
|
-
pl,
|
|
1103
|
-
pt,
|
|
1104
|
-
ru,
|
|
1105
|
-
ro,
|
|
1106
|
-
es,
|
|
1107
|
-
sv,
|
|
1108
|
-
ja,
|
|
1109
|
-
th,
|
|
1110
|
-
};
|
|
1111
|
-
/**
|
|
1112
|
-
* A helper function to get the matching Locale object for a given language.
|
|
1113
|
-
*
|
|
1114
|
-
* @param {string} language The language to match
|
|
1115
|
-
* @returns {Locale} The corresponding Locale object
|
|
1116
|
-
*/
|
|
1117
|
-
const useLocale = (language) => {
|
|
1118
|
-
return localeLookup[language] || localeLookup.en;
|
|
1119
|
-
};
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* The DayPicker component is used when the user needs to select a date.
|
|
1123
|
-
*
|
|
1124
|
-
* @param {DayPickerProps} props - The props for the DayPicker component
|
|
1125
|
-
* @returns {JSX.Element} DayPicker component
|
|
1126
|
-
*/
|
|
1127
|
-
const DayPicker = ({ onDaySelect, disabledDays, selectedDays, language, className, dataTestId, max, }) => {
|
|
1128
|
-
const locale = useLocale(language);
|
|
1129
|
-
return (jsx(DayPicker$1, { onDayClick: onDaySelect, selected: selectedDays, locale: locale, disabled: disabledDays, className: `custom-day-picker ${className !== null && className !== void 0 ? className : ""}`, max: max, footer: jsx("div", { "data-testid": dataTestId }) }));
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
859
|
/**
|
|
1133
860
|
* The DayPickerPopover component returns a button which when clicked shows the daypicker.
|
|
1134
861
|
*
|
|
@@ -1182,7 +909,7 @@ const Drawer = ({ open, onClose = () => { }, children, disableOverlay = false, p
|
|
|
1182
909
|
window.removeEventListener("keyup", onKeyPress);
|
|
1183
910
|
};
|
|
1184
911
|
}, [open, onClose]);
|
|
1185
|
-
return (jsx(FloatingFocusManager, Object.assign({ context: context }, { children: open ? (jsxs(Root$
|
|
912
|
+
return (jsx(FloatingFocusManager, Object.assign({ context: context }, { children: open ? (jsxs(Root$4, Object.assign({ id: "drawer" }, { children: [!disableOverlay && jsx(Overlay, { "aria-hidden": open, "$open": open, onClick: onClose, id: "drawer__overlay" }), jsx(StyledCard$1, Object.assign({ "aria-hidden": open, "data-testId": dataTestId, "$open": open, "$position": position, id: "drawer__card", className: className }, { children: children }))] }))) : (
|
|
1186
913
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
1187
914
|
jsx(Fragment, {})) })));
|
|
1188
915
|
};
|
|
@@ -1204,7 +931,7 @@ const StyledCard$1 = twx(Card) `
|
|
|
1204
931
|
${({ $open }) => $open && tws `tu-drawer__card--open`}
|
|
1205
932
|
${({ $position }) => getPositionStyles($position)}
|
|
1206
933
|
`;
|
|
1207
|
-
const Root$
|
|
934
|
+
const Root$4 = tw.div `
|
|
1208
935
|
tu-drawer
|
|
1209
936
|
`;
|
|
1210
937
|
const Overlay = tw.div `
|
|
@@ -1212,103 +939,6 @@ const Overlay = tw.div `
|
|
|
1212
939
|
${({ $open }) => $open && tws `tu-drawer__overlay--open`}
|
|
1213
940
|
`;
|
|
1214
941
|
|
|
1215
|
-
/**
|
|
1216
|
-
* The Drop Zone can be used to drag and drop files
|
|
1217
|
-
*
|
|
1218
|
-
* @param {DropZoneProps} props - The props for the DropZone component
|
|
1219
|
-
* @returns {JSX.Element} DropZone component
|
|
1220
|
-
*/
|
|
1221
|
-
const DropZone = (_a) => {
|
|
1222
|
-
var { className, dataTestId, filesSelected, label, size = "large", isInvalid = false, disabled = false } = _a, rest = __rest(_a, ["className", "dataTestId", "filesSelected", "label", "size", "isInvalid", "disabled"]);
|
|
1223
|
-
const [dragActive, setDragActive] = React__default.useState(false);
|
|
1224
|
-
const [fileDropped, setFileDropped] = React__default.useState(false);
|
|
1225
|
-
// function that handles drag enter, drag leave and drag over
|
|
1226
|
-
const handleDrag = (e) => {
|
|
1227
|
-
e.preventDefault();
|
|
1228
|
-
e.stopPropagation();
|
|
1229
|
-
if ((e.type === "dragenter" || e.type === "dragover") && !disabled) {
|
|
1230
|
-
setDragActive(true);
|
|
1231
|
-
}
|
|
1232
|
-
else if (e.type === "dragleave") {
|
|
1233
|
-
setDragActive(false);
|
|
1234
|
-
}
|
|
1235
|
-
};
|
|
1236
|
-
//function to handle when user clicks on dropzone to upload
|
|
1237
|
-
const handleChange = (e) => {
|
|
1238
|
-
e.preventDefault();
|
|
1239
|
-
e.stopPropagation();
|
|
1240
|
-
if (e.target.files && !disabled) {
|
|
1241
|
-
filesSelected(e.target.files);
|
|
1242
|
-
}
|
|
1243
|
-
};
|
|
1244
|
-
//funtion to handle drop
|
|
1245
|
-
const handleDrop = (e) => {
|
|
1246
|
-
e.preventDefault();
|
|
1247
|
-
e.stopPropagation();
|
|
1248
|
-
setDragActive(false);
|
|
1249
|
-
if (e.dataTransfer.files && e.dataTransfer.files[0] && !disabled) {
|
|
1250
|
-
filesSelected(e.dataTransfer.files);
|
|
1251
|
-
setFileDropped(true);
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
return (jsxs(Root$5, 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 => {
|
|
1255
|
-
if (disabled) {
|
|
1256
|
-
e.preventDefault();
|
|
1257
|
-
e.stopPropagation();
|
|
1258
|
-
}
|
|
1259
|
-
} }, rest, { children: [jsx("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxs(DropZoneLabel, Object.assign({ htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label` }, { children: [jsx(Icon, { type: "solid", name: "ArrowUpCircleIcon", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsx("span", { children: label })] }))] })));
|
|
1260
|
-
};
|
|
1261
|
-
const Root$5 = tw.div `
|
|
1262
|
-
tu-drop-zone
|
|
1263
|
-
${({ $size }) => ($size === "small" ? tws `tu-drop-zone--small` : null)}
|
|
1264
|
-
${({ $size }) => ($size === "medium" ? tws `tu-drop-zone--medium` : null)}
|
|
1265
|
-
${({ $size }) => ($size === "large" ? tws `tu-drop-zone--large` : null)}
|
|
1266
|
-
${({ $dragActive }) => ($dragActive ? tws `tu-drop-zone--drag-active` : null)}
|
|
1267
|
-
${({ $fileDropped }) => ($fileDropped ? tws `tu-drop-zone--drop-complete` : null)}
|
|
1268
|
-
${({ $isInvalid }) => ($isInvalid ? tws `tu-drop-zone--invalid` : null)}
|
|
1269
|
-
${({ $disabled }) => ($disabled ? tws `tu-drop-zone--disabled` : null)}
|
|
1270
|
-
`;
|
|
1271
|
-
const DropZoneLabel = tw.label `
|
|
1272
|
-
tu-drop-zone__label
|
|
1273
|
-
`;
|
|
1274
|
-
|
|
1275
|
-
/**
|
|
1276
|
-
* A Email Input component is used for input of the type Email.
|
|
1277
|
-
*
|
|
1278
|
-
* It has an ActionButton which sends an email to the specified address using "mailto:" link.
|
|
1279
|
-
*
|
|
1280
|
-
* Extends props of BaseInput.
|
|
1281
|
-
*
|
|
1282
|
-
* A reference to the input element is provided as the `ref` prop.
|
|
1283
|
-
* For specific input types make sure to use the corresponding input component.
|
|
1284
|
-
*/
|
|
1285
|
-
const EmailInput = React.forwardRef((_a, ref) => {
|
|
1286
|
-
var { fieldSize = "medium", disabled = false, dataTestId } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId"]);
|
|
1287
|
-
const [email, setEmail] = React.useState("");
|
|
1288
|
-
const sendEmail = () => {
|
|
1289
|
-
return window.open(`mailto:${email}`);
|
|
1290
|
-
};
|
|
1291
|
-
return (jsx(BaseInput, Object.assign({ dataTestId: dataTestId, fieldSize: fieldSize, ref: ref, type: "email", placeholder: rest.placeholder || "mail@example.com", onChange: e => setEmail(e.target.value) }, rest, { actions: jsx(ActionButton, { disabled: disabled, value: email, type: "EMAIL", onClick: sendEmail, dataTestId: dataTestId && `${dataTestId}-emailIcon`, iconSize: fieldSize }) })));
|
|
1292
|
-
});
|
|
1293
|
-
|
|
1294
|
-
/**
|
|
1295
|
-
* The EmailField component is used to enter email.
|
|
1296
|
-
* EmailField validates that user enters a valid email address.
|
|
1297
|
-
*
|
|
1298
|
-
*/
|
|
1299
|
-
const EmailField = forwardRef((_a, ref) => {
|
|
1300
|
-
var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId"]);
|
|
1301
|
-
const [value, setValue] = useState(defaultValue);
|
|
1302
|
-
const htmlForId = id ? id : "emailField-" + v4();
|
|
1303
|
-
// Type guard to check if value is a string
|
|
1304
|
-
function isString(inputValue) {
|
|
1305
|
-
return typeof inputValue === "string";
|
|
1306
|
-
}
|
|
1307
|
-
// Check the regular expression only if value is a string
|
|
1308
|
-
const renderAsInvalid = !!errorMessage || (isString(value) && !/^\S+@\S+\.\S+$/.test(value));
|
|
1309
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(EmailInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, value: value, onChange: e => setValue(e.target.value), isInvalid: renderAsInvalid, disabled: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1310
|
-
});
|
|
1311
|
-
|
|
1312
942
|
/**
|
|
1313
943
|
* The external link component is used to link to an external page outside the Trackunit Manager.
|
|
1314
944
|
*
|
|
@@ -1333,9 +963,9 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
|
|
|
1333
963
|
*/
|
|
1334
964
|
const Indicator = (_a) => {
|
|
1335
965
|
var { dataTestId, icon, label, color = "unknown", withBackground = true, withLabel = true, ping = false } = _a, rest = __rest(_a, ["dataTestId", "icon", "label", "color", "withBackground", "withLabel", "ping"]);
|
|
1336
|
-
return (jsxs(Container$
|
|
966
|
+
return (jsxs(Container$2, Object.assign({ "$color": color, "data-testid": dataTestId }, rest, { title: !withLabel ? label : undefined }, { children: [jsxs(IconBackground, Object.assign({ "data-testid": dataTestId ? `${dataTestId}-background` : "indicator-background", "$withBackground": withBackground }, { children: [ping && jsx(Ping, { "data-testid": dataTestId ? `${dataTestId}-ping` : "indicator-ping" }), icon] })), label !== undefined && withLabel && (jsx(Label$1, Object.assign({ "data-testid": dataTestId ? `${dataTestId}-label` : "indicator-label" }, { children: label })))] })));
|
|
1337
967
|
};
|
|
1338
|
-
const Container$
|
|
968
|
+
const Container$2 = tw.div `
|
|
1339
969
|
tu-indicator
|
|
1340
970
|
${({ $color }) => {
|
|
1341
971
|
switch ($color) {
|
|
@@ -1418,12 +1048,12 @@ const Ping = tw.span `
|
|
|
1418
1048
|
*/
|
|
1419
1049
|
const MenuItem = ({ className, dataTestId, label, children, selected, focused, prefix, suffix, disabled, onClick, }) => {
|
|
1420
1050
|
const containerProps = useContainerProps({ className, dataTestId });
|
|
1421
|
-
return (jsxs(Container$
|
|
1051
|
+
return (jsxs(Container$1, Object.assign({}, containerProps, { onClick: e => {
|
|
1422
1052
|
e.stopPropagation();
|
|
1423
1053
|
onClick && onClick(e);
|
|
1424
1054
|
}, "$selected": selected, "$focused": focused, tabIndex: 0, "$disabled": disabled }, { children: [prefix && (jsx(Prefix, Object.assign({ "$selected": selected, "data-testid": dataTestId && `${dataTestId}-prefix` }, { children: prefix }))), children && typeof children !== "string" ? (children) : (jsx(Label, Object.assign({ "data-testid": dataTestId && `${dataTestId}-label` }, { children: children !== null && children !== void 0 ? children : label }))), suffix && (jsx(Suffix, Object.assign({ "$selected": selected, "data-testid": dataTestId && `${dataTestId}-suffix` }, { children: suffix })))] })));
|
|
1425
1055
|
};
|
|
1426
|
-
const Container$
|
|
1056
|
+
const Container$1 = tw.div `
|
|
1427
1057
|
group tu-menu-item
|
|
1428
1058
|
${({ $selected }) => ($selected ? tws `tu-menu-item--selected ` : "tu-menu-item--unselected")}
|
|
1429
1059
|
${({ $focused }) => ($focused ? tws `tu-menu-item--focused ` : "")}
|
|
@@ -1452,9 +1082,9 @@ const MenuList = (_a) => {
|
|
|
1452
1082
|
var { dataTestId, className, children, withStickyHeader = false, showDivider = false } = _a; __rest(_a, ["dataTestId", "className", "children", "withStickyHeader", "showDivider"]);
|
|
1453
1083
|
const childrenArr = Children.toArray(children);
|
|
1454
1084
|
const isLastItem = (index) => index === childrenArr.length - 1;
|
|
1455
|
-
return (jsx(Container
|
|
1085
|
+
return (jsx(Container, Object.assign({ "$withStickyHeader": withStickyHeader, "data-testid": dataTestId, className: className, tabIndex: 0, role: "list" }, { children: Children.map(childrenArr, (menuItem, index) => (jsxs(Fragment, { children: [menuItem, showDivider && !isLastItem(index) && jsx(Divider, {})] }))) })));
|
|
1456
1086
|
};
|
|
1457
|
-
const Container
|
|
1087
|
+
const Container = tw.div `
|
|
1458
1088
|
tu-menu-list
|
|
1459
1089
|
${props => props.$withStickyHeader && tws `tu-menu-list--sticky-header`}
|
|
1460
1090
|
`;
|
|
@@ -1701,11 +1331,11 @@ const MoreMenu = ({ className, dataTestId, dotsDirection = "horizontal", menuPla
|
|
|
1701
1331
|
useClickOutside(actionMenuRef, () => {
|
|
1702
1332
|
setActionMenuIsOpen(false);
|
|
1703
1333
|
});
|
|
1704
|
-
return (jsx(Root$
|
|
1334
|
+
return (jsx(Root$3, Object.assign({ ref: actionMenuRef, className: className, "data-testid": dataTestId }, { children: jsxs(Popover, Object.assign({ placement: menuPlacement }, { children: [jsx(PopoverTrigger, { children: jsx(IconButton, Object.assign({}, iconButtonProps, { icon: jsx(Icon, Object.assign({ name: dotsName }, iconProps)), onClick: () => {
|
|
1705
1335
|
setActionMenuIsOpen(!actionMenuIsOpen);
|
|
1706
1336
|
} })) }), jsx(PopoverContent, { children: close => (typeof children === "function" ? children(close) : children) })] })) })));
|
|
1707
1337
|
};
|
|
1708
|
-
const Root$
|
|
1338
|
+
const Root$3 = tw.div `
|
|
1709
1339
|
tu-more-menu
|
|
1710
1340
|
${({ variant }) => (variant === "primary" ? tws `tu-more-menu--primary` : "")}
|
|
1711
1341
|
`;
|
|
@@ -1784,27 +1414,6 @@ const useModal = ({ closeOnOutsideClick } = {}) => {
|
|
|
1784
1414
|
};
|
|
1785
1415
|
};
|
|
1786
1416
|
|
|
1787
|
-
/**
|
|
1788
|
-
* A thin wrapper around the `BaseInput` component for number input fields.
|
|
1789
|
-
*
|
|
1790
|
-
* NOTE: If shown with a label, please use the `NumberField` component instead.
|
|
1791
|
-
*/
|
|
1792
|
-
const NumberInput = forwardRef((props, ref) => (jsx(BaseInput, Object.assign({ ref: ref, type: "number" }, props))));
|
|
1793
|
-
|
|
1794
|
-
/**
|
|
1795
|
-
* The number field component is used for entering numeric values and includes controls for incrementally increasing or decreasing the value.
|
|
1796
|
-
*
|
|
1797
|
-
* _**Do use**_ the NumberField when the controls to incrementally increase or decrease makes the task easier for the user.
|
|
1798
|
-
*
|
|
1799
|
-
* _**Do not use**_ this fields for non-serialized numbers. Use TextField instead.
|
|
1800
|
-
*/
|
|
1801
|
-
const NumberField = forwardRef((_a, ref) => {
|
|
1802
|
-
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"]);
|
|
1803
|
-
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1804
|
-
const htmlForId = id ? id : "numberField-" + v4();
|
|
1805
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(NumberInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1806
|
-
});
|
|
1807
|
-
|
|
1808
1417
|
/**
|
|
1809
1418
|
* The tag component is used to categorize elements in the ui.
|
|
1810
1419
|
*
|
|
@@ -1859,6 +1468,47 @@ const IconContainer = tw.div `
|
|
|
1859
1468
|
tu-tag__icon-container
|
|
1860
1469
|
`;
|
|
1861
1470
|
|
|
1471
|
+
/**
|
|
1472
|
+
* The Tooltip component is used to show helpful tips or contextual information to the users.
|
|
1473
|
+
*
|
|
1474
|
+
* @param {TooltipProps} props - The props for the Tooltip component
|
|
1475
|
+
* @returns {JSX.Element} Tooltip component
|
|
1476
|
+
*/
|
|
1477
|
+
const Tooltip = (_a) => {
|
|
1478
|
+
var { children, dataTestId, disabled, className } = _a, rest = __rest(_a, ["children", "dataTestId", "disabled", "className"]);
|
|
1479
|
+
const wrappedChildren = (jsx(Flex, Object.assign({ className: className, "data-testid": dataTestId && `${dataTestId}-parent` }, { children: children })));
|
|
1480
|
+
if (disabled) {
|
|
1481
|
+
return wrappedChildren;
|
|
1482
|
+
}
|
|
1483
|
+
return (jsx(TooltipContainer, Object.assign({ dataTestId: dataTestId }, rest, { children: wrappedChildren })));
|
|
1484
|
+
};
|
|
1485
|
+
const TooltipContainer = ({ label, placement = "bottom", mode = "dark", contentTextType = "p", children, dataTestId, }) => (jsxs(StyledPopover, Object.assign({ className: "tu-tooltip__container", placement: placement, activation: { hover: true }, dataTestId: dataTestId !== null && dataTestId !== void 0 ? dataTestId : "" }, { children: [jsx(PopoverTrigger, { children: children }), jsx(PopoverContent, { children: jsx(Content, Object.assign({ "$mode": mode }, { children: jsx(Text$1, Object.assign({ inverted: mode === "dark", type: contentTextType }, { children: label })) })) })] })));
|
|
1486
|
+
const Flex = tw.div `
|
|
1487
|
+
inline-flex
|
|
1488
|
+
`;
|
|
1489
|
+
const StyledPopover = twx(Popover) `
|
|
1490
|
+
tu-tooltip__container
|
|
1491
|
+
`;
|
|
1492
|
+
const Content = tw.div `
|
|
1493
|
+
tu-tooltip__content
|
|
1494
|
+
${p => (p.$mode === "light" ? tws `tu-tooltip--light` : null)}
|
|
1495
|
+
`;
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* The Tip component is used to show helpful tips or contextual information to the users.
|
|
1499
|
+
* The tip can optionally be rendered as an anchor tag, which redirects to users to an external link on click.
|
|
1500
|
+
*
|
|
1501
|
+
* @param {TipProps} props - The props for the Tip component
|
|
1502
|
+
* @returns {JSX.Element} Tip component
|
|
1503
|
+
*/
|
|
1504
|
+
const Tip = ({ children, iconProps, dataTestId, link, renderAs = "span", className, placement = "bottom", mode, }) => {
|
|
1505
|
+
const ifAnchorTag = renderAs === "a";
|
|
1506
|
+
return (jsx(TipContainer, Object.assign({ "data-testid": dataTestId, "$as": renderAs, href: ifAnchorTag ? link : undefined, target: ifAnchorTag ? "_blank" : undefined, className: className }, { children: jsx(Tooltip, Object.assign({ label: children, dataTestId: dataTestId && `${dataTestId}-tooltip`, mode: mode, className: "tu-tip-tooltip", placement: placement }, { children: jsx(Icon, Object.assign({ name: "QuestionMarkCircleIcon", size: "medium", dataTestId: dataTestId && `${dataTestId}-icon` }, iconProps)) })) })));
|
|
1507
|
+
};
|
|
1508
|
+
const TipContainer = tw.text `
|
|
1509
|
+
tu-tip
|
|
1510
|
+
`;
|
|
1511
|
+
|
|
1862
1512
|
/**
|
|
1863
1513
|
* Pageheader component is used to display a page header.
|
|
1864
1514
|
*
|
|
@@ -1970,573 +1620,19 @@ const Pagination = ({ previousPage, nextPage, canPreviousPage, canNextPage, page
|
|
|
1970
1620
|
onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange({ from, to, description });
|
|
1971
1621
|
}, [page, onPageChange, previousPage, nextPage]);
|
|
1972
1622
|
if (loading) {
|
|
1973
|
-
return (jsx(Root$
|
|
1623
|
+
return (jsx(Root$2, Object.assign({ className: className }, { children: jsx(SkeletonLines, { height: 16, width: 150 }) })));
|
|
1974
1624
|
}
|
|
1975
|
-
return (jsxs(Root$
|
|
1625
|
+
return (jsxs(Root$2, Object.assign({ "data-testid": dataTestId, className: className }, { children: [jsx(IconButton, { onClick: () => handlePageChange("prev"), disabled: cursorBase ? !canPreviousPage || false : page !== undefined && page <= 0, "data-testid": "prev-page", icon: jsx(Icon, { name: "ChevronLeftIcon", size: "small" }), size: "small", color: "secondary", variant: "transparent" }), !cursorBase && (jsxs(Fragment, { children: [jsx(TextStyled, Object.assign({ dataTestId: "current-page" }, { children: currentPage })), jsx(TextStyled, Object.assign({ dataTestId: "page-count" }, { children: pageCount !== null && pageCount !== undefined && getTranslatedCount(pageCount) }))] })), jsx(IconButton, { onClick: () => handlePageChange("next"), disabled: cursorBase
|
|
1976
1626
|
? !canNextPage || false
|
|
1977
1627
|
: page !== undefined && pageCount !== undefined && pageCount !== null && page >= pageCount - 1, "data-testid": "next-page", icon: jsx(Icon, { name: "ChevronRightIcon", size: "small" }), size: "small", color: "secondary", variant: "transparent" })] })));
|
|
1978
1628
|
};
|
|
1979
|
-
const Root$
|
|
1629
|
+
const Root$2 = tw.div `
|
|
1980
1630
|
tu-pagination
|
|
1981
1631
|
`;
|
|
1982
1632
|
const TextStyled = twx(Text$1) `
|
|
1983
1633
|
tu-pagination__text
|
|
1984
1634
|
`;
|
|
1985
1635
|
|
|
1986
|
-
/**
|
|
1987
|
-
* The SelectContainer component.
|
|
1988
|
-
*
|
|
1989
|
-
* @param {SelectContainerProps} props - The props for the SelectContainer component
|
|
1990
|
-
* @returns {JSX.Element} SelectContainer component
|
|
1991
|
-
*/
|
|
1992
|
-
const SelectContainer$1 = ({ children, label, hideLabel, id, hasError, error, description, info, dataTestId, isDisabled, }) => {
|
|
1993
|
-
return (jsxs(Container$2, Object.assign({ "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": isDisabled }, { children: [label && !hideLabel && jsx(Label$2, Object.assign({ htmlFor: id }, { children: label })), children, (hasError || info) && (jsx(InformativeText, Object.assign({ size: "small", "$hasError": hasError !== null && hasError !== void 0 ? hasError : false }, { children: hasError ? error : info })))] })));
|
|
1994
|
-
};
|
|
1995
|
-
const Container$2 = tw.label `
|
|
1996
|
-
tu-select__container
|
|
1997
|
-
tu-select
|
|
1998
|
-
${({ $hasError }) => ($hasError ? tws `tu-select--invalid` : null)}
|
|
1999
|
-
${({ $isDisabled }) => ($isDisabled ? tws `tu-select--disabled` : null)}
|
|
2000
|
-
`;
|
|
2001
|
-
const InformativeText = twx(Text$1) `
|
|
2002
|
-
tu-informative-text
|
|
2003
|
-
${p => (p.$hasError ? `tu-informative-text--error` : null)}
|
|
2004
|
-
`;
|
|
2005
|
-
|
|
2006
|
-
/**
|
|
2007
|
-
* @param {MultiValue<Option> | SingleValue<Option>} arg option to check type
|
|
2008
|
-
* @returns {arg is MultiValue<Option> } is Multivalue
|
|
2009
|
-
*/
|
|
2010
|
-
function isMultiValue(arg) {
|
|
2011
|
-
return Array.isArray(arg);
|
|
2012
|
-
}
|
|
2013
|
-
function isGroupBase(arg) {
|
|
2014
|
-
return arg.options !== undefined;
|
|
2015
|
-
}
|
|
2016
|
-
const isSelectedOption = (option, selected) => {
|
|
2017
|
-
if (isGroupBase(option)) {
|
|
2018
|
-
return false;
|
|
2019
|
-
}
|
|
2020
|
-
return isMultiValue(selected)
|
|
2021
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2022
|
-
selected.some(v => v.value === option.value)
|
|
2023
|
-
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2024
|
-
option.value === (selected === null || selected === void 0 ? void 0 : selected.value);
|
|
2025
|
-
};
|
|
2026
|
-
const removeSelectedFromGroups = (group, selected) => {
|
|
2027
|
-
if (isGroupBase(group)) {
|
|
2028
|
-
return Object.assign(Object.assign({}, group), { options: group.options.filter(option => !isSelectedOption(option, selected)) });
|
|
2029
|
-
}
|
|
2030
|
-
return group;
|
|
2031
|
-
};
|
|
2032
|
-
/**
|
|
2033
|
-
* @template IsMulti
|
|
2034
|
-
* @template Group
|
|
2035
|
-
* @param {OptionsOrGroups<Option, Group> | undefined} options An array of options to select from
|
|
2036
|
-
* @param {PropsValue<Option> | undefined} value Selected values
|
|
2037
|
-
* @returns {OptionsOrGroups<Option, Group>} An array of ordered options with selected on top
|
|
2038
|
-
*/
|
|
2039
|
-
const getOrderedOptions = (options, value) => {
|
|
2040
|
-
if (value && options) {
|
|
2041
|
-
const orderedValues = isMultiValue(value)
|
|
2042
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2043
|
-
[...value].sort((a, b) => a.label.localeCompare(b.label))
|
|
2044
|
-
: [value];
|
|
2045
|
-
const selectableOptions = options
|
|
2046
|
-
.filter(option => !isSelectedOption(option, value))
|
|
2047
|
-
.map(option => removeSelectedFromGroups(option, value));
|
|
2048
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2049
|
-
return orderedValues.concat(selectableOptions) || [];
|
|
2050
|
-
}
|
|
2051
|
-
return options || [];
|
|
2052
|
-
};
|
|
2053
|
-
const SelectPrefix = tw.div `
|
|
2054
|
-
tu-select__prefix
|
|
2055
|
-
`;
|
|
2056
|
-
|
|
2057
|
-
/**
|
|
2058
|
-
* A single select menu item is a basic wrapper around Menu item designed to be used as a single value render in Select list
|
|
2059
|
-
*
|
|
2060
|
-
* @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
|
|
2061
|
-
* @returns {JSX.Element} SingleSelectMenuItem
|
|
2062
|
-
*/
|
|
2063
|
-
const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, focused, disabled, }) => {
|
|
2064
|
-
return (jsx(MenuItem, { dataTestId: dataTestId, label: label, prefix: icon, onClick: onClick, selected: selected, disabled: disabled, focused: focused, suffix: selected ? jsx(Icon, { name: "CheckIcon", size: "small" }) : undefined }));
|
|
2065
|
-
};
|
|
2066
|
-
/**
|
|
2067
|
-
* A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
|
|
2068
|
-
*
|
|
2069
|
-
* @param {SelectMenuItemProps} props - The props for the MultiSelectMenuItem
|
|
2070
|
-
* @returns {JSX.Element} multi select menu item
|
|
2071
|
-
*/
|
|
2072
|
-
const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, focused, disabled, }) => {
|
|
2073
|
-
return (jsx(MenuItem, { dataTestId: dataTestId, label: label, disabled: disabled, prefix: jsx(Checkbox, { checked: selected, readOnly: false, onChange: () => null, disabled: disabled, onClick: e => {
|
|
2074
|
-
e.stopPropagation();
|
|
2075
|
-
} }), onClick: e => {
|
|
2076
|
-
e.stopPropagation();
|
|
2077
|
-
onClick && onClick(e);
|
|
2078
|
-
}, selected: selected, focused: focused }));
|
|
2079
|
-
};
|
|
2080
|
-
|
|
2081
|
-
/**
|
|
2082
|
-
* Extended Tag component with information about its own width.
|
|
2083
|
-
* Used in the select component.
|
|
2084
|
-
*
|
|
2085
|
-
* @param {TagProps} props - The props for the tag component
|
|
2086
|
-
* @returns {JSX.Element} TagWithWidth component
|
|
2087
|
-
*/
|
|
2088
|
-
const TagWithWidth = (_a) => {
|
|
2089
|
-
var { onWidthKnown, children } = _a, rest = __rest(_a, ["onWidthKnown", "children"]);
|
|
2090
|
-
const ref = React__default.useRef(null);
|
|
2091
|
-
React__default.useLayoutEffect(() => {
|
|
2092
|
-
var _a;
|
|
2093
|
-
onWidthKnown && onWidthKnown({ width: ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0 });
|
|
2094
|
-
}, [ref, onWidthKnown]);
|
|
2095
|
-
return (jsx(Tag, Object.assign({ ref: ref }, rest, { children: children })));
|
|
2096
|
-
};
|
|
2097
|
-
|
|
2098
|
-
/**
|
|
2099
|
-
* TagsContainer component to display tags in limited space when children can't fit space it displays counter
|
|
2100
|
-
*
|
|
2101
|
-
* @param {TagsContainerProps} props - The props for the TagContainer
|
|
2102
|
-
* @returns {JSX.Element} TagsContainer
|
|
2103
|
-
*/
|
|
2104
|
-
const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix }) => {
|
|
2105
|
-
const [isReady, setIsReady] = React__default.useState(false);
|
|
2106
|
-
const [counterWidth, setCounterWidth] = React__default.useState(0);
|
|
2107
|
-
const containerRef = React__default.useRef(null);
|
|
2108
|
-
const availableWidth = React__default.useRef();
|
|
2109
|
-
const childrenWidth = React__default.useRef([]);
|
|
2110
|
-
const itemsCount = items.length;
|
|
2111
|
-
React__default.useLayoutEffect(() => {
|
|
2112
|
-
var _a;
|
|
2113
|
-
availableWidth.current = ((_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
2114
|
-
}, [containerRef]);
|
|
2115
|
-
const onWidthKnownHandler = ({ width: reportedWidth }) => {
|
|
2116
|
-
childrenWidth.current.push({ width: reportedWidth + itemsGap });
|
|
2117
|
-
if (childrenWidth.current.length === itemsCount) {
|
|
2118
|
-
setIsReady(true);
|
|
2119
|
-
}
|
|
2120
|
-
};
|
|
2121
|
-
const requiredSpace = childrenWidth.current.reduce((previous, current) => {
|
|
2122
|
-
return previous + current.width;
|
|
2123
|
-
}, 0);
|
|
2124
|
-
let counter = 0;
|
|
2125
|
-
const availableSpace = ((availableWidth === null || availableWidth === void 0 ? void 0 : availableWidth.current) || 0) - counterWidth;
|
|
2126
|
-
const renderedElements = items
|
|
2127
|
-
.concat({ text: "", onClick: () => null, disabled: false }) // reserved element for a potential counter
|
|
2128
|
-
.map((item, index) => {
|
|
2129
|
-
const spaceNeeded = childrenWidth.current.slice(0, index + 1).reduce((previous, current) => {
|
|
2130
|
-
return previous + current.width;
|
|
2131
|
-
}, 0);
|
|
2132
|
-
const isLast = index === items.length;
|
|
2133
|
-
const counterRequired = requiredSpace > availableSpace && counter !== 0;
|
|
2134
|
-
if (isLast && counterRequired) {
|
|
2135
|
-
return (jsx(TagWithWidth, Object.assign({ onWidthKnown: ({ width: reportedWidth }) => setCounterWidth(reportedWidth), color: "neutral" }, { children: jsxs(Counter, { children: ["+", counter] }) }), item.text + index));
|
|
2136
|
-
}
|
|
2137
|
-
if (isLast) {
|
|
2138
|
-
return null;
|
|
2139
|
-
}
|
|
2140
|
-
const itemCanFit = spaceNeeded <= availableSpace;
|
|
2141
|
-
if (itemCanFit) {
|
|
2142
|
-
return (jsx(TagWithWidth, Object.assign({ onWidthKnown: onWidthKnownHandler, className: tws `shrink-0 inline-flex`, onClose: e => {
|
|
2143
|
-
e.stopPropagation();
|
|
2144
|
-
item.onClick();
|
|
2145
|
-
}, color: item.disabled ? "unknown" : "primary", dataTestId: item.text }, { children: item.text }), item.text + index));
|
|
2146
|
-
}
|
|
2147
|
-
const fromTheItems = item.text !== "";
|
|
2148
|
-
if (fromTheItems) {
|
|
2149
|
-
counter = counter + 1;
|
|
2150
|
-
}
|
|
2151
|
-
return null;
|
|
2152
|
-
})
|
|
2153
|
-
.filter(element => element !== null);
|
|
2154
|
-
return (jsxs(Container$1, Object.assign({ style: {
|
|
2155
|
-
width: `${width}`,
|
|
2156
|
-
}, "$ready": isReady, ref: containerRef }, { children: [renderedElements, postFix] })));
|
|
2157
|
-
};
|
|
2158
|
-
const Container$1 = tw.div `
|
|
2159
|
-
tu-select__dynamic-tag--container
|
|
2160
|
-
${({ $ready }) => {
|
|
2161
|
-
return $ready ? tws `visible` : tws `invisible`;
|
|
2162
|
-
}}
|
|
2163
|
-
`;
|
|
2164
|
-
const Counter = tw.div `
|
|
2165
|
-
tu-select__counter
|
|
2166
|
-
`;
|
|
2167
|
-
|
|
2168
|
-
/**
|
|
2169
|
-
* A hook to retrieve components override object.
|
|
2170
|
-
* 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.
|
|
2171
|
-
*
|
|
2172
|
-
* @template IsMulti
|
|
2173
|
-
* @template Group
|
|
2174
|
-
* @param {Partial<SelectComponents<Option, IsMulti, Group>> | undefined} componentsProps a custom component prop that you can to override defaults
|
|
2175
|
-
* @param {boolean} disabled decide to override disabled variant
|
|
2176
|
-
* @param {boolean} menuIsOpen menu is open state
|
|
2177
|
-
* @param {React.MutableRefObject<boolean>} refMenuIsEnabled a flag to block menu from open
|
|
2178
|
-
* @param {string} dataTestId a test id
|
|
2179
|
-
* @param {number} maxSelectedDisplayCount a number of max display count
|
|
2180
|
-
* @param {JSX.Element} dropdownIcon an custom dropdown icon
|
|
2181
|
-
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
2182
|
-
*/
|
|
2183
|
-
const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon) => {
|
|
2184
|
-
// perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
|
|
2185
|
-
const customComponents = React.useMemo(() => {
|
|
2186
|
-
return Object.assign({ ValueContainer: props => {
|
|
2187
|
-
if (props.isMulti) {
|
|
2188
|
-
const PLACEHOLDER_KEY = "placeholder";
|
|
2189
|
-
const key = props && props.children && props.children[0] ? props.children[0].key : "";
|
|
2190
|
-
const values = props && props.children ? props.children[0] : [];
|
|
2191
|
-
const tags = key === PLACEHOLDER_KEY ? [] : values;
|
|
2192
|
-
const searchInput = props && props.children && props.children[1];
|
|
2193
|
-
return (jsx(components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled }, { children: maxSelectedDisplayCount === undefined ? (jsx(TagsContainer, { width: "100%", items: tags
|
|
2194
|
-
? tags.map(({ props: tagProps }) => {
|
|
2195
|
-
return {
|
|
2196
|
-
text: tagProps.children,
|
|
2197
|
-
onClick: disabled
|
|
2198
|
-
? undefined
|
|
2199
|
-
: (e) => {
|
|
2200
|
-
var _a, _b;
|
|
2201
|
-
refMenuIsEnabled.current = false;
|
|
2202
|
-
((_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));
|
|
2203
|
-
},
|
|
2204
|
-
disabled: disabled,
|
|
2205
|
-
};
|
|
2206
|
-
})
|
|
2207
|
-
: [], postFix: searchInput })) : (jsxs(Fragment, { children: [tags &&
|
|
2208
|
-
tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
|
|
2209
|
-
var _a, _b;
|
|
2210
|
-
return (jsx(Tag, Object.assign({ className: tws `shrink-0 inline-flex`, onClose: e => {
|
|
2211
|
-
var _a, _b;
|
|
2212
|
-
e.stopPropagation();
|
|
2213
|
-
refMenuIsEnabled.current = false;
|
|
2214
|
-
((_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));
|
|
2215
|
-
}, 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()));
|
|
2216
|
-
}), tags && tags.length > maxSelectedDisplayCount && (jsxs(Tag, Object.assign({ color: "neutral", dataTestId: "counter" }, { children: ["+", tags.length - maxSelectedDisplayCount] }))), searchInput] })) })));
|
|
2217
|
-
}
|
|
2218
|
-
return (jsx(components.ValueContainer, Object.assign({}, props, { isDisabled: props.selectProps.isDisabled }, { children: props.children })));
|
|
2219
|
-
}, LoadingIndicator: props => {
|
|
2220
|
-
return jsx(Spinner, { size: "small", className: tws `mt-1.5 mr-1` });
|
|
2221
|
-
}, DropdownIndicator: props => {
|
|
2222
|
-
const icon = props.selectProps.menuIsOpen ? (jsx(Icon, { name: "ChevronUpIcon", size: "medium" })) : (jsx(Icon, { name: "ChevronDownIcon", size: "medium" }));
|
|
2223
|
-
return props.selectProps.isLoading ? null : (jsx(components.DropdownIndicator, Object.assign({}, props, { children: jsx(StyledIcon, { children: dropdownIcon ? dropdownIcon : icon }) })));
|
|
2224
|
-
}, IndicatorSeparator: () => null, ClearIndicator: props => {
|
|
2225
|
-
if (disabled) {
|
|
2226
|
-
return null;
|
|
2227
|
-
}
|
|
2228
|
-
return (jsx(components.ClearIndicator, Object.assign({}, props, { children: jsx(XMarkIcon, Object.assign({ onClick: props.clearValue, "data-testid": dataTestId && `${dataTestId}-XMarkIcon` }, { children: jsx(Icon, { name: "XCircleIcon", size: "medium" }) })) })));
|
|
2229
|
-
}, Control: props => {
|
|
2230
|
-
return (jsx(components.Control, Object.assign({}, props, { className: props.isDisabled ? tws `tu-select__control--disabled` : "" })));
|
|
2231
|
-
}, SingleValue: props => {
|
|
2232
|
-
return (jsx(components.SingleValue, Object.assign({}, props, { className: props.isDisabled ? tws `tu-select__single-value--disabled` : "" }, { children: jsx("div", Object.assign({ "data-testid": dataTestId + "-singleValue" }, { children: props.children })) })));
|
|
2233
|
-
}, Menu: props => {
|
|
2234
|
-
return (jsx(components.Menu, Object.assign({}, props, { className: props.selectProps.menuIsOpen
|
|
2235
|
-
? tws `tu-select__menu-list animate-fade-in-fast`
|
|
2236
|
-
: tws `tu-select__menu-list animate-fade-out-fast` })));
|
|
2237
|
-
}, Option: props => {
|
|
2238
|
-
const componentProps = {
|
|
2239
|
-
label: props.label,
|
|
2240
|
-
focused: props.isFocused,
|
|
2241
|
-
selected: props.isSelected,
|
|
2242
|
-
onClick: props.innerProps.onClick,
|
|
2243
|
-
};
|
|
2244
|
-
return (jsx(components.Option, Object.assign({}, props, { innerProps: Object.assign(Object.assign({}, props.innerProps), { role: "option", onClick: () => { } }) }, { children: props.isMulti ? (jsx(MultiSelectMenuItem, Object.assign({}, componentProps, { disabled: disabled, dataTestId: props.label }))) : (jsx(SingleSelectMenuItem, Object.assign({}, componentProps, { disabled: disabled || props.isDisabled, dataTestId: props.label }))) })));
|
|
2245
|
-
} }, componentsProps);
|
|
2246
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2247
|
-
}, [componentsProps, disabled, maxSelectedDisplayCount]); // do not add dropdownIcon (it will cause issue with opening/closing list for selects with custom icon)
|
|
2248
|
-
return customComponents;
|
|
2249
|
-
};
|
|
2250
|
-
const StyledIcon = tw.div `
|
|
2251
|
-
tu-select--icon
|
|
2252
|
-
`;
|
|
2253
|
-
const XMarkIcon = tw.div `
|
|
2254
|
-
tu-select--icon
|
|
2255
|
-
tu-select__x-icon
|
|
2256
|
-
`;
|
|
2257
|
-
|
|
2258
|
-
/**
|
|
2259
|
-
* @template IsMulti
|
|
2260
|
-
* @template Group
|
|
2261
|
-
* @param {React.RefObject<HTMLDivElement>} refContainer react ref to container element
|
|
2262
|
-
* @param {React.RefObject<HTMLDivElement>} refPrefix react ref to prefix element
|
|
2263
|
-
* @param {number | undefined} maxSelectedDisplayCount a number of max display count
|
|
2264
|
-
* @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
|
|
2265
|
-
* @returns {StylesConfig<Option, boolean>} styles to override in select
|
|
2266
|
-
*/
|
|
2267
|
-
const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles) => {
|
|
2268
|
-
const customStyles = React.useMemo(() => {
|
|
2269
|
-
return Object.assign({ control: base => {
|
|
2270
|
-
return Object.assign(Object.assign({}, base), { border: "0", boxShadow: "0", "&:hover": {
|
|
2271
|
-
border: "0",
|
|
2272
|
-
}, marginRight: "2px", backgroundColor: "" });
|
|
2273
|
-
}, singleValue: base => (Object.assign({}, base)), multiValue: base => (Object.assign({}, base)), multiValueLabel: base => (Object.assign({}, base)), indicatorsContainer: base => (Object.assign({}, base)), indicatorSeparator: () => ({
|
|
2274
|
-
width: "0px",
|
|
2275
|
-
}), menu: base => {
|
|
2276
|
-
return Object.assign(Object.assign({}, base), { width: "100%", marginTop: "4px", marginBottom: "18px", transition: "all 1s ease-in-out" });
|
|
2277
|
-
}, 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 => {
|
|
2278
|
-
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" });
|
|
2279
|
-
}, valueContainer: base => {
|
|
2280
|
-
return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
|
|
2281
|
-
}, 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 => {
|
|
2282
|
-
return Object.assign(Object.assign({}, base), { padding: "0px" });
|
|
2283
|
-
} }, styles);
|
|
2284
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2285
|
-
}, [refContainer, refPrefix]);
|
|
2286
|
-
return { customStyles };
|
|
2287
|
-
};
|
|
2288
|
-
|
|
2289
|
-
/**
|
|
2290
|
-
* A hook used by selects to share the common code
|
|
2291
|
-
*
|
|
2292
|
-
* @param {SelectProps} props - The props for the Select component
|
|
2293
|
-
* @returns {IUseSelect} Select component
|
|
2294
|
-
*/
|
|
2295
|
-
const useSelect = (_a) => {
|
|
2296
|
-
var _b;
|
|
2297
|
-
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"]);
|
|
2298
|
-
const refContainer = React__default.useRef(null);
|
|
2299
|
-
const refPrefix = React__default.useRef(null);
|
|
2300
|
-
const { customStyles } = useCustomStyles(refContainer, refPrefix, maxSelectedDisplayCount, styles);
|
|
2301
|
-
const [menuIsOpen, setMenuIsOpen] = React__default.useState((_b = props.menuIsOpen) !== null && _b !== void 0 ? _b : false);
|
|
2302
|
-
const refMenuIsEnabled = React__default.useRef(true);
|
|
2303
|
-
const customComponents = useCustomComponents(components, disabled || false, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon);
|
|
2304
|
-
const menuPlacement = "auto";
|
|
2305
|
-
const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
2306
|
-
onMenuOpen && onMenuOpen();
|
|
2307
|
-
if (refMenuIsEnabled.current) {
|
|
2308
|
-
setMenuIsOpen(true);
|
|
2309
|
-
}
|
|
2310
|
-
else {
|
|
2311
|
-
refMenuIsEnabled.current = true;
|
|
2312
|
-
}
|
|
2313
|
-
});
|
|
2314
|
-
const closeMenuHandler = () => {
|
|
2315
|
-
setMenuIsOpen(false);
|
|
2316
|
-
onMenuClose && onMenuClose();
|
|
2317
|
-
};
|
|
2318
|
-
const orderedOptions = React__default.useMemo(() => {
|
|
2319
|
-
return disabled
|
|
2320
|
-
? getOrderedOptions(options, value).map(option => {
|
|
2321
|
-
return Object.assign(Object.assign({}, option), { disabled: true });
|
|
2322
|
-
})
|
|
2323
|
-
: getOrderedOptions(options, value);
|
|
2324
|
-
}, [options, value, disabled]);
|
|
2325
|
-
return {
|
|
2326
|
-
refContainer,
|
|
2327
|
-
refPrefix,
|
|
2328
|
-
customStyles,
|
|
2329
|
-
menuIsOpen,
|
|
2330
|
-
customComponents,
|
|
2331
|
-
menuPlacement,
|
|
2332
|
-
openMenuHandler,
|
|
2333
|
-
closeMenuHandler,
|
|
2334
|
-
orderedOptions,
|
|
2335
|
-
};
|
|
2336
|
-
};
|
|
2337
|
-
|
|
2338
|
-
/**
|
|
2339
|
-
* The CreatableSelect component.
|
|
2340
|
-
*
|
|
2341
|
-
* @param {CreateableSelectProps} props - The props for the CreatableSelect component
|
|
2342
|
-
* @returns {JSX.Element} CreatableSelect component
|
|
2343
|
-
*/
|
|
2344
|
-
const CreatableSelect = (props) => {
|
|
2345
|
-
const { id, dataTestId = "select", async, maxMenuHeight = 200, label, error, disabled, isMulti, value, hideLabel, description, info, options, onChange, isLoading, classNamePrefix = "", filterOption, prefix, } = props;
|
|
2346
|
-
const hasError = !!error;
|
|
2347
|
-
const { refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
2348
|
-
const selectProps = {
|
|
2349
|
-
value,
|
|
2350
|
-
menuPlacement,
|
|
2351
|
-
maxMenuHeight,
|
|
2352
|
-
onChange,
|
|
2353
|
-
"aria-label": label,
|
|
2354
|
-
"data-testid": dataTestId,
|
|
2355
|
-
components: customComponents,
|
|
2356
|
-
styles: customStyles,
|
|
2357
|
-
tabSelectsValue: false,
|
|
2358
|
-
blurInputOnSelect: !isMulti,
|
|
2359
|
-
menuPortalTarget: document.body,
|
|
2360
|
-
isSearchable: disabled ? false : true,
|
|
2361
|
-
menuShouldBlockScroll: true,
|
|
2362
|
-
menuShouldScrollIntoView: true,
|
|
2363
|
-
openMenuOnFocus: disabled ? false : true,
|
|
2364
|
-
menuIsOpen: disabled ? false : menuIsOpen,
|
|
2365
|
-
openMenuOnClick: true,
|
|
2366
|
-
closeMenuOnSelect: false,
|
|
2367
|
-
isMulti: isMulti,
|
|
2368
|
-
classNamePrefix,
|
|
2369
|
-
isLoading,
|
|
2370
|
-
id,
|
|
2371
|
-
};
|
|
2372
|
-
return (jsx(SelectContainer$1, Object.assign({ label: label, hideLabel: hideLabel, id: id, hasError: hasError, error: error, description: description, info: info, dataTestId: dataTestId, isDisabled: disabled }, { children: jsxs(Fragment, { children: [prefix !== undefined && (jsx(SelectPrefix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix }, { children: prefix }))), async ? (jsx(ReactAsyncCreatableSelect, Object.assign({ "aria-label": label, maxMenuHeight: maxMenuHeight, "data-testid": dataTestId, components: customComponents }, props, { onMenuOpen: () => {
|
|
2373
|
-
!disabled && openMenuHandler();
|
|
2374
|
-
}, onMenuClose: () => {
|
|
2375
|
-
closeMenuHandler();
|
|
2376
|
-
} }))) : (jsx(ReactCreatableSelect, Object.assign({}, selectProps, { options: filterOption ? orderedOptions : options, isMulti: isMulti, onMenuOpen: () => {
|
|
2377
|
-
!disabled && openMenuHandler();
|
|
2378
|
-
}, onMenuClose: () => {
|
|
2379
|
-
closeMenuHandler();
|
|
2380
|
-
} })))] }) })));
|
|
2381
|
-
};
|
|
2382
|
-
|
|
2383
|
-
/**
|
|
2384
|
-
* Selects are input components used to choose a value from a set.
|
|
2385
|
-
*
|
|
2386
|
-
* @param {SelectProps} props - The props for the Select component
|
|
2387
|
-
* @returns {JSX.Element} Select component
|
|
2388
|
-
*/
|
|
2389
|
-
const Select = (props) => {
|
|
2390
|
-
const { className } = props, propsNoClassName = __rest(props, ["className"]);
|
|
2391
|
-
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = "", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable, } = props;
|
|
2392
|
-
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
2393
|
-
const selectProps = {
|
|
2394
|
-
value,
|
|
2395
|
-
menuPlacement,
|
|
2396
|
-
maxMenuHeight,
|
|
2397
|
-
onChange,
|
|
2398
|
-
"aria-label": label,
|
|
2399
|
-
"data-testid": dataTestId,
|
|
2400
|
-
components: customComponents,
|
|
2401
|
-
styles: customStyles,
|
|
2402
|
-
tabSelectsValue: false,
|
|
2403
|
-
blurInputOnSelect: !isMulti,
|
|
2404
|
-
menuPortalTarget: props.menuPortalTarget || document.body,
|
|
2405
|
-
isSearchable: disabled ? false : isSearchable,
|
|
2406
|
-
menuShouldBlockScroll: true,
|
|
2407
|
-
menuShouldScrollIntoView: true,
|
|
2408
|
-
openMenuOnFocus: true,
|
|
2409
|
-
menuIsOpen,
|
|
2410
|
-
openMenuOnClick: true,
|
|
2411
|
-
closeMenuOnSelect: false,
|
|
2412
|
-
isMulti,
|
|
2413
|
-
classNamePrefix,
|
|
2414
|
-
isLoading,
|
|
2415
|
-
isClearable,
|
|
2416
|
-
id,
|
|
2417
|
-
onMenuScrollToBottom,
|
|
2418
|
-
onInputChange,
|
|
2419
|
-
};
|
|
2420
|
-
return (jsxs(SelectContainer, Object.assign({ ref: refContainer, className: className, "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": disabled }, { children: [prefix !== undefined && (jsx(SelectPrefix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix }, { children: prefix }))), async ? (jsx(ReactAsyncSelect, Object.assign({}, propsNoClassName, selectProps, async, { onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler }))) : (jsx(ReactSelect, Object.assign({}, propsNoClassName, selectProps, { options: filterOption ? orderedOptions : options, hideSelectedOptions: false, isMulti: isMulti, onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler })))] })));
|
|
2421
|
-
};
|
|
2422
|
-
const SelectContainer = tw.div `
|
|
2423
|
-
tu-select
|
|
2424
|
-
${({ $hasError }) => ($hasError ? tws `tu-select--invalid` : null)}
|
|
2425
|
-
${({ $isDisabled }) => ($isDisabled ? tws `tu-select--disabled` : null)}
|
|
2426
|
-
`;
|
|
2427
|
-
Select.displayName = "Select";
|
|
2428
|
-
|
|
2429
|
-
const COUNTRY_CODES_NOT_SUPPORTED_BY_BACKEND = ["53", "98", "211", "247", "249", "383", "850", "963"];
|
|
2430
|
-
const ADDITIONAL_COUNTRY_CODES_SUPPORTED_BY_BACKEND = [
|
|
2431
|
-
"1242",
|
|
2432
|
-
"1246",
|
|
2433
|
-
"1264",
|
|
2434
|
-
"1268",
|
|
2435
|
-
"1284",
|
|
2436
|
-
"1340",
|
|
2437
|
-
"1345",
|
|
2438
|
-
"1441",
|
|
2439
|
-
"1473",
|
|
2440
|
-
"1649",
|
|
2441
|
-
"1664",
|
|
2442
|
-
"1670",
|
|
2443
|
-
"1671",
|
|
2444
|
-
"1684",
|
|
2445
|
-
"1721",
|
|
2446
|
-
"1758",
|
|
2447
|
-
"1767",
|
|
2448
|
-
"1784",
|
|
2449
|
-
"1809",
|
|
2450
|
-
"1868",
|
|
2451
|
-
"1869",
|
|
2452
|
-
"1876",
|
|
2453
|
-
"379",
|
|
2454
|
-
"5999",
|
|
2455
|
-
"881",
|
|
2456
|
-
"882",
|
|
2457
|
-
"883",
|
|
2458
|
-
];
|
|
2459
|
-
const countryCodesSet = [
|
|
2460
|
-
...new Set(getCountries().map(code => getCountryCallingCode(code))),
|
|
2461
|
-
...ADDITIONAL_COUNTRY_CODES_SUPPORTED_BY_BACKEND,
|
|
2462
|
-
]
|
|
2463
|
-
.filter(code => !COUNTRY_CODES_NOT_SUPPORTED_BY_BACKEND.includes(code))
|
|
2464
|
-
.sort((a, b) => Number(a) - Number(b));
|
|
2465
|
-
const countryCodes = countryCodesSet.map(code => ({ label: `+${code}`, value: code }));
|
|
2466
|
-
|
|
2467
|
-
/**
|
|
2468
|
-
* The CountryCodeSelect component is used to select a country code for a phone number.
|
|
2469
|
-
*
|
|
2470
|
-
* @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
|
|
2471
|
-
* @returns {JSX.Element} CountryCodeSelect component
|
|
2472
|
-
*/
|
|
2473
|
-
const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, setCountryCode, }) => {
|
|
2474
|
-
const [isCountryCodeMissing, setIsCountryCodeMissing] = useState(false);
|
|
2475
|
-
useEffect(() => {
|
|
2476
|
-
countryCode && setIsCountryCodeMissing(false);
|
|
2477
|
-
}, [countryCode]);
|
|
2478
|
-
const filteredCodes = countryCodes.filter(code => {
|
|
2479
|
-
return !(excludedCountries === null || excludedCountries === void 0 ? void 0 : excludedCountries.some(excludedCode => excludedCode.value === code.value));
|
|
2480
|
-
});
|
|
2481
|
-
return (jsx(Select, { className: "w-28", "aria-invalid": isCountryCodeMissing, options: filteredCodes.map(code => code), value: filteredCodes.find(({ value: currentValue }) => currentValue === countryCode), onChange: input => {
|
|
2482
|
-
setCountryCode(input === null || input === void 0 ? void 0 : input.value);
|
|
2483
|
-
}, placeholder: "+45", hasError: isCountryCodeMissing || isInvalid, maxMenuHeight: 200 }));
|
|
2484
|
-
};
|
|
2485
|
-
|
|
2486
|
-
/**
|
|
2487
|
-
* A component for inputting phone numbers with an optional action button for initiating a phone call.
|
|
2488
|
-
*
|
|
2489
|
-
* @param {string} [dataTestId] - The data test ID for the component.
|
|
2490
|
-
* @param {boolean} [disabled=false] - Whether the component is disabled or not.
|
|
2491
|
-
* @param {string} [fieldSize="medium"] - The size of the input field.
|
|
2492
|
-
* @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
|
|
2493
|
-
* @returns {JSX.Element} - The PhoneInput component.
|
|
2494
|
-
*/
|
|
2495
|
-
const PhoneInput = forwardRef((_a, ref) => {
|
|
2496
|
-
var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction"]);
|
|
2497
|
-
const [phoneNumber, setPhoneNumber] = useState();
|
|
2498
|
-
const [renderAsInvalid, setRenderAsInvalid] = useState(false);
|
|
2499
|
-
const [countryCode, setCountryCode] = useState(undefined);
|
|
2500
|
-
const [isPhoneNumberInvalid, setIsPhoneNumberInvalid] = useState(false);
|
|
2501
|
-
const handlePhoneNumberChange = (e) => {
|
|
2502
|
-
const input = e.target.value;
|
|
2503
|
-
setIsPhoneNumberInvalid(!Boolean(input));
|
|
2504
|
-
setPhoneNumber(input);
|
|
2505
|
-
};
|
|
2506
|
-
useEffect(() => {
|
|
2507
|
-
setRenderAsInvalid(isInvalid || isPhoneNumberInvalid);
|
|
2508
|
-
}, [isInvalid, isPhoneNumberInvalid]);
|
|
2509
|
-
return (jsxs(Container, { children: [jsx(CountryCodeSelect, { isInvalid: renderAsInvalid, countryCode: countryCode, setCountryCode: setCountryCode }), jsx(BaseInput, Object.assign({ ref: ref, dataTestId: dataTestId, isInvalid: renderAsInvalid, fieldSize: fieldSize, type: "tel", value: phoneNumber, onChange: handlePhoneNumberChange, disabled: disabled, actions: !disableAction && (jsx(ActionButton, { disabled: !countryCode || !phoneNumber || disabled || renderAsInvalid, value: `${countryCode}${phoneNumber}`, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
|
|
2510
|
-
});
|
|
2511
|
-
const Container = tw.div `
|
|
2512
|
-
grid
|
|
2513
|
-
grid-cols-min-fr
|
|
2514
|
-
gap-2
|
|
2515
|
-
`;
|
|
2516
|
-
|
|
2517
|
-
/**
|
|
2518
|
-
* The PhoneField component is used to enter phone number.
|
|
2519
|
-
* It is a wrapper around the PhoneInput component and the FormGroup component.
|
|
2520
|
-
* It is used to render a phone number field with a label, a tip, a help text, a help addon and an error message.
|
|
2521
|
-
*
|
|
2522
|
-
* @param {string} [label] - The label for the component.
|
|
2523
|
-
* @param {string} [tip] - The tip for the component.
|
|
2524
|
-
* @param {string} [helpText] - The help text for the component.
|
|
2525
|
-
* @param {string} [helpAddon] - The help addon for the component.
|
|
2526
|
-
* @param {string} [errorMessage] - The error message for the component.
|
|
2527
|
-
* @param {string} [defaultValue] - The default value for the component.
|
|
2528
|
-
* @param {boolean} [disabled=false] - Whether the component is disabled or not.
|
|
2529
|
-
* @param {string} [fieldSize="medium"] - The size of the input field.
|
|
2530
|
-
* @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
|
|
2531
|
-
* @returns {JSX.Element} - The PhoneField component.
|
|
2532
|
-
*/
|
|
2533
|
-
const PhoneField = forwardRef((_a, ref) => {
|
|
2534
|
-
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"]);
|
|
2535
|
-
const renderAsInvalid = isInvalid || Boolean(errorMessage);
|
|
2536
|
-
const htmlForId = id ? id : "phoneField-" + v4();
|
|
2537
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: value || defaultValue, isInvalid: renderAsInvalid }, rest)) })));
|
|
2538
|
-
});
|
|
2539
|
-
|
|
2540
1636
|
function useConfirmExit(confirmExit, when = true) {
|
|
2541
1637
|
const { navigator } = useContext(UNSAFE_NavigationContext);
|
|
2542
1638
|
useEffect(() => {
|
|
@@ -2590,84 +1686,6 @@ const Prompt = ({ when, message }) => {
|
|
|
2590
1686
|
return null;
|
|
2591
1687
|
};
|
|
2592
1688
|
|
|
2593
|
-
const RadioGroupContext = React.createContext(null);
|
|
2594
|
-
|
|
2595
|
-
/**
|
|
2596
|
-
* Use radio buttons when you have a group of mutually exclusive choices and only one selection from the group is allowed.
|
|
2597
|
-
*
|
|
2598
|
-
* 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.
|
|
2599
|
-
*
|
|
2600
|
-
* _**Do use** Radio buttons in forms, settings, or selections in a list._
|
|
2601
|
-
*
|
|
2602
|
-
* _**Do not use** Radio buttons if a user can select many option from a list, use checkboxes instead of radio buttons._
|
|
2603
|
-
*
|
|
2604
|
-
* @param {RadioGroupProps} props - The props for the RadioGroup component
|
|
2605
|
-
* @returns {JSX.Element} RadioGroup component
|
|
2606
|
-
*/
|
|
2607
|
-
const RadioGroup = ({ children, id, name, value, disabled, onChange, label, inline, className, dataTestId, isInvalid, }) => {
|
|
2608
|
-
return (jsx(FormGroup, Object.assign({ label: label, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(Flex, Object.assign({ "$inline": inline, className: className, "data-testid": dataTestId }, { children: jsx(RadioGroupContext.Provider, Object.assign({ value: {
|
|
2609
|
-
id,
|
|
2610
|
-
value,
|
|
2611
|
-
name: name || id,
|
|
2612
|
-
onChange,
|
|
2613
|
-
disabled,
|
|
2614
|
-
isInvalid,
|
|
2615
|
-
} }, { children: children })) })) })));
|
|
2616
|
-
};
|
|
2617
|
-
RadioGroup.displayName = "RadioGroup";
|
|
2618
|
-
const Flex = tw.div `
|
|
2619
|
-
${({ $inline }) => ($inline ? tws `tu-radiogroup--inline` : tws `tu-radiogroup`)}
|
|
2620
|
-
`;
|
|
2621
|
-
|
|
2622
|
-
/**
|
|
2623
|
-
* The RadioItem component.
|
|
2624
|
-
*
|
|
2625
|
-
* @param {RadioItemProps} props - The props for the RadioItem component
|
|
2626
|
-
* @returns {JSX.Element} RadioItem component
|
|
2627
|
-
*/
|
|
2628
|
-
const RadioItem = ({ label, value, dataTestId, className, description }) => {
|
|
2629
|
-
const groupCtx = React.useContext(RadioGroupContext);
|
|
2630
|
-
const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
|
|
2631
|
-
return (jsxs(InputWrapper, Object.assign({ className: className, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, "data-testid": dataTestId && `${dataTestId}-Wrapper` }, { children: [jsx(Input, { id: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, type: "radio", role: "radio", value: value, checked: isChecked, "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled, "$isInvalid": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, "data-testid": dataTestId, "$checked": isChecked }), jsxs(LabelContainer$1, { children: [jsx(Label$2, Object.assign({ htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, dataTestId: dataTestId && `${dataTestId}-Label`, disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled, isInvalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid }, { children: label })), description && (jsx(Description$1, Object.assign({ htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, "data-testid": dataTestId && `${dataTestId}-Description`, "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }, { children: description })))] })] })));
|
|
2632
|
-
};
|
|
2633
|
-
const InputWrapper = tw.label `tu-radioitem__wrapper`;
|
|
2634
|
-
const Input = tw.input `
|
|
2635
|
-
tu-radioitem
|
|
2636
|
-
${({ $checked }) => $checked && tws `tu-radioitem--checked`}
|
|
2637
|
-
${({ $disabled }) => $disabled && tws `tu-radioitem--disabled`}
|
|
2638
|
-
${({ $isInvalid }) => $isInvalid && tws `tu-radioitem--invalid`}
|
|
2639
|
-
`;
|
|
2640
|
-
const LabelContainer$1 = tw.div `tu-radioitem__label-container`;
|
|
2641
|
-
const Description$1 = tw.label `
|
|
2642
|
-
tu-radioitem__description
|
|
2643
|
-
${({ $disabled }) => $disabled && tws `tu-radioitem__description--disabled`}
|
|
2644
|
-
`;
|
|
2645
|
-
|
|
2646
|
-
/**
|
|
2647
|
-
* A thin wrapper around the `BaseInput` component for text input fields.
|
|
2648
|
-
*
|
|
2649
|
-
* NOTE: If shown with a label, please use the `TextField` component instead.
|
|
2650
|
-
*/
|
|
2651
|
-
const TextInput = forwardRef((props, ref) => (jsx(BaseInput, Object.assign({ ref: ref, type: "text" }, props))));
|
|
2652
|
-
|
|
2653
|
-
/**
|
|
2654
|
-
* The Search component is used to render a search input field.
|
|
2655
|
-
*
|
|
2656
|
-
* @param {SearchProps} props - The props for the Search component
|
|
2657
|
-
* @returns {JSX.Element} Search component
|
|
2658
|
-
*/
|
|
2659
|
-
const Search = (_a) => {
|
|
2660
|
-
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"]);
|
|
2661
|
-
return (jsx(StyledTextInput, Object.assign({}, rest, { ref: ref, dataTestId: dataTestId, name: name, className: className, "$widenOnFocus": widenInputOnFocus, "$showBorderWhenNotInFocus": showBorderWhenNotInFocus, placeholder: placeholder, prefix: jsx(Icon, { name: "MagnifyingGlassIcon", size: "medium" }), suffix: onClear ? (jsx("button", Object.assign({ "data-testid": dataTestId && `${dataTestId}_suffix_component`, onClick: () => {
|
|
2662
|
-
onClear();
|
|
2663
|
-
} }, { children: jsx(Icon, { name: "XMarkIcon", size: "small" }) }))) : undefined, value: value, disabled: disabled, onChange: onChange, onKeyUp: onKeyUp, onFocus: onFocus, onBlur: onBlur, autoComplete: autoComplete })));
|
|
2664
|
-
};
|
|
2665
|
-
const StyledTextInput = twx(TextInput) `
|
|
2666
|
-
tu-search
|
|
2667
|
-
${({ $showBorderWhenNotInFocus }) => $showBorderWhenNotInFocus && tws `tu-search--border`}
|
|
2668
|
-
${({ $widenOnFocus }) => $widenOnFocus && tws `tu-search--widen-on-focus`}
|
|
2669
|
-
`;
|
|
2670
|
-
|
|
2671
1689
|
/**
|
|
2672
1690
|
* The Spacer component is used for adding a bit of space in the ui.
|
|
2673
1691
|
*
|
|
@@ -2780,7 +1798,7 @@ const Sidebar = ({ childContainerClassName, children, breakpoint = "lg", classNa
|
|
|
2780
1798
|
}
|
|
2781
1799
|
return tws `visible`;
|
|
2782
1800
|
};
|
|
2783
|
-
return (jsxs(Root$
|
|
1801
|
+
return (jsxs(Root$1, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsx(ChildContainer, Object.assign({ "$breakpoint": breakpoint, ref: overflowContainerRef, className: childContainerClassName, "data-testid": dataTestId && `${dataTestId}-child-container` }, { children: React__default.Children.map(children, child => {
|
|
2784
1802
|
return React__default.cloneElement(child, {
|
|
2785
1803
|
className: `${child.props.className} ${itemVisibilityClassName(child.props.id)}`,
|
|
2786
1804
|
});
|
|
@@ -2800,7 +1818,7 @@ const Sidebar = ({ childContainerClassName, children, breakpoint = "lg", classNa
|
|
|
2800
1818
|
: null;
|
|
2801
1819
|
}) }))) }))) : null] })));
|
|
2802
1820
|
};
|
|
2803
|
-
const Root$
|
|
1821
|
+
const Root$1 = tw.div `
|
|
2804
1822
|
tu-sidebar
|
|
2805
1823
|
`;
|
|
2806
1824
|
const breakpointClasses = {
|
|
@@ -2817,85 +1835,6 @@ const ChildContainer = tw.div `
|
|
|
2817
1835
|
${({ $breakpoint }) => breakpointClasses[$breakpoint]}
|
|
2818
1836
|
`;
|
|
2819
1837
|
|
|
2820
|
-
/**
|
|
2821
|
-
* The TextArea is a base component, and should not be used very often.
|
|
2822
|
-
* For most cases the TextAreaField is the correct component.
|
|
2823
|
-
*/
|
|
2824
|
-
const TextArea = React.forwardRef((_a, ref) => {
|
|
2825
|
-
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"]);
|
|
2826
|
-
return (jsx(StyledTextArea, Object.assign({ id: id, name: name, value: value, rows: rows, disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, onFocus: onFocus, onBlur: onBlur, maxLength: maxLength, "$resize": resize, "$invalid": isInvalid, ref: ref, defaultValue: defaultValue, required: required }, rest, { onChange: onChange, "data-testid": dataTestId })));
|
|
2827
|
-
});
|
|
2828
|
-
const StyledTextArea = tw.textarea `
|
|
2829
|
-
tu-textarea
|
|
2830
|
-
${({ $invalid }) => ($invalid ? tws `tu-textarea--invalid` : null)}
|
|
2831
|
-
${({ disabled }) => (disabled ? tws `tu-textarea--disabled` : null)}
|
|
2832
|
-
${({ $resize }) => {
|
|
2833
|
-
switch ($resize) {
|
|
2834
|
-
case "both":
|
|
2835
|
-
return tws `resize`;
|
|
2836
|
-
case "horizontal":
|
|
2837
|
-
return tws `resize-x`;
|
|
2838
|
-
case "vertical":
|
|
2839
|
-
return tws `resize-y`;
|
|
2840
|
-
case "none":
|
|
2841
|
-
return tws `resize-none`;
|
|
2842
|
-
default:
|
|
2843
|
-
return null;
|
|
2844
|
-
}
|
|
2845
|
-
}};
|
|
2846
|
-
`;
|
|
2847
|
-
|
|
2848
|
-
/**
|
|
2849
|
-
* The TextLengthIndicator component shows a `{length}/{maxLength}` label.
|
|
2850
|
-
* Used for TextFields to communicate a maximum allowed input length.
|
|
2851
|
-
*
|
|
2852
|
-
* @param {TextLengthIndicatorProps} props - The props for the TextLengthIndicator component
|
|
2853
|
-
* @returns {JSX.Element} TextLengthIndicator component
|
|
2854
|
-
*/
|
|
2855
|
-
const TextLengthIndicator = ({ length, maxLength }) => {
|
|
2856
|
-
return (jsxs(Root$1, { children: [length, "/", maxLength] }));
|
|
2857
|
-
};
|
|
2858
|
-
const Root$1 = tw.span `
|
|
2859
|
-
font-mono
|
|
2860
|
-
`;
|
|
2861
|
-
|
|
2862
|
-
const TextAreaField = React.forwardRef((_a, ref) => {
|
|
2863
|
-
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"]);
|
|
2864
|
-
const [valueLength, setValueLength] = React.useState(value ? `${value}`.length : 0);
|
|
2865
|
-
const renderAsInvalid = isInvalid || Boolean(errorMessage);
|
|
2866
|
-
const htmlForId = id ? id : "textAreaField-" + v4();
|
|
2867
|
-
const handleChange = React.useCallback((event) => {
|
|
2868
|
-
setValueLength(event.target.value.length);
|
|
2869
|
-
if (onChange) {
|
|
2870
|
-
onChange(event);
|
|
2871
|
-
}
|
|
2872
|
-
}, [onChange]);
|
|
2873
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon ||
|
|
2874
|
-
(maxLength !== null && maxLength !== undefined && (jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength }))), className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(TextArea, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, onChange: handleChange, dataTestId: dataTestId })) })));
|
|
2875
|
-
});
|
|
2876
|
-
|
|
2877
|
-
/**
|
|
2878
|
-
* 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.
|
|
2879
|
-
*
|
|
2880
|
-
* _**Do use** when the user has to input or edit simple text based information, such as metadata._
|
|
2881
|
-
*
|
|
2882
|
-
* _**Do not use** to confirm user actions, such as deleting. Use a checkbox for such flows._
|
|
2883
|
-
*/
|
|
2884
|
-
const TextField = React.forwardRef((_a, ref) => {
|
|
2885
|
-
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"]);
|
|
2886
|
-
const [valueLength, setValueLength] = React.useState(value ? `${value}`.length : 0);
|
|
2887
|
-
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2888
|
-
const htmlFor = id ? id : "textField-" + v4();
|
|
2889
|
-
const handleChange = React.useCallback((event) => {
|
|
2890
|
-
setValueLength(event.target.value.length);
|
|
2891
|
-
if (onChange) {
|
|
2892
|
-
onChange(event);
|
|
2893
|
-
}
|
|
2894
|
-
}, [onChange]);
|
|
2895
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlFor, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon ||
|
|
2896
|
-
(maxLength !== null && maxLength !== undefined && (jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength }))), dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.readOnly }, { children: jsx(TextInput, Object.assign({ id: htmlFor, "aria-labelledby": htmlFor + "-label", ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, onChange: handleChange, dataTestId: dataTestId })) })));
|
|
2897
|
-
});
|
|
2898
|
-
|
|
2899
1838
|
/**
|
|
2900
1839
|
* Timeline - used to contain TimelineElements for building a sequence of timed entries - each rendered on a line
|
|
2901
1840
|
* - with an indicator (dot)
|
|
@@ -2925,68 +1864,6 @@ function defaultHeader(date, showTime) {
|
|
|
2925
1864
|
})})`;
|
|
2926
1865
|
}
|
|
2927
1866
|
|
|
2928
|
-
/**
|
|
2929
|
-
* Use Toggle when you have to only enable/disable a feature.
|
|
2930
|
-
*
|
|
2931
|
-
* _**Do use** Toggle in forms or settings._
|
|
2932
|
-
*
|
|
2933
|
-
* _**Do not use** Toggle if a user can select many option from a list, use checkboxes instead of toggle._
|
|
2934
|
-
*
|
|
2935
|
-
* @param {ToggleProps} props - The props for the Toggle component
|
|
2936
|
-
* @returns {JSX.Element} Toggle component
|
|
2937
|
-
*/
|
|
2938
|
-
const Toggle = React.forwardRef(({ toggled = false, onChange, disabled, size = "medium", id, tabIndex, required, className, dataTestId, onBlur, name, description = "", }, ref) => {
|
|
2939
|
-
return (jsxs(ToggleWrapper, { children: [jsxs(InputContainer, Object.assign({ htmlFor: id }, { children: [jsx(HiddenInput, { name: name, type: "checkbox", checked: toggled, disabled: disabled, onChange: e => {
|
|
2940
|
-
e.stopPropagation();
|
|
2941
|
-
onChange(!toggled, e);
|
|
2942
|
-
}, id: id, "aria-checked": toggled, role: "checkbox", tabIndex: tabIndex, required: required, ref: ref, "data-testid": dataTestId && `${dataTestId}-Input`, onBlur: onBlur }), jsx(SwitchContainer, Object.assign({ "$toggled": toggled, htmlFor: id, "$disabled": disabled, "$size": size }, { children: jsx(Switch, { "$toggled": toggled, htmlFor: id, "data-testid": dataTestId && `${dataTestId}-Switch` }) }))] })), jsxs(LabelContainer, { children: [jsx(Label$2, Object.assign({ htmlFor: id, dataTestId: dataTestId && `${dataTestId}-Label`, disabled: disabled }, { children: name })), description && (jsx(Description, Object.assign({ htmlFor: id, "data-testid": dataTestId && `${dataTestId}-Description`, "$disabled": disabled }, { children: description })))] })] }));
|
|
2943
|
-
});
|
|
2944
|
-
Toggle.displayName = "Toggle";
|
|
2945
|
-
const ToggleWrapper = tw.div `tu-toggle__wrapper`;
|
|
2946
|
-
const InputContainer = tw.label `tu-toggle__input-container `;
|
|
2947
|
-
const HiddenInput = tw.input `tu-toggle__input`;
|
|
2948
|
-
const Switch = tw.label `
|
|
2949
|
-
${({ $toggled }) => ($toggled ? tws `tu-toggle__switch` : tws `tu-toggle`)}`;
|
|
2950
|
-
const SwitchContainer = tw.label `
|
|
2951
|
-
tu-toggle__switch-container
|
|
2952
|
-
${({ $disabled }) => $disabled && tws `tu-toggle--disabled`};
|
|
2953
|
-
${({ $size }) => ($size === "small" ? tws `tu-toggle--small` : tws `tu-toggle--medium`)};
|
|
2954
|
-
${({ $toggled }) => $toggled && tws `tu-toggle--toggled`}`;
|
|
2955
|
-
const LabelContainer = tw.div `tu-toggle__label-container`;
|
|
2956
|
-
const Description = tw.label `
|
|
2957
|
-
tu-toggle__description
|
|
2958
|
-
${({ $disabled }) => $disabled && tws `tu-toggle__description--disabled`}
|
|
2959
|
-
`;
|
|
2960
|
-
|
|
2961
|
-
/**
|
|
2962
|
-
* A thin wrapper around the `BaseInput` component for upload input fields.
|
|
2963
|
-
*
|
|
2964
|
-
* NOTE: If shown with a label, please use the `UploadField` component instead.
|
|
2965
|
-
*/
|
|
2966
|
-
const UploadInput = forwardRef((_a, ref) => {
|
|
2967
|
-
var { disabled, acceptedTypes, nonInteractive, uploadLabel, multipleFiles } = _a, rest = __rest(_a, ["disabled", "acceptedTypes", "nonInteractive", "uploadLabel", "multipleFiles"]);
|
|
2968
|
-
return (jsx(UploadInputContainer, { children: jsx(BaseInput, Object.assign({ addonBefore: uploadLabel, ref: ref, disabled: disabled, accept: acceptedTypes, multiple: multipleFiles, type: "file", nonInteractive: nonInteractive,
|
|
2969
|
-
// onClick used to work with nonInteractive option
|
|
2970
|
-
onClick: event => {
|
|
2971
|
-
if (nonInteractive) {
|
|
2972
|
-
event.preventDefault();
|
|
2973
|
-
event.stopPropagation();
|
|
2974
|
-
}
|
|
2975
|
-
} }, rest)) }));
|
|
2976
|
-
});
|
|
2977
|
-
const UploadInputContainer = tw.label `
|
|
2978
|
-
tu-upload-input`;
|
|
2979
|
-
|
|
2980
|
-
/**
|
|
2981
|
-
* Upload fields enable the user to upload Files.
|
|
2982
|
-
*/
|
|
2983
|
-
const UploadField = forwardRef((_a, ref) => {
|
|
2984
|
-
var { label, id, tip, helpText, errorMessage, isInvalid, className, value, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "isInvalid", "className", "value", "dataTestId"]);
|
|
2985
|
-
const renderAsInvalid = isInvalid || Boolean(errorMessage);
|
|
2986
|
-
const htmlForId = id ? id : "uploadField-" + v4();
|
|
2987
|
-
return (jsx(FormGroup, Object.assign({ htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, dataTestId: `${dataTestId}-FormGroup` }, { children: jsx(UploadInput, Object.assign({ ref: ref, id: htmlForId, "aria-labelledby": htmlForId + "-label", isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
2988
|
-
});
|
|
2989
|
-
|
|
2990
1867
|
/**
|
|
2991
1868
|
* Helper function to get normalized score in range 0-1 used by the ValueBar
|
|
2992
1869
|
*
|
|
@@ -3261,4 +2138,4 @@ const Layout = tw.div `
|
|
|
3261
2138
|
tu-layout-TwoColumnLayout
|
|
3262
2139
|
`;
|
|
3263
2140
|
|
|
3264
|
-
export {
|
|
2141
|
+
export { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Collapse, ContentGridArea, CopyableText, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon, IconButton, Indicator, IntrinsicallyResponsiveGrid, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, NavGridArea, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Tooltip, TwoColumnLayout, ValueBar, docs, getDevicePixelRatio, getValueBarColorByValue, useClickOutside, useContainerProps, useDebounce, useDevicePixelRatio, useLocalStorage, useModal, usePopoverContext, usePrompt, useResize, useTimeout };
|