@trackunit/react-form-components 0.0.118 → 0.0.120

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
@@ -14493,7 +14493,7 @@ const countryCodes = countryCodesSet.map(code => ({ label: `+${code}`, value: `+
14493
14493
  * @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
14494
14494
  * @returns {JSX.Element} CountryCodeSelect component
14495
14495
  */
14496
- const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, }) => {
14496
+ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, onBlur, }) => {
14497
14497
  const [isCountryCodeMissing, setIsCountryCodeMissing] = React.useState(false);
14498
14498
  React.useEffect(() => {
14499
14499
  countryCode && setIsCountryCodeMissing(false);
@@ -14501,7 +14501,7 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
14501
14501
  const filteredCodes = countryCodes.filter(code => {
14502
14502
  return !(excludedCountries === null || excludedCountries === void 0 ? void 0 : excludedCountries.some(excludedCode => excludedCode.value === code.value));
14503
14503
  });
14504
- return (jsxRuntime.jsx(Select, { dataTestId: dataTestId, className: "w-28", "aria-invalid": isCountryCodeMissing, options: filteredCodes.map(code => code), value: filteredCodes.find(({ value }) => value === `+${countryCode}`), placeholder: placeholder, hasError: isCountryCodeMissing || isInvalid, maxMenuHeight: 200, onChange: onChange, disabled: disabled, readOnly: readOnly, menuIsOpen: readOnly ? false : undefined }));
14504
+ return (jsxRuntime.jsx(Select, { dataTestId: dataTestId, className: "w-28", "aria-invalid": isCountryCodeMissing, options: filteredCodes.map(code => code), value: filteredCodes.find(({ value }) => value === `+${countryCode}`), placeholder: placeholder, hasError: isCountryCodeMissing || isInvalid, maxMenuHeight: 200, onChange: onChange, disabled: disabled, readOnly: readOnly, onBlur: onBlur, menuIsOpen: readOnly ? false : undefined }));
14505
14505
  };
14506
14506
 
14507
14507
  /**
@@ -14515,7 +14515,7 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
14515
14515
  * @returns {JSX.Element} - The PhoneInput component.
14516
14516
  */
14517
14517
  const PhoneInput = React.forwardRef((_a, ref) => {
14518
- var { dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, onChangeGetSeparateValues, readOnly } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "value", "defaultValue", "fieldSize", "disableAction", "onChange", "onChangeGetSeparateValues", "readOnly"]);
14518
+ var { dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, onChangeGetSeparateValues, onBlurCountryCode, readOnly, countryCodePlaceholder } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "value", "defaultValue", "fieldSize", "disableAction", "onChange", "onChangeGetSeparateValues", "onBlurCountryCode", "readOnly", "countryCodePlaceholder"]);
14519
14519
  const hiddenInputRef = React.useRef(null);
14520
14520
  const { countryCode, phoneNumber, isCountryCodeInvalid, isPhoneNumberInvalid, handleCountryCodeChange, handlePhoneNumberChange, combinedValue, isCombinedValueInvalid, } = usePhoneInput(!!value ? value : defaultValue);
14521
14521
  React.useEffect(() => {
@@ -14529,7 +14529,8 @@ const PhoneInput = React.forwardRef((_a, ref) => {
14529
14529
  React.useEffect(() => {
14530
14530
  onChangeGetSeparateValues && onChangeGetSeparateValues({ countryCode, phoneNumber });
14531
14531
  }, [countryCode, onChangeGetSeparateValues, phoneNumber]);
14532
- return (jsxRuntime.jsxs("div", { className: "grid grid-cols-min-fr gap-2", "data-testid": dataTestId && `${dataTestId}-container`, children: [jsxRuntime.jsx("input", { hidden: true, id: "phone-input", "data-testid": dataTestId, value: combinedValue, ref: hiddenInputRef, onChange: onChange, "aria-invalid": isCombinedValueInvalid || isInvalid }), jsxRuntime.jsx(CountryCodeSelect, { dataTestId: dataTestId && `${dataTestId}-countryCodeSelect`, countryCode: countryCode, onChange: handleCountryCodeChange, disabled: disabled, readOnly: readOnly, isInvalid: isCountryCodeInvalid || isInvalid, placeholder: "+45" }), jsxRuntime.jsx(BaseInput, Object.assign({ id: "phoneInput-number", dataTestId: dataTestId && `${dataTestId}-phoneNumberInput`, fieldSize: fieldSize, type: "tel", value: phoneNumber, disabled: disabled, readOnly: readOnly, onChange: handlePhoneNumberChange, isInvalid: isPhoneNumberInvalid || isInvalid, actions: !disableAction && (jsxRuntime.jsx(ActionButton, { disabled: disabled || isInvalid || isCountryCodeInvalid || isPhoneNumberInvalid, value: `${countryCode}${phoneNumber}`, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
14532
+ const countryCodePlaceholderValue = countryCodePlaceholder || "+45";
14533
+ return (jsxRuntime.jsxs("div", { className: "grid grid-cols-min-fr gap-2", "data-testid": dataTestId && `${dataTestId}-container`, children: [jsxRuntime.jsx("input", { hidden: true, id: "phone-input", "data-testid": dataTestId, value: combinedValue, ref: hiddenInputRef, onChange: onChange, "aria-invalid": isCombinedValueInvalid || isInvalid }), jsxRuntime.jsx(CountryCodeSelect, { dataTestId: dataTestId && `${dataTestId}-countryCodeSelect`, countryCode: countryCode, onChange: handleCountryCodeChange, disabled: disabled, readOnly: readOnly, isInvalid: isCountryCodeInvalid || isInvalid, placeholder: countryCodePlaceholderValue, onBlur: onBlurCountryCode }), jsxRuntime.jsx(BaseInput, Object.assign({ id: "phoneInput-number", dataTestId: dataTestId && `${dataTestId}-phoneNumberInput`, fieldSize: fieldSize, type: "tel", value: phoneNumber, disabled: disabled, readOnly: readOnly, onChange: handlePhoneNumberChange, isInvalid: isPhoneNumberInvalid || isInvalid, actions: !disableAction && (jsxRuntime.jsx(ActionButton, { disabled: disabled || isInvalid || isCountryCodeInvalid || isPhoneNumberInvalid, value: `${countryCode}${phoneNumber}`, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
14533
14534
  });
14534
14535
 
14535
14536
  /**
package/index.esm.js CHANGED
@@ -14467,7 +14467,7 @@ const countryCodes = countryCodesSet.map(code => ({ label: `+${code}`, value: `+
14467
14467
  * @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
14468
14468
  * @returns {JSX.Element} CountryCodeSelect component
14469
14469
  */
14470
- const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, }) => {
14470
+ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, onBlur, }) => {
14471
14471
  const [isCountryCodeMissing, setIsCountryCodeMissing] = useState(false);
14472
14472
  useEffect(() => {
14473
14473
  countryCode && setIsCountryCodeMissing(false);
@@ -14475,7 +14475,7 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
14475
14475
  const filteredCodes = countryCodes.filter(code => {
14476
14476
  return !(excludedCountries === null || excludedCountries === void 0 ? void 0 : excludedCountries.some(excludedCode => excludedCode.value === code.value));
14477
14477
  });
14478
- return (jsx$1(Select, { dataTestId: dataTestId, className: "w-28", "aria-invalid": isCountryCodeMissing, options: filteredCodes.map(code => code), value: filteredCodes.find(({ value }) => value === `+${countryCode}`), placeholder: placeholder, hasError: isCountryCodeMissing || isInvalid, maxMenuHeight: 200, onChange: onChange, disabled: disabled, readOnly: readOnly, menuIsOpen: readOnly ? false : undefined }));
14478
+ return (jsx$1(Select, { dataTestId: dataTestId, className: "w-28", "aria-invalid": isCountryCodeMissing, options: filteredCodes.map(code => code), value: filteredCodes.find(({ value }) => value === `+${countryCode}`), placeholder: placeholder, hasError: isCountryCodeMissing || isInvalid, maxMenuHeight: 200, onChange: onChange, disabled: disabled, readOnly: readOnly, onBlur: onBlur, menuIsOpen: readOnly ? false : undefined }));
14479
14479
  };
14480
14480
 
14481
14481
  /**
@@ -14489,7 +14489,7 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
14489
14489
  * @returns {JSX.Element} - The PhoneInput component.
14490
14490
  */
14491
14491
  const PhoneInput = forwardRef((_a, ref) => {
14492
- var { dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, onChangeGetSeparateValues, readOnly } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "value", "defaultValue", "fieldSize", "disableAction", "onChange", "onChangeGetSeparateValues", "readOnly"]);
14492
+ var { dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, onChangeGetSeparateValues, onBlurCountryCode, readOnly, countryCodePlaceholder } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "value", "defaultValue", "fieldSize", "disableAction", "onChange", "onChangeGetSeparateValues", "onBlurCountryCode", "readOnly", "countryCodePlaceholder"]);
14493
14493
  const hiddenInputRef = useRef(null);
14494
14494
  const { countryCode, phoneNumber, isCountryCodeInvalid, isPhoneNumberInvalid, handleCountryCodeChange, handlePhoneNumberChange, combinedValue, isCombinedValueInvalid, } = usePhoneInput(!!value ? value : defaultValue);
14495
14495
  useEffect(() => {
@@ -14503,7 +14503,8 @@ const PhoneInput = forwardRef((_a, ref) => {
14503
14503
  useEffect(() => {
14504
14504
  onChangeGetSeparateValues && onChangeGetSeparateValues({ countryCode, phoneNumber });
14505
14505
  }, [countryCode, onChangeGetSeparateValues, phoneNumber]);
14506
- return (jsxs("div", { className: "grid grid-cols-min-fr gap-2", "data-testid": dataTestId && `${dataTestId}-container`, children: [jsx$1("input", { hidden: true, id: "phone-input", "data-testid": dataTestId, value: combinedValue, ref: hiddenInputRef, onChange: onChange, "aria-invalid": isCombinedValueInvalid || isInvalid }), jsx$1(CountryCodeSelect, { dataTestId: dataTestId && `${dataTestId}-countryCodeSelect`, countryCode: countryCode, onChange: handleCountryCodeChange, disabled: disabled, readOnly: readOnly, isInvalid: isCountryCodeInvalid || isInvalid, placeholder: "+45" }), jsx$1(BaseInput, Object.assign({ id: "phoneInput-number", dataTestId: dataTestId && `${dataTestId}-phoneNumberInput`, fieldSize: fieldSize, type: "tel", value: phoneNumber, disabled: disabled, readOnly: readOnly, onChange: handlePhoneNumberChange, isInvalid: isPhoneNumberInvalid || isInvalid, actions: !disableAction && (jsx$1(ActionButton, { disabled: disabled || isInvalid || isCountryCodeInvalid || isPhoneNumberInvalid, value: `${countryCode}${phoneNumber}`, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
14506
+ const countryCodePlaceholderValue = countryCodePlaceholder || "+45";
14507
+ return (jsxs("div", { className: "grid grid-cols-min-fr gap-2", "data-testid": dataTestId && `${dataTestId}-container`, children: [jsx$1("input", { hidden: true, id: "phone-input", "data-testid": dataTestId, value: combinedValue, ref: hiddenInputRef, onChange: onChange, "aria-invalid": isCombinedValueInvalid || isInvalid }), jsx$1(CountryCodeSelect, { dataTestId: dataTestId && `${dataTestId}-countryCodeSelect`, countryCode: countryCode, onChange: handleCountryCodeChange, disabled: disabled, readOnly: readOnly, isInvalid: isCountryCodeInvalid || isInvalid, placeholder: countryCodePlaceholderValue, onBlur: onBlurCountryCode }), jsx$1(BaseInput, Object.assign({ id: "phoneInput-number", dataTestId: dataTestId && `${dataTestId}-phoneNumberInput`, fieldSize: fieldSize, type: "tel", value: phoneNumber, disabled: disabled, readOnly: readOnly, onChange: handlePhoneNumberChange, isInvalid: isPhoneNumberInvalid || isInvalid, actions: !disableAction && (jsx$1(ActionButton, { disabled: disabled || isInvalid || isCountryCodeInvalid || isPhoneNumberInvalid, value: `${countryCode}${phoneNumber}`, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
14507
14508
  });
14508
14509
 
14509
14510
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.118",
3
+ "version": "0.0.120",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@trackunit/css-class-variance-utilities": "0.0.11",
11
- "@trackunit/i18n-library-translation": "0.0.68",
11
+ "@trackunit/i18n-library-translation": "0.0.69",
12
12
  "@trackunit/react-components": "0.1.148",
13
13
  "date-fns": "2.29.3",
14
14
  "libphonenumber-js": "1.10.36",
@@ -16,7 +16,7 @@ export interface IOptionCardProps extends InputHTMLAttributes<HTMLInputElement>,
16
16
  /**
17
17
  * Descriptive text displayed inside the OptionCard.
18
18
  */
19
- description?: string;
19
+ description?: string | JSX.Element;
20
20
  }
21
21
  /**
22
22
  * A card version of a radio button that includes an icon, headings and a description.
@@ -1,5 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { CommonProps } from "@trackunit/react-components";
2
+ import { FocusEventHandler } from "react";
3
3
  import { SingleValue } from "react-select";
4
4
  import { CountryCode } from "./CountryCodes";
5
5
  interface CountryCodeSelectProps extends CommonProps {
@@ -13,6 +13,7 @@ interface CountryCodeSelectProps extends CommonProps {
13
13
  disabled?: boolean;
14
14
  readOnly?: boolean;
15
15
  placeholder?: string;
16
+ onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
16
17
  }
17
18
  /**
18
19
  * The CountryCodeSelect component is used to select a country code for a phone number.
@@ -20,5 +21,5 @@ interface CountryCodeSelectProps extends CommonProps {
20
21
  * @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
21
22
  * @returns {JSX.Element} CountryCodeSelect component
22
23
  */
23
- export declare const CountryCodeSelect: ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, }: CountryCodeSelectProps) => JSX.Element;
24
+ export declare const CountryCodeSelect: ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, onBlur, }: CountryCodeSelectProps) => JSX.Element;
24
25
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import { FocusEventHandler } from "react";
2
2
  import { BaseInputProps } from "../BaseInput";
3
3
  type BaseInputExposedProps = Omit<BaseInputProps, "actions">;
4
4
  export interface PhoneNumberProps {
@@ -19,6 +19,14 @@ export interface PhoneInputProps extends BaseInputExposedProps {
19
19
  * A callback function that gives you the country code and phone number as separate values.
20
20
  */
21
21
  onChangeGetSeparateValues?: (params: PhoneNumberProps) => void;
22
+ /**
23
+ * On blur handler for country code component.
24
+ */
25
+ onBlurCountryCode?: FocusEventHandler<HTMLInputElement> | undefined;
26
+ /**
27
+ * A placeholder value for country code.
28
+ */
29
+ countryCodePlaceholder?: string;
22
30
  }
23
31
  /**
24
32
  * A component for inputting phone numbers with an optional action button for initiating a phone call.