@trackunit/react-form-components 0.0.230 → 0.0.232
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 +50 -40
- package/index.esm.js +51 -41
- package/package.json +1 -1
- package/src/translation.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -44,7 +44,14 @@ var ReactCreatableSelect__default = /*#__PURE__*/_interopDefaultLegacy(ReactCrea
|
|
|
44
44
|
var ReactAsyncSelect__default = /*#__PURE__*/_interopDefaultLegacy(ReactAsyncSelect);
|
|
45
45
|
|
|
46
46
|
var defaultTranslations = {
|
|
47
|
-
"phoneField.error": "
|
|
47
|
+
"phoneField.error.INVALID_COUNTRY": "Country code is invalid",
|
|
48
|
+
"phoneField.error.INVALID_LENGTH": "Phone number is invalid",
|
|
49
|
+
"phoneField.error.NOT_A_NUMBER": "Phone number must be a number",
|
|
50
|
+
"phoneField.error.REQUIRED": "Phone number is required",
|
|
51
|
+
"phoneField.error.REQUIRED_COUNTRY": "Country code is required",
|
|
52
|
+
"phoneField.error.TOO_LONG": "Phone number is too long",
|
|
53
|
+
"phoneField.error.TOO_SHORT": "Phone number is too short",
|
|
54
|
+
"phoneField.error.undefined": "Phone number is valid"
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
/** The translation namespace for this library */
|
|
@@ -1499,45 +1506,6 @@ const PhoneInput = React.forwardRef((_a, ref) => {
|
|
|
1499
1506
|
}, actions: !disableAction && (jsxRuntime.jsx(ActionButton, { disabled: disabled || isInvalid, value: phoneNumber, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
|
|
1500
1507
|
});
|
|
1501
1508
|
|
|
1502
|
-
/**
|
|
1503
|
-
* The PhoneField component is used to enter phone number.
|
|
1504
|
-
* It is a wrapper around the PhoneInput component and the FormGroup component.
|
|
1505
|
-
* It is used to render a phone number field with a label, a tip, a help text, a help addon and an error message.
|
|
1506
|
-
*
|
|
1507
|
-
* @param {string} [label] - The label for the component.
|
|
1508
|
-
* @param {string} [tip] - The tip for the component.
|
|
1509
|
-
* @param {string} [helpText] - The help text for the component.
|
|
1510
|
-
* @param {string} [helpAddon] - The help addon for the component.
|
|
1511
|
-
* @param {string} [errorMessage] - The error message for the component.
|
|
1512
|
-
* @param {string} [defaultValue] - The default value for the component.
|
|
1513
|
-
* @param {boolean} [disabled=false] - Whether the component is disabled or not.
|
|
1514
|
-
* @param {string} [fieldSize="medium"] - The size of the input field.
|
|
1515
|
-
* @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
|
|
1516
|
-
* @returns {JSX.Element} - The PhoneField component.
|
|
1517
|
-
*/
|
|
1518
|
-
const PhoneField = React.forwardRef((_a, ref) => {
|
|
1519
|
-
var { label, id, tip, helpText, isInvalid, errorMessage, value, helpAddon, className, defaultValue, dataTestId, onChangeValue, onFieldsBlur } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "isInvalid", "errorMessage", "value", "helpAddon", "className", "defaultValue", "dataTestId", "onChangeValue", "onFieldsBlur"]);
|
|
1520
|
-
const htmlForId = id ? id : "phoneField-" + uuid.v4();
|
|
1521
|
-
const [t] = useTranslation();
|
|
1522
|
-
const [isValid, setIsValid] = React.useState(true);
|
|
1523
|
-
const renderAsInvalid = !isValid || isInvalid || Boolean(errorMessage);
|
|
1524
|
-
const onChangeValueHandler = ({ phone, national, countryCode }) => {
|
|
1525
|
-
if (!isValid && countryCode) {
|
|
1526
|
-
const countryAbbreviation = getCountryAbbreviation(countryCode);
|
|
1527
|
-
setIsValid(phone && national && countryAbbreviation ? parsePhoneNumberFromString.isValidPhoneNumber(phone, countryAbbreviation) : true);
|
|
1528
|
-
}
|
|
1529
|
-
onChangeValue && onChangeValue({ phone, national, countryCode, isValid });
|
|
1530
|
-
};
|
|
1531
|
-
const handleOnFieldBlur = ({ phone, national, countryCode }) => {
|
|
1532
|
-
if (countryCode) {
|
|
1533
|
-
const countryAbbreviation = getCountryAbbreviation(countryCode);
|
|
1534
|
-
setIsValid(phone && national && countryAbbreviation ? parsePhoneNumberFromString.isValidPhoneNumber(phone, countryAbbreviation) : true);
|
|
1535
|
-
}
|
|
1536
|
-
onFieldsBlur && onFieldsBlur({ phone, national, countryCode, isValid });
|
|
1537
|
-
};
|
|
1538
|
-
return (jsxRuntime.jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && (errorMessage || t("phoneField.error"))) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsxRuntime.jsx(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: value, defaultValue: defaultValue, ref: ref, isInvalid: renderAsInvalid, dataTestId: dataTestId, onChangeValue: onChangeValueHandler, onFieldsBlur: handleOnFieldBlur }, rest)) }));
|
|
1539
|
-
});
|
|
1540
|
-
|
|
1541
1509
|
/**
|
|
1542
1510
|
* Validates a phone number
|
|
1543
1511
|
*/
|
|
@@ -1576,6 +1544,48 @@ const isInvalidCountryCode = (error, required) => (!!required && error === "REQU
|
|
|
1576
1544
|
*/
|
|
1577
1545
|
const isInvalidPhoneNumber = (error, required) => error !== "REQUIRED_COUNTRY" && ((!!error && error !== "REQUIRED") || (!!required && error === "REQUIRED"));
|
|
1578
1546
|
|
|
1547
|
+
/**
|
|
1548
|
+
* The PhoneField component is used to enter phone number.
|
|
1549
|
+
* It is a wrapper around the PhoneInput component and the FormGroup component.
|
|
1550
|
+
* It is used to render a phone number field with a label, a tip, a help text, a help addon and an error message.
|
|
1551
|
+
*
|
|
1552
|
+
* @param {string} [label] - The label for the component.
|
|
1553
|
+
* @param {string} [tip] - The tip for the component.
|
|
1554
|
+
* @param {string} [helpText] - The help text for the component.
|
|
1555
|
+
* @param {string} [helpAddon] - The help addon for the component.
|
|
1556
|
+
* @param {string} [errorMessage] - The error message for the component.
|
|
1557
|
+
* @param {string} [defaultValue] - The default value for the component.
|
|
1558
|
+
* @param {boolean} [disabled=false] - Whether the component is disabled or not.
|
|
1559
|
+
* @param {string} [fieldSize="medium"] - The size of the input field.
|
|
1560
|
+
* @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
|
|
1561
|
+
* @returns {JSX.Element} - The PhoneField component.
|
|
1562
|
+
*/
|
|
1563
|
+
const PhoneField = React.forwardRef((_a, ref) => {
|
|
1564
|
+
var { label, id, tip, helpText, isInvalid, errorMessage, value, helpAddon, className, defaultValue, dataTestId, onChangeValue, onFieldsBlur } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "isInvalid", "errorMessage", "value", "helpAddon", "className", "defaultValue", "dataTestId", "onChangeValue", "onFieldsBlur"]);
|
|
1565
|
+
const htmlForId = id ? id : "phoneField-" + uuid.v4();
|
|
1566
|
+
const [t] = useTranslation();
|
|
1567
|
+
const [isValid, setIsValid] = React.useState(true);
|
|
1568
|
+
const [localError, setLocalError] = React.useState(undefined);
|
|
1569
|
+
const renderAsInvalid = !isValid || isInvalid || Boolean(errorMessage);
|
|
1570
|
+
const validate = ({ phone, national, countryCode }) => {
|
|
1571
|
+
const areFieldsPopulated = Boolean(national && countryCode);
|
|
1572
|
+
const phoneValidationResult = validatePhoneNumber({ phone, national, countryCode });
|
|
1573
|
+
setIsValid(areFieldsPopulated ? !Boolean(phoneValidationResult) : true);
|
|
1574
|
+
setLocalError(Boolean(phoneValidationResult) ? t(`phoneField.error.${phoneValidationResult}`) : undefined);
|
|
1575
|
+
};
|
|
1576
|
+
const onChangeValueHandler = (phoneNumberValue) => {
|
|
1577
|
+
if (!isValid) {
|
|
1578
|
+
validate(phoneNumberValue);
|
|
1579
|
+
}
|
|
1580
|
+
onChangeValue && onChangeValue(Object.assign(Object.assign({}, phoneNumberValue), { isValid }));
|
|
1581
|
+
};
|
|
1582
|
+
const handleOnFieldBlur = (phoneNumberValue) => {
|
|
1583
|
+
validate(phoneNumberValue);
|
|
1584
|
+
onFieldsBlur && onFieldsBlur(Object.assign(Object.assign({}, phoneNumberValue), { isValid }));
|
|
1585
|
+
};
|
|
1586
|
+
return (jsxRuntime.jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && (errorMessage || localError)) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsxRuntime.jsx(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: value, defaultValue: defaultValue, ref: ref, isInvalid: renderAsInvalid, dataTestId: dataTestId, onChangeValue: onChangeValueHandler, onFieldsBlur: handleOnFieldBlur }, rest)) }));
|
|
1587
|
+
});
|
|
1588
|
+
|
|
1579
1589
|
const cvaRadioGroup = cssClassVarianceUtilities.cvaMerge(["flex", "gap-2", "flex-col", "items-start"], {
|
|
1580
1590
|
variants: {
|
|
1581
1591
|
layout: {
|
package/index.esm.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
import React__default, { useMemo, forwardRef, useState, cloneElement, useEffect, useRef } from 'react';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import { format } from 'date-fns';
|
|
9
|
-
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode,
|
|
9
|
+
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode, parsePhoneNumberFromString as parsePhoneNumberFromString$1, isValidPhoneNumber, validatePhoneNumberLength } from 'libphonenumber-js';
|
|
10
10
|
import ReactSelect, { components } from 'react-select';
|
|
11
11
|
export { default as ValueType } from 'react-select';
|
|
12
12
|
import ReactAsyncCreatableSelect from 'react-select/async-creatable';
|
|
@@ -14,7 +14,14 @@ import ReactCreatableSelect from 'react-select/creatable';
|
|
|
14
14
|
import ReactAsyncSelect from 'react-select/async';
|
|
15
15
|
|
|
16
16
|
var defaultTranslations = {
|
|
17
|
-
"phoneField.error": "
|
|
17
|
+
"phoneField.error.INVALID_COUNTRY": "Country code is invalid",
|
|
18
|
+
"phoneField.error.INVALID_LENGTH": "Phone number is invalid",
|
|
19
|
+
"phoneField.error.NOT_A_NUMBER": "Phone number must be a number",
|
|
20
|
+
"phoneField.error.REQUIRED": "Phone number is required",
|
|
21
|
+
"phoneField.error.REQUIRED_COUNTRY": "Country code is required",
|
|
22
|
+
"phoneField.error.TOO_LONG": "Phone number is too long",
|
|
23
|
+
"phoneField.error.TOO_SHORT": "Phone number is too short",
|
|
24
|
+
"phoneField.error.undefined": "Phone number is valid"
|
|
18
25
|
};
|
|
19
26
|
|
|
20
27
|
/** The translation namespace for this library */
|
|
@@ -1469,45 +1476,6 @@ const PhoneInput = forwardRef((_a, ref) => {
|
|
|
1469
1476
|
}, actions: !disableAction && (jsx(ActionButton, { disabled: disabled || isInvalid, value: phoneNumber, type: "PHONE_NUMBER", dataTestId: dataTestId && `${dataTestId}-phoneIcon`, iconSize: fieldSize })) }, rest))] }));
|
|
1470
1477
|
});
|
|
1471
1478
|
|
|
1472
|
-
/**
|
|
1473
|
-
* The PhoneField component is used to enter phone number.
|
|
1474
|
-
* It is a wrapper around the PhoneInput component and the FormGroup component.
|
|
1475
|
-
* It is used to render a phone number field with a label, a tip, a help text, a help addon and an error message.
|
|
1476
|
-
*
|
|
1477
|
-
* @param {string} [label] - The label for the component.
|
|
1478
|
-
* @param {string} [tip] - The tip for the component.
|
|
1479
|
-
* @param {string} [helpText] - The help text for the component.
|
|
1480
|
-
* @param {string} [helpAddon] - The help addon for the component.
|
|
1481
|
-
* @param {string} [errorMessage] - The error message for the component.
|
|
1482
|
-
* @param {string} [defaultValue] - The default value for the component.
|
|
1483
|
-
* @param {boolean} [disabled=false] - Whether the component is disabled or not.
|
|
1484
|
-
* @param {string} [fieldSize="medium"] - The size of the input field.
|
|
1485
|
-
* @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
|
|
1486
|
-
* @returns {JSX.Element} - The PhoneField component.
|
|
1487
|
-
*/
|
|
1488
|
-
const PhoneField = forwardRef((_a, ref) => {
|
|
1489
|
-
var { label, id, tip, helpText, isInvalid, errorMessage, value, helpAddon, className, defaultValue, dataTestId, onChangeValue, onFieldsBlur } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "isInvalid", "errorMessage", "value", "helpAddon", "className", "defaultValue", "dataTestId", "onChangeValue", "onFieldsBlur"]);
|
|
1490
|
-
const htmlForId = id ? id : "phoneField-" + v4();
|
|
1491
|
-
const [t] = useTranslation();
|
|
1492
|
-
const [isValid, setIsValid] = useState(true);
|
|
1493
|
-
const renderAsInvalid = !isValid || isInvalid || Boolean(errorMessage);
|
|
1494
|
-
const onChangeValueHandler = ({ phone, national, countryCode }) => {
|
|
1495
|
-
if (!isValid && countryCode) {
|
|
1496
|
-
const countryAbbreviation = getCountryAbbreviation(countryCode);
|
|
1497
|
-
setIsValid(phone && national && countryAbbreviation ? isValidPhoneNumber(phone, countryAbbreviation) : true);
|
|
1498
|
-
}
|
|
1499
|
-
onChangeValue && onChangeValue({ phone, national, countryCode, isValid });
|
|
1500
|
-
};
|
|
1501
|
-
const handleOnFieldBlur = ({ phone, national, countryCode }) => {
|
|
1502
|
-
if (countryCode) {
|
|
1503
|
-
const countryAbbreviation = getCountryAbbreviation(countryCode);
|
|
1504
|
-
setIsValid(phone && national && countryAbbreviation ? isValidPhoneNumber(phone, countryAbbreviation) : true);
|
|
1505
|
-
}
|
|
1506
|
-
onFieldsBlur && onFieldsBlur({ phone, national, countryCode, isValid });
|
|
1507
|
-
};
|
|
1508
|
-
return (jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && (errorMessage || t("phoneField.error"))) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsx(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: value, defaultValue: defaultValue, ref: ref, isInvalid: renderAsInvalid, dataTestId: dataTestId, onChangeValue: onChangeValueHandler, onFieldsBlur: handleOnFieldBlur }, rest)) }));
|
|
1509
|
-
});
|
|
1510
|
-
|
|
1511
1479
|
/**
|
|
1512
1480
|
* Validates a phone number
|
|
1513
1481
|
*/
|
|
@@ -1546,6 +1514,48 @@ const isInvalidCountryCode = (error, required) => (!!required && error === "REQU
|
|
|
1546
1514
|
*/
|
|
1547
1515
|
const isInvalidPhoneNumber = (error, required) => error !== "REQUIRED_COUNTRY" && ((!!error && error !== "REQUIRED") || (!!required && error === "REQUIRED"));
|
|
1548
1516
|
|
|
1517
|
+
/**
|
|
1518
|
+
* The PhoneField component is used to enter phone number.
|
|
1519
|
+
* It is a wrapper around the PhoneInput component and the FormGroup component.
|
|
1520
|
+
* It is used to render a phone number field with a label, a tip, a help text, a help addon and an error message.
|
|
1521
|
+
*
|
|
1522
|
+
* @param {string} [label] - The label for the component.
|
|
1523
|
+
* @param {string} [tip] - The tip for the component.
|
|
1524
|
+
* @param {string} [helpText] - The help text for the component.
|
|
1525
|
+
* @param {string} [helpAddon] - The help addon for the component.
|
|
1526
|
+
* @param {string} [errorMessage] - The error message for the component.
|
|
1527
|
+
* @param {string} [defaultValue] - The default value for the component.
|
|
1528
|
+
* @param {boolean} [disabled=false] - Whether the component is disabled or not.
|
|
1529
|
+
* @param {string} [fieldSize="medium"] - The size of the input field.
|
|
1530
|
+
* @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
|
|
1531
|
+
* @returns {JSX.Element} - The PhoneField component.
|
|
1532
|
+
*/
|
|
1533
|
+
const PhoneField = forwardRef((_a, ref) => {
|
|
1534
|
+
var { label, id, tip, helpText, isInvalid, errorMessage, value, helpAddon, className, defaultValue, dataTestId, onChangeValue, onFieldsBlur } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "isInvalid", "errorMessage", "value", "helpAddon", "className", "defaultValue", "dataTestId", "onChangeValue", "onFieldsBlur"]);
|
|
1535
|
+
const htmlForId = id ? id : "phoneField-" + v4();
|
|
1536
|
+
const [t] = useTranslation();
|
|
1537
|
+
const [isValid, setIsValid] = useState(true);
|
|
1538
|
+
const [localError, setLocalError] = useState(undefined);
|
|
1539
|
+
const renderAsInvalid = !isValid || isInvalid || Boolean(errorMessage);
|
|
1540
|
+
const validate = ({ phone, national, countryCode }) => {
|
|
1541
|
+
const areFieldsPopulated = Boolean(national && countryCode);
|
|
1542
|
+
const phoneValidationResult = validatePhoneNumber({ phone, national, countryCode });
|
|
1543
|
+
setIsValid(areFieldsPopulated ? !Boolean(phoneValidationResult) : true);
|
|
1544
|
+
setLocalError(Boolean(phoneValidationResult) ? t(`phoneField.error.${phoneValidationResult}`) : undefined);
|
|
1545
|
+
};
|
|
1546
|
+
const onChangeValueHandler = (phoneNumberValue) => {
|
|
1547
|
+
if (!isValid) {
|
|
1548
|
+
validate(phoneNumberValue);
|
|
1549
|
+
}
|
|
1550
|
+
onChangeValue && onChangeValue(Object.assign(Object.assign({}, phoneNumberValue), { isValid }));
|
|
1551
|
+
};
|
|
1552
|
+
const handleOnFieldBlur = (phoneNumberValue) => {
|
|
1553
|
+
validate(phoneNumberValue);
|
|
1554
|
+
onFieldsBlur && onFieldsBlur(Object.assign(Object.assign({}, phoneNumberValue), { isValid }));
|
|
1555
|
+
};
|
|
1556
|
+
return (jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && (errorMessage || localError)) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsx(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: value, defaultValue: defaultValue, ref: ref, isInvalid: renderAsInvalid, dataTestId: dataTestId, onChangeValue: onChangeValueHandler, onFieldsBlur: handleOnFieldBlur }, rest)) }));
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1549
1559
|
const cvaRadioGroup = cvaMerge(["flex", "gap-2", "flex-col", "items-start"], {
|
|
1550
1560
|
variants: {
|
|
1551
1561
|
layout: {
|
package/package.json
CHANGED
package/src/translation.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
|
|
|
15
15
|
/**
|
|
16
16
|
* Local useTranslation for this specific library
|
|
17
17
|
*/
|
|
18
|
-
export declare const useTranslation: () => [TransForLibs<"phoneField.error">, import("i18next").i18n, boolean] & {
|
|
19
|
-
t: TransForLibs<"phoneField.error">;
|
|
18
|
+
export declare const useTranslation: () => [TransForLibs<"phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined">, import("i18next").i18n, boolean] & {
|
|
19
|
+
t: TransForLibs<"phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined">;
|
|
20
20
|
i18n: import("i18next").i18n;
|
|
21
21
|
ready: boolean;
|
|
22
22
|
};
|