@trackunit/react-form-components 1.0.16 → 1.0.17

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/index.cjs.js CHANGED
@@ -148,7 +148,6 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className }
148
148
  }
149
149
  };
150
150
  const buttonAction = () => {
151
- var _a, _b;
152
151
  switch (type) {
153
152
  case "EMAIL":
154
153
  return window.open(`mailto:${value}`);
@@ -163,7 +162,7 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className }
163
162
  // Typescript seems to be unable to detect RefObject
164
163
  // as one of the members of the union RefObject | string | null which gives access to the `current` property
165
164
  // eslint-disable-next-line react/prop-types
166
- return copyToClipboard((_b = (_a = value === null || value === void 0 ? void 0 : value.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
165
+ return copyToClipboard(value?.current?.value ?? "");
167
166
  default:
168
167
  return null;
169
168
  }
@@ -379,7 +378,6 @@ const DisabledForReasonsTip = ({ reasons, kind }) => {
379
378
  * This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
380
379
  */
381
380
  const BaseInput = React__namespace.forwardRef(({ className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, showDefaultActions = false, inputClassName, placeholder, addonBeforeClassName, style, ...rest }, ref) => {
382
- var _a;
383
381
  const renderAsDisabled = Boolean(rest.disabled) || rest.readOnly;
384
382
  const innerRef = React__namespace.useRef(null);
385
383
  // eslint-disable-next-line local-rules/no-typescript-assertion
@@ -407,7 +405,7 @@ const BaseInput = React__namespace.forwardRef(({ className, isInvalid, dataTestI
407
405
  actions: (actions && !compareReactNodes(addonBefore, actions)) || false,
408
406
  }), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null, rest.readOnly === true &&
409
407
  showDefaultActions &&
410
- ((_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.value.length) &&
408
+ innerRef.current?.value.length &&
411
409
  innerRef.current.value.length > 0 ? (jsxRuntime.jsx(ActionButton, { type: "COPY", value: innerRef }, "default-copy-action")) : null, actions && !compareReactNodes(addonBefore, actions) ? (jsxRuntime.jsx("div", { className: cvaInputAction({
412
410
  addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
413
411
  suffix: !compareReactNodes(addonBefore, suffix),
@@ -587,13 +585,12 @@ const Checkbox = React__namespace.forwardRef(({ className, dataTestId = "checkbo
587
585
  const textIsCutOff = reactComponents.useIsTextCutOff(labelRef);
588
586
  const isReadonly = disabled || readOnly;
589
587
  const onKeyPress = e => {
590
- var _a, _b;
591
588
  if ("Space" === e.code) {
592
589
  e.preventDefault();
593
- (_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.click();
590
+ internalRef.current?.click();
594
591
  }
595
592
  if ("Enter" === e.code) {
596
- (_b = internalRef.current) === null || _b === void 0 ? void 0 : _b.click();
593
+ internalRef.current?.click();
597
594
  }
598
595
  };
599
596
  const uuid = rest.id;
@@ -716,7 +713,7 @@ const ColorField = React.forwardRef(({ label, id, tip, helpText, errorMessage, h
716
713
  const newValue = event.target.value;
717
714
  setInnerValue(newValue);
718
715
  setRenderAsInvalid(!!errorType);
719
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
716
+ onBlur?.(event);
720
717
  }, [errorType, onBlur]);
721
718
  const handleChange = React.useCallback((event) => {
722
719
  const newValue = event.target.value;
@@ -864,13 +861,12 @@ const DropZone = ({ className, dataTestId, filesSelected, label = jsxRuntime.jsx
864
861
  };
865
862
  //function to handle focusable button click (for accessibility)
866
863
  const handleButtonClick = (e) => {
867
- var _a;
868
864
  e.preventDefault();
869
865
  e.stopPropagation();
870
866
  if (disabled) {
871
867
  return;
872
868
  }
873
- (_a = inputLabelRef.current) === null || _a === void 0 ? void 0 : _a.click();
869
+ inputLabelRef.current?.click();
874
870
  };
875
871
  return (jsxRuntime.jsx("div", { className: cvaDropZone({ size, dropComplete: fileDropped, dragActive, disabled, invalid: isInvalid, className }), "data-testid": dataTestId, onClick: e => {
876
872
  if (disabled) {
@@ -929,7 +925,7 @@ const EmailInput = React__namespace.forwardRef(({ fieldSize = "medium", disabled
929
925
  };
930
926
  const handleChange = React.useCallback(event => {
931
927
  const newValue = event.target.value;
932
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
928
+ onChange?.(event);
933
929
  setEmail(newValue);
934
930
  }, [onChange]);
935
931
  const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
@@ -946,17 +942,16 @@ const EmailField = React.forwardRef(({ label, id, tip, helpText, errorMessage, h
946
942
  const htmlForId = id ? id : "emailField-" + sharedUtils.uuidv4();
947
943
  const [t] = useTranslation();
948
944
  const [innerValue, setInnerValue] = React.useState(() => {
949
- var _a;
950
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : "";
945
+ return (value?.toString() || defaultValue?.toString()) ?? "";
951
946
  });
952
947
  const [renderAsInvalid, setRenderAsInvalid] = React.useState(!!errorMessage || (value && isString(value) && !validateEmailAddress(value)) || isInvalid);
953
- const errorType = React.useMemo(() => validateEmailId(innerValue !== null && innerValue !== void 0 ? innerValue : "", rest.required), [rest.required, innerValue]);
948
+ const errorType = React.useMemo(() => validateEmailId(innerValue ?? "", rest.required), [rest.required, innerValue]);
954
949
  const error = React.useMemo(() => (errorType ? t(`emailField.error.${errorType}`) : errorMessage), [errorType, errorMessage, t]);
955
950
  const handleBlur = React.useCallback(event => {
956
951
  const newValue = event.target.value;
957
952
  setInnerValue(newValue);
958
953
  setRenderAsInvalid(!!errorType);
959
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
954
+ onBlur?.(event);
960
955
  }, [errorType, onBlur]);
961
956
  const handleChange = React.useCallback((event) => {
962
957
  setInnerValue(event.target.value);
@@ -1039,10 +1034,10 @@ const NumberField = React.forwardRef(({ label, id, tip, helpText, errorMessage,
1039
1034
  const htmlForId = id ? id : "numberField-" + sharedUtils.uuidv4();
1040
1035
  const [t] = useTranslation();
1041
1036
  const [innerValue, setInnerValue] = React.useState(() => {
1042
- return Number(value === null || value === void 0 ? void 0 : value.toString()) || Number(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString());
1037
+ return Number(value?.toString()) || Number(defaultValue?.toString());
1043
1038
  });
1044
1039
  const [renderAsInvalid, setRenderAsInvalid] = React.useState((isInvalid === undefined ? Boolean(errorMessage) : isInvalid) ||
1045
- !!validateNumber(value === null || value === void 0 ? void 0 : value.toString(), rest.required, rest.min, rest.max));
1040
+ !!validateNumber(value?.toString(), rest.required, rest.min, rest.max));
1046
1041
  const errorType = React.useMemo(() => validateNumber(innerValue, rest.required, rest.min, rest.max), [innerValue, rest.max, rest.min, rest.required]);
1047
1042
  const error = React.useMemo(() => {
1048
1043
  // for the case when a custom error message is provided
@@ -1065,7 +1060,7 @@ const NumberField = React.forwardRef(({ label, id, tip, helpText, errorMessage,
1065
1060
  else {
1066
1061
  setRenderAsInvalid(!!validateNumber(newValue, rest.required, rest.min, rest.max));
1067
1062
  }
1068
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
1063
+ onBlur?.(event);
1069
1064
  }, [errorMessage, onBlur, rest.max, rest.min, rest.required]);
1070
1065
  const handleChange = React.useCallback((event) => {
1071
1066
  setInnerValue(event.target.value);
@@ -1107,7 +1102,7 @@ const cvaOptionCardContainer = cssClassVarianceUtilities.cvaMerge(["contents"]);
1107
1102
  * A card version of a radio button that includes an icon, headings and a description.
1108
1103
  */
1109
1104
  const OptionCard = React.forwardRef(({ icon, heading, subheading, description, disabled, id, value, className, contentClassName, dataTestId, customImage, ...rest }, ref) => {
1110
- const htmlForId = id !== null && id !== void 0 ? id : "option-card-" + sharedUtils.uuidv4();
1105
+ const htmlForId = id ?? "option-card-" + sharedUtils.uuidv4();
1111
1106
  return (jsxRuntime.jsxs("div", { className: cvaOptionCardContainer(), "data-testid": dataTestId, children: [jsxRuntime.jsx("input", { className: "peer absolute h-0 w-0 opacity-0", "data-testid": `${dataTestId}-option-card`, disabled: disabled, id: htmlForId, ref: ref, type: "radio", value: value, ...rest }), jsxRuntime.jsxs("label", { className: cvaOptionCardLabel({ className, disabled }), "data-testid": `${dataTestId}-option-card-label`, htmlFor: htmlForId, children: [disabled && icon && !customImage
1112
1107
  ? React.cloneElement(icon, { className: `${icon.props.className} text-secondary-400` })
1113
1108
  : null, disabled && customImage ? jsxRuntime.jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }) : null, !disabled && !customImage && icon, !disabled && customImage ? jsxRuntime.jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }) : null, heading ? (jsxRuntime.jsx(reactComponents.Heading, { subtle: disabled, variant: "secondary", children: heading })) : null, subheading || description ? (jsxRuntime.jsxs("div", { className: cvaOptionCardContent({ className: contentClassName }), children: [subheading ? (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: disabled, type: "span", weight: "thick", children: subheading })) : null, description ? (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, type: "span", children: description })) : null] })) : null] })] }));
@@ -1136,7 +1131,7 @@ const PasswordField = React.forwardRef(({ id, label, tip, helpText, helpAddon, e
1136
1131
  const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
1137
1132
  const htmlFor = id ? id : "passwordField-" + sharedUtils.uuidv4();
1138
1133
  const handleChange = React.useCallback((event) => {
1139
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
1134
+ onChange?.(event);
1140
1135
  }, [onChange]);
1141
1136
  return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, required: rest.required ? !(rest.disabled || rest.readOnly) : false, tip: tip, children: jsxRuntime.jsx(PasswordInput, { ...rest, "aria-labelledby": htmlFor + "-label", className: className, dataTestId: dataTestId, disabled: rest.readOnly, id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, onChange: handleChange, ref: ref, value: value }) }));
1142
1137
  });
@@ -1208,8 +1203,7 @@ const DEFAULT_COUNTRY_CODE = undefined;
1208
1203
  */
1209
1204
  const PhoneInput = React.forwardRef(({ dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, readOnly, onFocus, onBlur, name, ...rest }, ref) => {
1210
1205
  const [innerValue, setInnerValue] = React.useState(() => {
1211
- var _a;
1212
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : "";
1206
+ return (value?.toString() || defaultValue?.toString()) ?? "";
1213
1207
  });
1214
1208
  const fieldIsFocused = React.useRef(false);
1215
1209
  const [countryCode, setCountryCode] = React.useState(DEFAULT_COUNTRY_CODE);
@@ -1222,7 +1216,7 @@ const PhoneInput = React.forwardRef(({ dataTestId, isInvalid, disabled = false,
1222
1216
  const newValue = event.target.value;
1223
1217
  const noneFormattedValue = parsePhoneNumberFromString.parseIncompletePhoneNumber(newValue);
1224
1218
  event.target.value = noneFormattedValue;
1225
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
1219
+ onChange?.(event);
1226
1220
  setInnerValue(newValue);
1227
1221
  determineCountry(newValue);
1228
1222
  }, [onChange, determineCountry]);
@@ -1240,17 +1234,17 @@ const PhoneInput = React.forwardRef(({ dataTestId, isInvalid, disabled = false,
1240
1234
  const handleBlur = React.useCallback(event => {
1241
1235
  const newValue = event.target.value;
1242
1236
  makePretty(newValue);
1243
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
1237
+ onBlur?.(event);
1244
1238
  fieldIsFocused.current = false;
1245
1239
  }, [makePretty, onBlur]);
1246
1240
  const handleFocus = React.useCallback(event => {
1247
1241
  const newValue = event.target.value;
1248
1242
  const noneFormattedValue = parsePhoneNumberFromString.parseIncompletePhoneNumber(newValue);
1249
1243
  setInnerValue(noneFormattedValue);
1250
- onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
1244
+ onFocus?.(event);
1251
1245
  fieldIsFocused.current = true;
1252
1246
  }, [onFocus]);
1253
- return (jsxRuntime.jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsxRuntime.jsx(BaseInput, { actions: !disableAction && innerValue && innerValue.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue, ...rest }) }));
1247
+ return (jsxRuntime.jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsxRuntime.jsx(BaseInput, { actions: !disableAction && innerValue && innerValue.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: value?.toString() || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue, ...rest }) }));
1254
1248
  });
1255
1249
  PhoneInput.displayName = "PhoneInput";
1256
1250
 
@@ -1324,11 +1318,10 @@ const PhoneField = React.forwardRef(({ label, id, tip, helpText, isInvalid, erro
1324
1318
  const htmlForId = id ? id : "phoneField-" + sharedUtils.uuidv4();
1325
1319
  const [t] = useTranslation();
1326
1320
  const [innerValue, setInnerValue] = React.useState(() => {
1327
- var _a;
1328
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : undefined;
1321
+ return (value?.toString() || defaultValue?.toString()) ?? undefined;
1329
1322
  });
1330
1323
  const [renderAsInvalid, setRenderAsInvalid] = React.useState((isInvalid === undefined ? Boolean(errorMessage) : isInvalid) ||
1331
- !!phoneErrorMessage(value === null || value === void 0 ? void 0 : value.toString(), rest.required));
1324
+ !!phoneErrorMessage(value?.toString(), rest.required));
1332
1325
  const errorType = React.useMemo(() => phoneErrorMessage(innerValue, rest.required), [innerValue, rest.required]);
1333
1326
  const error = React.useMemo(() => {
1334
1327
  // for the case when a custom error message is provided
@@ -1351,7 +1344,7 @@ const PhoneField = React.forwardRef(({ label, id, tip, helpText, isInvalid, erro
1351
1344
  else {
1352
1345
  setRenderAsInvalid(!!phoneErrorMessage(newValue.toString(), rest.required));
1353
1346
  }
1354
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
1347
+ onBlur?.(event);
1355
1348
  }, [errorMessage, onBlur, rest.required]);
1356
1349
  return (jsxRuntime.jsx(FormGroup, { className: className, dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && error) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required ? !(rest.disabled || rest.readOnly) : false, tip: tip, children: jsxRuntime.jsx(PhoneInput, { "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, defaultValue: defaultValue, id: htmlForId, isInvalid: renderAsInvalid, name: name, onBlur: handleBlur, ref: ref, value: value, ...rest }) }));
1357
1350
  });
@@ -1491,21 +1484,21 @@ RadioGroup.displayName = "RadioGroup";
1491
1484
  */
1492
1485
  const RadioItem = ({ label, value, dataTestId, className, description, suffix, ...rest }) => {
1493
1486
  const groupCtx = React.useContext(RadioGroupContext);
1494
- const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
1487
+ const isChecked = groupCtx?.value === value;
1495
1488
  const labelRef = React.useRef(null);
1496
1489
  const descriptionRef = React.useRef(null);
1497
1490
  const labelTextIsCutOff = reactComponents.useIsTextCutOff(labelRef);
1498
1491
  const descriptionTextIsCutOff = reactComponents.useIsTextCutOff(descriptionRef);
1499
- const descriptionId = description ? `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}-description` : undefined;
1500
- const inputId = `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`;
1492
+ const descriptionId = description ? `${groupCtx?.id}-${value}-description` : undefined;
1493
+ const inputId = `${groupCtx?.id}-${value}`;
1501
1494
  return (jsxRuntime.jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : undefined, htmlFor: inputId, children: [jsxRuntime.jsx("input", { "aria-describedby": descriptionId, checked: isChecked, className: cvaRadioItem({
1502
1495
  checked: isChecked,
1503
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1504
- invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1505
- }), "data-testid": dataTestId, id: inputId, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value, ...rest }), jsxRuntime.jsx(reactComponents.Tooltip, { className: cvaLabelTooltip(), dataTestId: dataTestId ? `${dataTestId}-Label-Tooltip` : undefined, disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsxRuntime.jsx("span", { className: cvaLabel({
1506
- invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1507
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1508
- }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, ref: labelRef, children: label }) }, "tooltip-" + rest.name), suffix ? (jsxRuntime.jsx("div", { className: cvaSuffixContainer(), "data-testid": dataTestId ? `${dataTestId}-suffix-container` : undefined, children: suffix })) : null, description ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: cvaDescriptionTooltip(), dataTestId: dataTestId ? `${dataTestId}-Description-Tooltip` : undefined, disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsxRuntime.jsx("span", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : undefined, id: descriptionId, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null] }));
1496
+ disabled: groupCtx?.disabled,
1497
+ invalid: groupCtx?.isInvalid,
1498
+ }), "data-testid": dataTestId, id: inputId, onChange: groupCtx?.onChange, type: "radio", value: value, ...rest }), jsxRuntime.jsx(reactComponents.Tooltip, { className: cvaLabelTooltip(), dataTestId: dataTestId ? `${dataTestId}-Label-Tooltip` : undefined, disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsxRuntime.jsx("span", { className: cvaLabel({
1499
+ invalid: groupCtx?.isInvalid,
1500
+ disabled: groupCtx?.disabled,
1501
+ }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, ref: labelRef, children: label }) }, "tooltip-" + rest.name), suffix ? (jsxRuntime.jsx("div", { className: cvaSuffixContainer(), "data-testid": dataTestId ? `${dataTestId}-suffix-container` : undefined, children: suffix })) : null, description ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: cvaDescriptionTooltip(), dataTestId: dataTestId ? `${dataTestId}-Description-Tooltip` : undefined, disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsxRuntime.jsx("span", { className: cvaRadioItemDescription({ disabled: groupCtx?.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : undefined, id: descriptionId, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null] }));
1509
1502
  };
1510
1503
 
1511
1504
  const cvaTimeRange = cssClassVarianceUtilities.cvaMerge([
@@ -1525,7 +1518,7 @@ const cvaTimeRange = cssClassVarianceUtilities.cvaMerge([
1525
1518
  * @returns {JSX.Element} TimeRange component
1526
1519
  */
1527
1520
  const TimeRange = ({ id, className, dataTestId, children, range, onChange, disabled, isInvalid, }) => {
1528
- const [timeRange, setTimeRange] = React.useState(range !== null && range !== void 0 ? range : {
1521
+ const [timeRange, setTimeRange] = React.useState(range ?? {
1529
1522
  timeFrom: "",
1530
1523
  timeTo: "",
1531
1524
  });
@@ -1536,7 +1529,7 @@ const TimeRange = ({ id, className, dataTestId, children, range, onChange, disab
1536
1529
  setTimeRange(prev => ({ ...prev, timeTo }));
1537
1530
  };
1538
1531
  const onRangeChange = () => onChange(timeRange);
1539
- return (jsxRuntime.jsxs("div", { className: cvaTimeRange({ className }), "data-testid": dataTestId, id: id, children: [jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-from`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeFrom(time.currentTarget.value), type: "time", value: timeRange.timeFrom }), children !== null && children !== void 0 ? children : jsxRuntime.jsx("div", { "data-testid": `${dataTestId}-separator`, children: "-" }), jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-to`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeTo(time.currentTarget.value), type: "time", value: timeRange.timeTo })] }));
1532
+ return (jsxRuntime.jsxs("div", { className: cvaTimeRange({ className }), "data-testid": dataTestId, id: id, children: [jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-from`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeFrom(time.currentTarget.value), type: "time", value: timeRange.timeFrom }), children ?? jsxRuntime.jsx("div", { "data-testid": `${dataTestId}-separator`, children: "-" }), jsxRuntime.jsx(BaseInput, { dataTestId: `${dataTestId}-to`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeTo(time.currentTarget.value), type: "time", value: timeRange.timeTo })] }));
1540
1533
  };
1541
1534
 
1542
1535
  const cvaScheduleItem = cssClassVarianceUtilities.cvaMerge([
@@ -1609,7 +1602,7 @@ const parseSchedule = (scheduleString) => {
1609
1602
  }
1610
1603
  const schedule = scheduleString.split(",").map(daySchedule => {
1611
1604
  const [day, timeRange] = daySchedule.split("#");
1612
- const [timeFrom, timeTo] = (timeRange !== null && timeRange !== void 0 ? timeRange : "").split("-");
1605
+ const [timeFrom, timeTo] = (timeRange ?? "").split("-");
1613
1606
  const isAllDay = timeFrom === "00:00" && timeTo === "24:00";
1614
1607
  return {
1615
1608
  day: Number(day),
@@ -1683,7 +1676,7 @@ const serializeSchedule = (weekSchedule) => {
1683
1676
  * @returns {boolean} Whether the schedule is uniform
1684
1677
  */
1685
1678
  const isUniform = (schedule) => {
1686
- return schedule.every((day, _, collection) => { var _a, _b, _c, _d, _e, _f; return ((_b = (_a = collection[0]) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.timeFrom) === ((_c = day.range) === null || _c === void 0 ? void 0 : _c.timeFrom) && ((_e = (_d = collection[0]) === null || _d === void 0 ? void 0 : _d.range) === null || _e === void 0 ? void 0 : _e.timeTo) === ((_f = day.range) === null || _f === void 0 ? void 0 : _f.timeTo); });
1679
+ return schedule.every((day, _, collection) => collection[0]?.range?.timeFrom === day.range?.timeFrom && collection[0]?.range?.timeTo === day.range?.timeTo);
1687
1680
  };
1688
1681
  /**
1689
1682
  * Checks if a list of schedule objects are consecutive days
@@ -1735,8 +1728,7 @@ const cvaSearch = cssClassVarianceUtilities.cvaMerge([
1735
1728
  * @returns {JSX.Element} Search component
1736
1729
  */
1737
1730
  const Search = React.forwardRef(({ className, placeholder = "Search", value, widenInputOnFocus, hideBorderWhenNotInFocus = false, disabled, onKeyUp, onChange, onFocus, onBlur, name, onClear, dataTestId, autoComplete = "on", loading, inputClassName, iconName = "MagnifyingGlass", ...rest }, ref) => {
1738
- var _a, _b;
1739
- return (jsxRuntime.jsx(TextInput, { ...rest, autoComplete: autoComplete, className: cvaSearch({ className, border: hideBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), dataTestId: dataTestId, disabled: disabled, inputClassName: inputClassName, name: name, onBlur: onBlur, onChange: onChange, onFocus: onFocus, onKeyUp: onKeyUp, placeholder: placeholder, prefix: loading ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", size: (_a = rest.fieldSize) !== null && _a !== void 0 ? _a : undefined })) : (jsxRuntime.jsx(reactComponents.Icon, { name: iconName, size: (_b = rest.fieldSize) !== null && _b !== void 0 ? _b : undefined })), ref: ref, suffix:
1731
+ return (jsxRuntime.jsx(TextInput, { ...rest, autoComplete: autoComplete, className: cvaSearch({ className, border: hideBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), dataTestId: dataTestId, disabled: disabled, inputClassName: inputClassName, name: name, onBlur: onBlur, onChange: onChange, onFocus: onFocus, onKeyUp: onKeyUp, placeholder: placeholder, prefix: loading ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", size: rest.fieldSize ?? undefined })) : (jsxRuntime.jsx(reactComponents.Icon, { name: iconName, size: rest.fieldSize ?? undefined })), ref: ref, suffix:
1740
1732
  //only show the clear button if there is a value and the onClear function is provided
1741
1733
  onClear && value ? (jsxRuntime.jsx("button", { className: "flex", "data-testid": dataTestId ? `${dataTestId}_suffix_component` : null, onClick: () => {
1742
1734
  onClear();
@@ -1868,8 +1860,7 @@ const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, disabled, o
1868
1860
  const TagWithWidth = ({ onWidthKnown, children, ...rest }) => {
1869
1861
  const ref = React.useRef(null);
1870
1862
  React.useLayoutEffect(() => {
1871
- var _a;
1872
- onWidthKnown && onWidthKnown({ width: ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0 });
1863
+ onWidthKnown && onWidthKnown({ width: ref.current?.offsetWidth || 0 });
1873
1864
  }, [ref, onWidthKnown]);
1874
1865
  return (jsxRuntime.jsx(reactComponents.Tag, { ref: ref, ...rest, children: children }));
1875
1866
  };
@@ -1888,8 +1879,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
1888
1879
  const childrenWidth = React.useRef([]);
1889
1880
  const itemsCount = items.length;
1890
1881
  React.useLayoutEffect(() => {
1891
- var _a;
1892
- availableWidth.current = ((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
1882
+ availableWidth.current = containerRef.current?.offsetWidth || 0;
1893
1883
  }, [containerRef]);
1894
1884
  const onWidthKnownHandler = ({ width: reportedWidth }) => {
1895
1885
  childrenWidth.current.push({ width: reportedWidth + itemsGap });
@@ -1958,11 +1948,10 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
1958
1948
  const customComponents = React__namespace.useMemo(() => {
1959
1949
  return {
1960
1950
  ValueContainer: props => {
1961
- var _a;
1962
1951
  if (props.isMulti && Array.isArray(props.children) && props.children.length > 0) {
1963
1952
  const PLACEHOLDER_KEY = "placeholder";
1964
1953
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1965
- const key = props && props.children && props.children[0] ? (_a = props.children[0]) === null || _a === void 0 ? void 0 : _a.key : "";
1954
+ const key = props && props.children && props.children[0] ? props.children[0]?.key : "";
1966
1955
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1967
1956
  const values = props && props.children ? props.children[0] : [];
1968
1957
  const tags = key === PLACEHOLDER_KEY ? [] : values;
@@ -1983,12 +1972,11 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
1983
1972
  })
1984
1973
  : [], postFix: searchInput, width: "100%" })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [tags
1985
1974
  ? tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
1986
- var _a;
1987
1975
  return (jsxRuntime.jsx(reactComponents.Tag, { className: "inline-flex shrink-0", color: disabled ? "unknown" : "primary", dataTestId: tagProps.children ? `${tagProps.children.toString()}-tag` : undefined, onClose: e => {
1988
1976
  e.stopPropagation();
1989
1977
  refMenuIsEnabled.current = false;
1990
1978
  tagProps.removeProps.onClick && tagProps.removeProps.onClick(e);
1991
- }, children: tagProps.children }, (_a = tagProps.children) === null || _a === void 0 ? void 0 : _a.toString()));
1979
+ }, children: tagProps.children }, tagProps.children?.toString()));
1992
1980
  })
1993
1981
  : null, tags && tags.length > maxSelectedDisplayCount ? (jsxRuntime.jsxs(reactComponents.Tag, { color: "neutral", dataTestId: "counter-tag", children: ["+", tags.length - maxSelectedDisplayCount] })) : null, searchInput] })) }));
1994
1982
  }
@@ -1999,7 +1987,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
1999
1987
  },
2000
1988
  DropdownIndicator: props => {
2001
1989
  const icon = props.selectProps.menuIsOpen ? (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronUp", size: "medium" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronDown", size: "medium" }));
2002
- return props.selectProps.isLoading || props.selectProps.isDisabled || readOnly ? null : (jsxRuntime.jsx(ReactSelect.components.DropdownIndicator, { ...props, children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon !== null && dropdownIcon !== void 0 ? dropdownIcon : icon }) }));
1990
+ return props.selectProps.isLoading || props.selectProps.isDisabled || readOnly ? null : (jsxRuntime.jsx(ReactSelect.components.DropdownIndicator, { ...props, children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ?? icon }) }));
2003
1991
  },
2004
1992
  IndicatorSeparator: () => null,
2005
1993
  ClearIndicator: props => {
@@ -2049,7 +2037,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
2049
2037
  ...props.innerProps,
2050
2038
  role: "option",
2051
2039
  onClick: () => { },
2052
- }, children: props.isMulti ? (jsxRuntime.jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) : (jsxRuntime.jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) }));
2040
+ }, children: props.isMulti ? (jsxRuntime.jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled, optionLabelDescription: getOptionLabelDescription?.(props.data) })) : (jsxRuntime.jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled, optionLabelDescription: getOptionLabelDescription?.(props.data) })) }));
2053
2041
  },
2054
2042
  ...componentsProps,
2055
2043
  };
@@ -2167,7 +2155,6 @@ const useCustomStyles = ({ refContainer, refPrefix, maxSelectedDisplayCount, sty
2167
2155
  * @returns {UseSelectProps} Select component
2168
2156
  */
2169
2157
  const useSelect = ({ 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, getOptionLabelDescription, ...props }) => {
2170
- var _a;
2171
2158
  const refContainer = React.useRef(null);
2172
2159
  const refPrefix = React.useRef(null);
2173
2160
  const { customStyles } = useCustomStyles({
@@ -2177,7 +2164,7 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
2177
2164
  styles,
2178
2165
  disabled: Boolean(disabled),
2179
2166
  });
2180
- const [menuIsOpen, setMenuIsOpen] = React.useState((_a = props.menuIsOpen) !== null && _a !== void 0 ? _a : false);
2167
+ const [menuIsOpen, setMenuIsOpen] = React.useState(props.menuIsOpen ?? false);
2181
2168
  const refMenuIsEnabled = React.useRef(true);
2182
2169
  const customComponents = useCustomComponents({
2183
2170
  componentsProps: components,
@@ -2193,7 +2180,7 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
2193
2180
  });
2194
2181
  const menuPlacement = "auto";
2195
2182
  const openMenuHandler = async () => {
2196
- onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
2183
+ onMenuOpen?.();
2197
2184
  if (refMenuIsEnabled.current) {
2198
2185
  setMenuIsOpen(true);
2199
2186
  }
@@ -2367,7 +2354,6 @@ const FormFieldSelectAdapter = React.forwardRef(({ className, dataTestId, helpTe
2367
2354
  const innerRef = React.useRef(null);
2368
2355
  React.useImperativeHandle(ref, () => innerRef.current, []);
2369
2356
  React.useEffect(() => {
2370
- var _a;
2371
2357
  if (innerValue === undefined) {
2372
2358
  return;
2373
2359
  }
@@ -2375,8 +2361,8 @@ const FormFieldSelectAdapter = React.forwardRef(({ className, dataTestId, helpTe
2375
2361
  if (innerValue === "" && innerRef.current) {
2376
2362
  innerRef.current.value = ""; // Set the desired option value
2377
2363
  }
2378
- (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
2379
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
2364
+ innerRef.current?.dispatchEvent(event);
2365
+ onChange?.(event);
2380
2366
  }, [onChange, innerValue, isFirstRender]);
2381
2367
  const optionsWithCurrentSelectionBackupOption = [
2382
2368
  // Add the current selection in case there's no options loaded yet (in CreatableSelect)
@@ -2712,7 +2698,7 @@ const validateUrl = (url, required) => {
2712
2698
  * NOTE: If shown with a label, please use the `UrlField` component instead.
2713
2699
  */
2714
2700
  const UrlInput = React.forwardRef(({ dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue, ...rest }, ref) => {
2715
- const [url, setUrl] = React.useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
2701
+ const [url, setUrl] = React.useState(value?.toString() || defaultValue?.toString());
2716
2702
  const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
2717
2703
  return (jsxRuntime.jsx(BaseInput, { dataTestId: dataTestId ? `${dataTestId}-url-input` : undefined, disabled: disabled, id: "url-input", isInvalid: renderAsInvalid, onChange: e => setUrl(e.target.value), placeholder: rest.placeholder || "https://www.example.com", ref: ref, type: "url", value: url, ...rest, actions: !disableAction && (jsxRuntime.jsx(ActionButton, { dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", disabled: renderAsInvalid || disableAction, iconSize: fieldSize, type: "WEB_ADDRESS", value: url })) }));
2718
2704
  });
@@ -2727,17 +2713,16 @@ const UrlField = React.forwardRef(({ label, id, tip, helpText, errorMessage, hel
2727
2713
  const htmlForId = id ? id : "urlField-" + sharedUtils.uuidv4();
2728
2714
  const [t] = useTranslation();
2729
2715
  const [innerValue, setInnerValue] = React.useState(() => {
2730
- var _a;
2731
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : "";
2716
+ return (value?.toString() || defaultValue?.toString()) ?? "";
2732
2717
  });
2733
2718
  const [renderAsInvalid, setRenderAsInvalid] = React.useState(!!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid);
2734
- const errorType = React.useMemo(() => validateUrl(innerValue !== null && innerValue !== void 0 ? innerValue : "", rest.required), [rest.required, innerValue]);
2719
+ const errorType = React.useMemo(() => validateUrl(innerValue ?? "", rest.required), [rest.required, innerValue]);
2735
2720
  const error = React.useMemo(() => (errorType ? t(`urlField.error.${errorType}`) : errorMessage), [errorType, errorMessage, t]);
2736
2721
  const handleBlur = React.useCallback(event => {
2737
2722
  const newValue = event.target.value;
2738
2723
  setInnerValue(newValue);
2739
2724
  setRenderAsInvalid(!!validateUrl(newValue, rest.required));
2740
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
2725
+ onBlur?.(event);
2741
2726
  }, [onBlur, rest.required]);
2742
2727
  return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: renderAsInvalid ? error : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required ? !(rest.disabled || rest.readOnly) : false, tip: tip, children: jsxRuntime.jsx(UrlInput, { "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, onBlur: handleBlur, ref: ref, value: value || defaultValue, ...rest, className: className, dataTestId: dataTestId }) }));
2743
2728
  });
package/index.esm.js CHANGED
@@ -129,7 +129,6 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className }
129
129
  }
130
130
  };
131
131
  const buttonAction = () => {
132
- var _a, _b;
133
132
  switch (type) {
134
133
  case "EMAIL":
135
134
  return window.open(`mailto:${value}`);
@@ -144,7 +143,7 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className }
144
143
  // Typescript seems to be unable to detect RefObject
145
144
  // as one of the members of the union RefObject | string | null which gives access to the `current` property
146
145
  // eslint-disable-next-line react/prop-types
147
- return copyToClipboard((_b = (_a = value === null || value === void 0 ? void 0 : value.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
146
+ return copyToClipboard(value?.current?.value ?? "");
148
147
  default:
149
148
  return null;
150
149
  }
@@ -360,7 +359,6 @@ const DisabledForReasonsTip = ({ reasons, kind }) => {
360
359
  * This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
361
360
  */
362
361
  const BaseInput = React.forwardRef(({ className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, showDefaultActions = false, inputClassName, placeholder, addonBeforeClassName, style, ...rest }, ref) => {
363
- var _a;
364
362
  const renderAsDisabled = Boolean(rest.disabled) || rest.readOnly;
365
363
  const innerRef = React.useRef(null);
366
364
  // eslint-disable-next-line local-rules/no-typescript-assertion
@@ -388,7 +386,7 @@ const BaseInput = React.forwardRef(({ className, isInvalid, dataTestId, prefix,
388
386
  actions: (actions && !compareReactNodes(addonBefore, actions)) || false,
389
387
  }), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null, rest.readOnly === true &&
390
388
  showDefaultActions &&
391
- ((_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.value.length) &&
389
+ innerRef.current?.value.length &&
392
390
  innerRef.current.value.length > 0 ? (jsx(ActionButton, { type: "COPY", value: innerRef }, "default-copy-action")) : null, actions && !compareReactNodes(addonBefore, actions) ? (jsx("div", { className: cvaInputAction({
393
391
  addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
394
392
  suffix: !compareReactNodes(addonBefore, suffix),
@@ -568,13 +566,12 @@ const Checkbox = React.forwardRef(({ className, dataTestId = "checkbox", onChang
568
566
  const textIsCutOff = useIsTextCutOff(labelRef);
569
567
  const isReadonly = disabled || readOnly;
570
568
  const onKeyPress = e => {
571
- var _a, _b;
572
569
  if ("Space" === e.code) {
573
570
  e.preventDefault();
574
- (_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.click();
571
+ internalRef.current?.click();
575
572
  }
576
573
  if ("Enter" === e.code) {
577
- (_b = internalRef.current) === null || _b === void 0 ? void 0 : _b.click();
574
+ internalRef.current?.click();
578
575
  }
579
576
  };
580
577
  const uuid = rest.id;
@@ -697,7 +694,7 @@ const ColorField = forwardRef(({ label, id, tip, helpText, errorMessage, helpAdd
697
694
  const newValue = event.target.value;
698
695
  setInnerValue(newValue);
699
696
  setRenderAsInvalid(!!errorType);
700
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
697
+ onBlur?.(event);
701
698
  }, [errorType, onBlur]);
702
699
  const handleChange = useCallback((event) => {
703
700
  const newValue = event.target.value;
@@ -845,13 +842,12 @@ const DropZone = ({ className, dataTestId, filesSelected, label = jsx(DropZoneDe
845
842
  };
846
843
  //function to handle focusable button click (for accessibility)
847
844
  const handleButtonClick = (e) => {
848
- var _a;
849
845
  e.preventDefault();
850
846
  e.stopPropagation();
851
847
  if (disabled) {
852
848
  return;
853
849
  }
854
- (_a = inputLabelRef.current) === null || _a === void 0 ? void 0 : _a.click();
850
+ inputLabelRef.current?.click();
855
851
  };
856
852
  return (jsx("div", { className: cvaDropZone({ size, dropComplete: fileDropped, dragActive, disabled, invalid: isInvalid, className }), "data-testid": dataTestId, onClick: e => {
857
853
  if (disabled) {
@@ -910,7 +906,7 @@ const EmailInput = React.forwardRef(({ fieldSize = "medium", disabled = false, d
910
906
  };
911
907
  const handleChange = useCallback(event => {
912
908
  const newValue = event.target.value;
913
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
909
+ onChange?.(event);
914
910
  setEmail(newValue);
915
911
  }, [onChange]);
916
912
  const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
@@ -927,17 +923,16 @@ const EmailField = forwardRef(({ label, id, tip, helpText, errorMessage, helpAdd
927
923
  const htmlForId = id ? id : "emailField-" + uuidv4();
928
924
  const [t] = useTranslation();
929
925
  const [innerValue, setInnerValue] = useState(() => {
930
- var _a;
931
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : "";
926
+ return (value?.toString() || defaultValue?.toString()) ?? "";
932
927
  });
933
928
  const [renderAsInvalid, setRenderAsInvalid] = useState(!!errorMessage || (value && isString(value) && !validateEmailAddress(value)) || isInvalid);
934
- const errorType = useMemo(() => validateEmailId(innerValue !== null && innerValue !== void 0 ? innerValue : "", rest.required), [rest.required, innerValue]);
929
+ const errorType = useMemo(() => validateEmailId(innerValue ?? "", rest.required), [rest.required, innerValue]);
935
930
  const error = useMemo(() => (errorType ? t(`emailField.error.${errorType}`) : errorMessage), [errorType, errorMessage, t]);
936
931
  const handleBlur = useCallback(event => {
937
932
  const newValue = event.target.value;
938
933
  setInnerValue(newValue);
939
934
  setRenderAsInvalid(!!errorType);
940
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
935
+ onBlur?.(event);
941
936
  }, [errorType, onBlur]);
942
937
  const handleChange = useCallback((event) => {
943
938
  setInnerValue(event.target.value);
@@ -1020,10 +1015,10 @@ const NumberField = forwardRef(({ label, id, tip, helpText, errorMessage, helpAd
1020
1015
  const htmlForId = id ? id : "numberField-" + uuidv4();
1021
1016
  const [t] = useTranslation();
1022
1017
  const [innerValue, setInnerValue] = useState(() => {
1023
- return Number(value === null || value === void 0 ? void 0 : value.toString()) || Number(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString());
1018
+ return Number(value?.toString()) || Number(defaultValue?.toString());
1024
1019
  });
1025
1020
  const [renderAsInvalid, setRenderAsInvalid] = useState((isInvalid === undefined ? Boolean(errorMessage) : isInvalid) ||
1026
- !!validateNumber(value === null || value === void 0 ? void 0 : value.toString(), rest.required, rest.min, rest.max));
1021
+ !!validateNumber(value?.toString(), rest.required, rest.min, rest.max));
1027
1022
  const errorType = useMemo(() => validateNumber(innerValue, rest.required, rest.min, rest.max), [innerValue, rest.max, rest.min, rest.required]);
1028
1023
  const error = useMemo(() => {
1029
1024
  // for the case when a custom error message is provided
@@ -1046,7 +1041,7 @@ const NumberField = forwardRef(({ label, id, tip, helpText, errorMessage, helpAd
1046
1041
  else {
1047
1042
  setRenderAsInvalid(!!validateNumber(newValue, rest.required, rest.min, rest.max));
1048
1043
  }
1049
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
1044
+ onBlur?.(event);
1050
1045
  }, [errorMessage, onBlur, rest.max, rest.min, rest.required]);
1051
1046
  const handleChange = useCallback((event) => {
1052
1047
  setInnerValue(event.target.value);
@@ -1088,7 +1083,7 @@ const cvaOptionCardContainer = cvaMerge(["contents"]);
1088
1083
  * A card version of a radio button that includes an icon, headings and a description.
1089
1084
  */
1090
1085
  const OptionCard = forwardRef(({ icon, heading, subheading, description, disabled, id, value, className, contentClassName, dataTestId, customImage, ...rest }, ref) => {
1091
- const htmlForId = id !== null && id !== void 0 ? id : "option-card-" + uuidv4();
1086
+ const htmlForId = id ?? "option-card-" + uuidv4();
1092
1087
  return (jsxs("div", { className: cvaOptionCardContainer(), "data-testid": dataTestId, children: [jsx("input", { className: "peer absolute h-0 w-0 opacity-0", "data-testid": `${dataTestId}-option-card`, disabled: disabled, id: htmlForId, ref: ref, type: "radio", value: value, ...rest }), jsxs("label", { className: cvaOptionCardLabel({ className, disabled }), "data-testid": `${dataTestId}-option-card-label`, htmlFor: htmlForId, children: [disabled && icon && !customImage
1093
1088
  ? cloneElement(icon, { className: `${icon.props.className} text-secondary-400` })
1094
1089
  : null, disabled && customImage ? jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }) : null, !disabled && !customImage && icon, !disabled && customImage ? jsx("img", { alt: "logo", className: customImage.className, src: customImage.src }) : null, heading ? (jsx(Heading, { subtle: disabled, variant: "secondary", children: heading })) : null, subheading || description ? (jsxs("div", { className: cvaOptionCardContent({ className: contentClassName }), children: [subheading ? (jsx(Text, { align: "center", subtle: disabled, type: "span", weight: "thick", children: subheading })) : null, description ? (jsx(Text, { align: "center", subtle: true, type: "span", children: description })) : null] })) : null] })] }));
@@ -1117,7 +1112,7 @@ const PasswordField = forwardRef(({ id, label, tip, helpText, helpAddon, errorMe
1117
1112
  const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
1118
1113
  const htmlFor = id ? id : "passwordField-" + uuidv4();
1119
1114
  const handleChange = useCallback((event) => {
1120
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
1115
+ onChange?.(event);
1121
1116
  }, [onChange]);
1122
1117
  return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, required: rest.required ? !(rest.disabled || rest.readOnly) : false, tip: tip, children: jsx(PasswordInput, { ...rest, "aria-labelledby": htmlFor + "-label", className: className, dataTestId: dataTestId, disabled: rest.readOnly, id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, onChange: handleChange, ref: ref, value: value }) }));
1123
1118
  });
@@ -1189,8 +1184,7 @@ const DEFAULT_COUNTRY_CODE = undefined;
1189
1184
  */
1190
1185
  const PhoneInput = forwardRef(({ dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, readOnly, onFocus, onBlur, name, ...rest }, ref) => {
1191
1186
  const [innerValue, setInnerValue] = useState(() => {
1192
- var _a;
1193
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : "";
1187
+ return (value?.toString() || defaultValue?.toString()) ?? "";
1194
1188
  });
1195
1189
  const fieldIsFocused = useRef(false);
1196
1190
  const [countryCode, setCountryCode] = useState(DEFAULT_COUNTRY_CODE);
@@ -1203,7 +1197,7 @@ const PhoneInput = forwardRef(({ dataTestId, isInvalid, disabled = false, value,
1203
1197
  const newValue = event.target.value;
1204
1198
  const noneFormattedValue = parseIncompletePhoneNumber(newValue);
1205
1199
  event.target.value = noneFormattedValue;
1206
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
1200
+ onChange?.(event);
1207
1201
  setInnerValue(newValue);
1208
1202
  determineCountry(newValue);
1209
1203
  }, [onChange, determineCountry]);
@@ -1221,17 +1215,17 @@ const PhoneInput = forwardRef(({ dataTestId, isInvalid, disabled = false, value,
1221
1215
  const handleBlur = useCallback(event => {
1222
1216
  const newValue = event.target.value;
1223
1217
  makePretty(newValue);
1224
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
1218
+ onBlur?.(event);
1225
1219
  fieldIsFocused.current = false;
1226
1220
  }, [makePretty, onBlur]);
1227
1221
  const handleFocus = useCallback(event => {
1228
1222
  const newValue = event.target.value;
1229
1223
  const noneFormattedValue = parseIncompletePhoneNumber(newValue);
1230
1224
  setInnerValue(noneFormattedValue);
1231
- onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
1225
+ onFocus?.(event);
1232
1226
  fieldIsFocused.current = true;
1233
1227
  }, [onFocus]);
1234
- return (jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsx(BaseInput, { actions: !disableAction && innerValue && innerValue.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue, ...rest }) }));
1228
+ return (jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsx(BaseInput, { actions: !disableAction && innerValue && innerValue.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: value?.toString() || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue, ...rest }) }));
1235
1229
  });
1236
1230
  PhoneInput.displayName = "PhoneInput";
1237
1231
 
@@ -1305,11 +1299,10 @@ const PhoneField = forwardRef(({ label, id, tip, helpText, isInvalid, errorMessa
1305
1299
  const htmlForId = id ? id : "phoneField-" + uuidv4();
1306
1300
  const [t] = useTranslation();
1307
1301
  const [innerValue, setInnerValue] = useState(() => {
1308
- var _a;
1309
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : undefined;
1302
+ return (value?.toString() || defaultValue?.toString()) ?? undefined;
1310
1303
  });
1311
1304
  const [renderAsInvalid, setRenderAsInvalid] = useState((isInvalid === undefined ? Boolean(errorMessage) : isInvalid) ||
1312
- !!phoneErrorMessage(value === null || value === void 0 ? void 0 : value.toString(), rest.required));
1305
+ !!phoneErrorMessage(value?.toString(), rest.required));
1313
1306
  const errorType = useMemo(() => phoneErrorMessage(innerValue, rest.required), [innerValue, rest.required]);
1314
1307
  const error = useMemo(() => {
1315
1308
  // for the case when a custom error message is provided
@@ -1332,7 +1325,7 @@ const PhoneField = forwardRef(({ label, id, tip, helpText, isInvalid, errorMessa
1332
1325
  else {
1333
1326
  setRenderAsInvalid(!!phoneErrorMessage(newValue.toString(), rest.required));
1334
1327
  }
1335
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
1328
+ onBlur?.(event);
1336
1329
  }, [errorMessage, onBlur, rest.required]);
1337
1330
  return (jsx(FormGroup, { className: className, dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: (renderAsInvalid && error) || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required ? !(rest.disabled || rest.readOnly) : false, tip: tip, children: jsx(PhoneInput, { "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, defaultValue: defaultValue, id: htmlForId, isInvalid: renderAsInvalid, name: name, onBlur: handleBlur, ref: ref, value: value, ...rest }) }));
1338
1331
  });
@@ -1472,21 +1465,21 @@ RadioGroup.displayName = "RadioGroup";
1472
1465
  */
1473
1466
  const RadioItem = ({ label, value, dataTestId, className, description, suffix, ...rest }) => {
1474
1467
  const groupCtx = useContext(RadioGroupContext);
1475
- const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
1468
+ const isChecked = groupCtx?.value === value;
1476
1469
  const labelRef = useRef(null);
1477
1470
  const descriptionRef = useRef(null);
1478
1471
  const labelTextIsCutOff = useIsTextCutOff(labelRef);
1479
1472
  const descriptionTextIsCutOff = useIsTextCutOff(descriptionRef);
1480
- const descriptionId = description ? `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}-description` : undefined;
1481
- const inputId = `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`;
1473
+ const descriptionId = description ? `${groupCtx?.id}-${value}-description` : undefined;
1474
+ const inputId = `${groupCtx?.id}-${value}`;
1482
1475
  return (jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : undefined, htmlFor: inputId, children: [jsx("input", { "aria-describedby": descriptionId, checked: isChecked, className: cvaRadioItem({
1483
1476
  checked: isChecked,
1484
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1485
- invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1486
- }), "data-testid": dataTestId, id: inputId, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value, ...rest }), jsx(Tooltip, { className: cvaLabelTooltip(), dataTestId: dataTestId ? `${dataTestId}-Label-Tooltip` : undefined, disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsx("span", { className: cvaLabel({
1487
- invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1488
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1489
- }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, ref: labelRef, children: label }) }, "tooltip-" + rest.name), suffix ? (jsx("div", { className: cvaSuffixContainer(), "data-testid": dataTestId ? `${dataTestId}-suffix-container` : undefined, children: suffix })) : null, description ? (jsx(Tooltip, { className: cvaDescriptionTooltip(), dataTestId: dataTestId ? `${dataTestId}-Description-Tooltip` : undefined, disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsx("span", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : undefined, id: descriptionId, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null] }));
1477
+ disabled: groupCtx?.disabled,
1478
+ invalid: groupCtx?.isInvalid,
1479
+ }), "data-testid": dataTestId, id: inputId, onChange: groupCtx?.onChange, type: "radio", value: value, ...rest }), jsx(Tooltip, { className: cvaLabelTooltip(), dataTestId: dataTestId ? `${dataTestId}-Label-Tooltip` : undefined, disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsx("span", { className: cvaLabel({
1480
+ invalid: groupCtx?.isInvalid,
1481
+ disabled: groupCtx?.disabled,
1482
+ }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, ref: labelRef, children: label }) }, "tooltip-" + rest.name), suffix ? (jsx("div", { className: cvaSuffixContainer(), "data-testid": dataTestId ? `${dataTestId}-suffix-container` : undefined, children: suffix })) : null, description ? (jsx(Tooltip, { className: cvaDescriptionTooltip(), dataTestId: dataTestId ? `${dataTestId}-Description-Tooltip` : undefined, disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsx("span", { className: cvaRadioItemDescription({ disabled: groupCtx?.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : undefined, id: descriptionId, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null] }));
1490
1483
  };
1491
1484
 
1492
1485
  const cvaTimeRange = cvaMerge([
@@ -1506,7 +1499,7 @@ const cvaTimeRange = cvaMerge([
1506
1499
  * @returns {JSX.Element} TimeRange component
1507
1500
  */
1508
1501
  const TimeRange = ({ id, className, dataTestId, children, range, onChange, disabled, isInvalid, }) => {
1509
- const [timeRange, setTimeRange] = React__default.useState(range !== null && range !== void 0 ? range : {
1502
+ const [timeRange, setTimeRange] = React__default.useState(range ?? {
1510
1503
  timeFrom: "",
1511
1504
  timeTo: "",
1512
1505
  });
@@ -1517,7 +1510,7 @@ const TimeRange = ({ id, className, dataTestId, children, range, onChange, disab
1517
1510
  setTimeRange(prev => ({ ...prev, timeTo }));
1518
1511
  };
1519
1512
  const onRangeChange = () => onChange(timeRange);
1520
- return (jsxs("div", { className: cvaTimeRange({ className }), "data-testid": dataTestId, id: id, children: [jsx(BaseInput, { dataTestId: `${dataTestId}-from`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeFrom(time.currentTarget.value), type: "time", value: timeRange.timeFrom }), children !== null && children !== void 0 ? children : jsx("div", { "data-testid": `${dataTestId}-separator`, children: "-" }), jsx(BaseInput, { dataTestId: `${dataTestId}-to`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeTo(time.currentTarget.value), type: "time", value: timeRange.timeTo })] }));
1513
+ return (jsxs("div", { className: cvaTimeRange({ className }), "data-testid": dataTestId, id: id, children: [jsx(BaseInput, { dataTestId: `${dataTestId}-from`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeFrom(time.currentTarget.value), type: "time", value: timeRange.timeFrom }), children ?? jsx("div", { "data-testid": `${dataTestId}-separator`, children: "-" }), jsx(BaseInput, { dataTestId: `${dataTestId}-to`, disabled: disabled, isInvalid: isInvalid, onBlur: onRangeChange, onChange: (time) => onChangeTo(time.currentTarget.value), type: "time", value: timeRange.timeTo })] }));
1521
1514
  };
1522
1515
 
1523
1516
  const cvaScheduleItem = cvaMerge([
@@ -1590,7 +1583,7 @@ const parseSchedule = (scheduleString) => {
1590
1583
  }
1591
1584
  const schedule = scheduleString.split(",").map(daySchedule => {
1592
1585
  const [day, timeRange] = daySchedule.split("#");
1593
- const [timeFrom, timeTo] = (timeRange !== null && timeRange !== void 0 ? timeRange : "").split("-");
1586
+ const [timeFrom, timeTo] = (timeRange ?? "").split("-");
1594
1587
  const isAllDay = timeFrom === "00:00" && timeTo === "24:00";
1595
1588
  return {
1596
1589
  day: Number(day),
@@ -1664,7 +1657,7 @@ const serializeSchedule = (weekSchedule) => {
1664
1657
  * @returns {boolean} Whether the schedule is uniform
1665
1658
  */
1666
1659
  const isUniform = (schedule) => {
1667
- return schedule.every((day, _, collection) => { var _a, _b, _c, _d, _e, _f; return ((_b = (_a = collection[0]) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.timeFrom) === ((_c = day.range) === null || _c === void 0 ? void 0 : _c.timeFrom) && ((_e = (_d = collection[0]) === null || _d === void 0 ? void 0 : _d.range) === null || _e === void 0 ? void 0 : _e.timeTo) === ((_f = day.range) === null || _f === void 0 ? void 0 : _f.timeTo); });
1660
+ return schedule.every((day, _, collection) => collection[0]?.range?.timeFrom === day.range?.timeFrom && collection[0]?.range?.timeTo === day.range?.timeTo);
1668
1661
  };
1669
1662
  /**
1670
1663
  * Checks if a list of schedule objects are consecutive days
@@ -1716,8 +1709,7 @@ const cvaSearch = cvaMerge([
1716
1709
  * @returns {JSX.Element} Search component
1717
1710
  */
1718
1711
  const Search = forwardRef(({ className, placeholder = "Search", value, widenInputOnFocus, hideBorderWhenNotInFocus = false, disabled, onKeyUp, onChange, onFocus, onBlur, name, onClear, dataTestId, autoComplete = "on", loading, inputClassName, iconName = "MagnifyingGlass", ...rest }, ref) => {
1719
- var _a, _b;
1720
- return (jsx(TextInput, { ...rest, autoComplete: autoComplete, className: cvaSearch({ className, border: hideBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), dataTestId: dataTestId, disabled: disabled, inputClassName: inputClassName, name: name, onBlur: onBlur, onChange: onChange, onFocus: onFocus, onKeyUp: onKeyUp, placeholder: placeholder, prefix: loading ? (jsx(Spinner, { centering: "centered", size: (_a = rest.fieldSize) !== null && _a !== void 0 ? _a : undefined })) : (jsx(Icon, { name: iconName, size: (_b = rest.fieldSize) !== null && _b !== void 0 ? _b : undefined })), ref: ref, suffix:
1712
+ return (jsx(TextInput, { ...rest, autoComplete: autoComplete, className: cvaSearch({ className, border: hideBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), dataTestId: dataTestId, disabled: disabled, inputClassName: inputClassName, name: name, onBlur: onBlur, onChange: onChange, onFocus: onFocus, onKeyUp: onKeyUp, placeholder: placeholder, prefix: loading ? (jsx(Spinner, { centering: "centered", size: rest.fieldSize ?? undefined })) : (jsx(Icon, { name: iconName, size: rest.fieldSize ?? undefined })), ref: ref, suffix:
1721
1713
  //only show the clear button if there is a value and the onClear function is provided
1722
1714
  onClear && value ? (jsx("button", { className: "flex", "data-testid": dataTestId ? `${dataTestId}_suffix_component` : null, onClick: () => {
1723
1715
  onClear();
@@ -1849,8 +1841,7 @@ const MultiSelectMenuItem = ({ label, onClick, selected, dataTestId, disabled, o
1849
1841
  const TagWithWidth = ({ onWidthKnown, children, ...rest }) => {
1850
1842
  const ref = React__default.useRef(null);
1851
1843
  React__default.useLayoutEffect(() => {
1852
- var _a;
1853
- onWidthKnown && onWidthKnown({ width: ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0 });
1844
+ onWidthKnown && onWidthKnown({ width: ref.current?.offsetWidth || 0 });
1854
1845
  }, [ref, onWidthKnown]);
1855
1846
  return (jsx(Tag, { ref: ref, ...rest, children: children }));
1856
1847
  };
@@ -1869,8 +1860,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
1869
1860
  const childrenWidth = React__default.useRef([]);
1870
1861
  const itemsCount = items.length;
1871
1862
  React__default.useLayoutEffect(() => {
1872
- var _a;
1873
- availableWidth.current = ((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
1863
+ availableWidth.current = containerRef.current?.offsetWidth || 0;
1874
1864
  }, [containerRef]);
1875
1865
  const onWidthKnownHandler = ({ width: reportedWidth }) => {
1876
1866
  childrenWidth.current.push({ width: reportedWidth + itemsGap });
@@ -1939,11 +1929,10 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
1939
1929
  const customComponents = React.useMemo(() => {
1940
1930
  return {
1941
1931
  ValueContainer: props => {
1942
- var _a;
1943
1932
  if (props.isMulti && Array.isArray(props.children) && props.children.length > 0) {
1944
1933
  const PLACEHOLDER_KEY = "placeholder";
1945
1934
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1946
- const key = props && props.children && props.children[0] ? (_a = props.children[0]) === null || _a === void 0 ? void 0 : _a.key : "";
1935
+ const key = props && props.children && props.children[0] ? props.children[0]?.key : "";
1947
1936
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1948
1937
  const values = props && props.children ? props.children[0] : [];
1949
1938
  const tags = key === PLACEHOLDER_KEY ? [] : values;
@@ -1964,12 +1953,11 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
1964
1953
  })
1965
1954
  : [], postFix: searchInput, width: "100%" })) : (jsxs(Fragment, { children: [tags
1966
1955
  ? tags.slice(0, maxSelectedDisplayCount).map(({ props: tagProps }) => {
1967
- var _a;
1968
1956
  return (jsx(Tag, { className: "inline-flex shrink-0", color: disabled ? "unknown" : "primary", dataTestId: tagProps.children ? `${tagProps.children.toString()}-tag` : undefined, onClose: e => {
1969
1957
  e.stopPropagation();
1970
1958
  refMenuIsEnabled.current = false;
1971
1959
  tagProps.removeProps.onClick && tagProps.removeProps.onClick(e);
1972
- }, children: tagProps.children }, (_a = tagProps.children) === null || _a === void 0 ? void 0 : _a.toString()));
1960
+ }, children: tagProps.children }, tagProps.children?.toString()));
1973
1961
  })
1974
1962
  : null, tags && tags.length > maxSelectedDisplayCount ? (jsxs(Tag, { color: "neutral", dataTestId: "counter-tag", children: ["+", tags.length - maxSelectedDisplayCount] })) : null, searchInput] })) }));
1975
1963
  }
@@ -1980,7 +1968,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
1980
1968
  },
1981
1969
  DropdownIndicator: props => {
1982
1970
  const icon = props.selectProps.menuIsOpen ? (jsx(Icon, { name: "ChevronUp", size: "medium" })) : (jsx(Icon, { name: "ChevronDown", size: "medium" }));
1983
- return props.selectProps.isLoading || props.selectProps.isDisabled || readOnly ? null : (jsx(components.DropdownIndicator, { ...props, children: jsx("div", { className: cvaSelectIcon(), children: dropdownIcon !== null && dropdownIcon !== void 0 ? dropdownIcon : icon }) }));
1971
+ return props.selectProps.isLoading || props.selectProps.isDisabled || readOnly ? null : (jsx(components.DropdownIndicator, { ...props, children: jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ?? icon }) }));
1984
1972
  },
1985
1973
  IndicatorSeparator: () => null,
1986
1974
  ClearIndicator: props => {
@@ -2030,7 +2018,7 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, refMenuIsEna
2030
2018
  ...props.innerProps,
2031
2019
  role: "option",
2032
2020
  onClick: () => { },
2033
- }, children: props.isMulti ? (jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) : (jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled, optionLabelDescription: getOptionLabelDescription === null || getOptionLabelDescription === void 0 ? void 0 : getOptionLabelDescription(props.data) })) }));
2021
+ }, children: props.isMulti ? (jsx(MultiSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled, optionLabelDescription: getOptionLabelDescription?.(props.data) })) : (jsx(SingleSelectMenuItem, { ...componentProps, dataTestId: typeof props.label === "string" ? props.label : undefined, disabled: disabled || props.isDisabled, optionLabelDescription: getOptionLabelDescription?.(props.data) })) }));
2034
2022
  },
2035
2023
  ...componentsProps,
2036
2024
  };
@@ -2148,7 +2136,6 @@ const useCustomStyles = ({ refContainer, refPrefix, maxSelectedDisplayCount, sty
2148
2136
  * @returns {UseSelectProps} Select component
2149
2137
  */
2150
2138
  const useSelect = ({ 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, getOptionLabelDescription, ...props }) => {
2151
- var _a;
2152
2139
  const refContainer = React__default.useRef(null);
2153
2140
  const refPrefix = React__default.useRef(null);
2154
2141
  const { customStyles } = useCustomStyles({
@@ -2158,7 +2145,7 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
2158
2145
  styles,
2159
2146
  disabled: Boolean(disabled),
2160
2147
  });
2161
- const [menuIsOpen, setMenuIsOpen] = React__default.useState((_a = props.menuIsOpen) !== null && _a !== void 0 ? _a : false);
2148
+ const [menuIsOpen, setMenuIsOpen] = React__default.useState(props.menuIsOpen ?? false);
2162
2149
  const refMenuIsEnabled = React__default.useRef(true);
2163
2150
  const customComponents = useCustomComponents({
2164
2151
  componentsProps: components,
@@ -2174,7 +2161,7 @@ const useSelect = ({ id, className, dataTestId = "select", prefix, async, dropdo
2174
2161
  });
2175
2162
  const menuPlacement = "auto";
2176
2163
  const openMenuHandler = async () => {
2177
- onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
2164
+ onMenuOpen?.();
2178
2165
  if (refMenuIsEnabled.current) {
2179
2166
  setMenuIsOpen(true);
2180
2167
  }
@@ -2348,7 +2335,6 @@ const FormFieldSelectAdapter = forwardRef(({ className, dataTestId, helpText, he
2348
2335
  const innerRef = useRef(null);
2349
2336
  useImperativeHandle(ref, () => innerRef.current, []);
2350
2337
  useEffect(() => {
2351
- var _a;
2352
2338
  if (innerValue === undefined) {
2353
2339
  return;
2354
2340
  }
@@ -2356,8 +2342,8 @@ const FormFieldSelectAdapter = forwardRef(({ className, dataTestId, helpText, he
2356
2342
  if (innerValue === "" && innerRef.current) {
2357
2343
  innerRef.current.value = ""; // Set the desired option value
2358
2344
  }
2359
- (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
2360
- onChange === null || onChange === void 0 ? void 0 : onChange(event);
2345
+ innerRef.current?.dispatchEvent(event);
2346
+ onChange?.(event);
2361
2347
  }, [onChange, innerValue, isFirstRender]);
2362
2348
  const optionsWithCurrentSelectionBackupOption = [
2363
2349
  // Add the current selection in case there's no options loaded yet (in CreatableSelect)
@@ -2693,7 +2679,7 @@ const validateUrl = (url, required) => {
2693
2679
  * NOTE: If shown with a label, please use the `UrlField` component instead.
2694
2680
  */
2695
2681
  const UrlInput = forwardRef(({ dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue, ...rest }, ref) => {
2696
- const [url, setUrl] = useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
2682
+ const [url, setUrl] = useState(value?.toString() || defaultValue?.toString());
2697
2683
  const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
2698
2684
  return (jsx(BaseInput, { dataTestId: dataTestId ? `${dataTestId}-url-input` : undefined, disabled: disabled, id: "url-input", isInvalid: renderAsInvalid, onChange: e => setUrl(e.target.value), placeholder: rest.placeholder || "https://www.example.com", ref: ref, type: "url", value: url, ...rest, actions: !disableAction && (jsx(ActionButton, { dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", disabled: renderAsInvalid || disableAction, iconSize: fieldSize, type: "WEB_ADDRESS", value: url })) }));
2699
2685
  });
@@ -2708,17 +2694,16 @@ const UrlField = forwardRef(({ label, id, tip, helpText, errorMessage, helpAddon
2708
2694
  const htmlForId = id ? id : "urlField-" + uuidv4();
2709
2695
  const [t] = useTranslation();
2710
2696
  const [innerValue, setInnerValue] = useState(() => {
2711
- var _a;
2712
- return (_a = ((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()))) !== null && _a !== void 0 ? _a : "";
2697
+ return (value?.toString() || defaultValue?.toString()) ?? "";
2713
2698
  });
2714
2699
  const [renderAsInvalid, setRenderAsInvalid] = useState(!!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid);
2715
- const errorType = useMemo(() => validateUrl(innerValue !== null && innerValue !== void 0 ? innerValue : "", rest.required), [rest.required, innerValue]);
2700
+ const errorType = useMemo(() => validateUrl(innerValue ?? "", rest.required), [rest.required, innerValue]);
2716
2701
  const error = useMemo(() => (errorType ? t(`urlField.error.${errorType}`) : errorMessage), [errorType, errorMessage, t]);
2717
2702
  const handleBlur = useCallback(event => {
2718
2703
  const newValue = event.target.value;
2719
2704
  setInnerValue(newValue);
2720
2705
  setRenderAsInvalid(!!validateUrl(newValue, rest.required));
2721
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
2706
+ onBlur?.(event);
2722
2707
  }, [onBlur, rest.required]);
2723
2708
  return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon, helpText: renderAsInvalid ? error : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required ? !(rest.disabled || rest.readOnly) : false, tip: tip, children: jsx(UrlInput, { "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, onBlur: handleBlur, ref: ref, value: value || defaultValue, ...rest, className: className, dataTestId: dataTestId }) }));
2724
2709
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -18,7 +18,7 @@
18
18
  "react-hook-form": "7.53.1",
19
19
  "tailwind-merge": "^2.0.0",
20
20
  "@trackunit/css-class-variance-utilities": "^1.0.1",
21
- "@trackunit/react-components": "^1.0.13",
21
+ "@trackunit/react-components": "^1.1.0",
22
22
  "@trackunit/ui-icons": "^1.0.3",
23
23
  "@trackunit/shared-utils": "^1.0.3",
24
24
  "@trackunit/i18n-library-translation": "^1.0.7"
@@ -11,10 +11,10 @@ import { BaseOptionType } from "./FormFieldSelectAdapter";
11
11
  * @returns {JSX.Element} CreatableSelectField component
12
12
  */
13
13
  export declare const CreatableSelectField: import("react").ForwardRefExoticComponent<import("dist/libs/react/components/src").CommonProps & {
14
- label: string | import("react").ReactNode;
15
- tip?: string | import("react").ReactNode;
14
+ label: string | React.ReactNode;
15
+ tip?: string | React.ReactNode;
16
16
  helpText?: (string | null) | undefined;
17
- helpAddon?: string | import("react").ReactNode;
17
+ helpAddon?: string | React.ReactNode;
18
18
  isInvalid?: boolean | undefined;
19
19
  } & import("dist/libs/shared/utils/src").MappedOmit<import("../Select/useSelect").SelectProps<BaseOptionType, false, false, import("react-select").GroupBase<BaseOptionType>>, "label" | "onBlur" | "onChange" | "options" | "value" | "defaultValue"> & {
20
20
  onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
@@ -10,10 +10,10 @@ import { BaseOptionType } from "./FormFieldSelectAdapter";
10
10
  * @returns {JSX.Element} SelectField component
11
11
  */
12
12
  export declare const SelectField: import("react").ForwardRefExoticComponent<import("dist/libs/react/components/src").CommonProps & {
13
- label: string | import("react").ReactNode;
14
- tip?: string | import("react").ReactNode;
13
+ label: string | React.ReactNode;
14
+ tip?: string | React.ReactNode;
15
15
  helpText?: (string | null) | undefined;
16
- helpAddon?: string | import("react").ReactNode;
16
+ helpAddon?: string | React.ReactNode;
17
17
  isInvalid?: boolean | undefined;
18
18
  } & import("dist/libs/shared/utils/src").MappedOmit<import("../Select/useSelect").SelectProps<BaseOptionType, false, false, import("react-select").GroupBase<BaseOptionType>>, "label" | "onBlur" | "onChange" | "options" | "value" | "defaultValue"> & {
19
19
  onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;