@trackunit/react-form-components 0.0.258 → 0.0.261
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 +8 -9
- package/index.esm.js +9 -10
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.d.ts +4 -0
- package/src/components/PhoneInput/PhoneInputValidationUtils.d.ts +1 -1
- package/src/translation.d.ts +2 -2
- package/translation.cjs7.js +7 -7
- package/translation.esm7.js +7 -7
package/index.cjs.js
CHANGED
|
@@ -46,6 +46,7 @@ var ReactAsyncSelect__default = /*#__PURE__*/_interopDefaultLegacy(ReactAsyncSel
|
|
|
46
46
|
var defaultTranslations = {
|
|
47
47
|
"phoneField.error.INVALID_COUNTRY": "The country code is not valid",
|
|
48
48
|
"phoneField.error.INVALID_LENGTH": "The phone number is not valid",
|
|
49
|
+
"phoneField.error.INVALID_NUMBER": "The phone number is not valid",
|
|
49
50
|
"phoneField.error.NOT_A_NUMBER": "The phone number can contain numbers only",
|
|
50
51
|
"phoneField.error.REQUIRED": "The phone number is required",
|
|
51
52
|
"phoneField.error.REQUIRED_COUNTRY": "The country code is required",
|
|
@@ -477,7 +478,7 @@ const IndeterminateIcon = ({ className }) => (jsxRuntime.jsx("svg", { xmlns: "ht
|
|
|
477
478
|
* @returns {JSX.Element} Checkbox component
|
|
478
479
|
*/
|
|
479
480
|
const Checkbox = React__namespace.forwardRef((_a, ref) => {
|
|
480
|
-
var { className, dataTestId = "checkbox", onChange, checked = false, disabled = false, isInvalid = false, readOnly, indeterminate = false, suffix, label, tabIndex = 0, onLabelRefChange } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "checked", "disabled", "isInvalid", "readOnly", "indeterminate", "suffix", "label", "tabIndex", "onLabelRefChange"]);
|
|
481
|
+
var { className, dataTestId = "checkbox", onChange, checked = false, disabled = false, isInvalid = false, readOnly, indeterminate = false, suffix, label, tabIndex = 0, onLabelRefChange, stopPropagation } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "checked", "disabled", "isInvalid", "readOnly", "indeterminate", "suffix", "label", "tabIndex", "onLabelRefChange", "stopPropagation"]);
|
|
481
482
|
const icon = indeterminate ? (jsxRuntime.jsx(IndeterminateIcon, { className: cvaCheckboxIcon() })) : (checked && jsxRuntime.jsx(CheckIcon, { className: cvaCheckboxIcon() }));
|
|
482
483
|
const internalRef = React__namespace.useRef(null);
|
|
483
484
|
const isReadonly = disabled || readOnly;
|
|
@@ -496,7 +497,7 @@ const Checkbox = React__namespace.forwardRef((_a, ref) => {
|
|
|
496
497
|
onLabelRefChange && labelRef && onLabelRefChange(labelRef);
|
|
497
498
|
}, [labelRef, onLabelRefChange]);
|
|
498
499
|
const uuid = rest.id;
|
|
499
|
-
return (jsxRuntime.jsxs("label", { "data-testid": dataTestId && `${dataTestId}-container`, htmlFor: uuid, className: cvaCheckboxContainer({ className }), ref: internalRef, onKeyDown: onKeyPress, children: [jsxRuntime.jsx("input", Object.assign({ type: "checkbox", className: cvaCheckboxInput(), checked: !indeterminate && checked, onChange: onChange, disabled: disabled, "data-testid": dataTestId, readOnly: readOnly, "aria-checked": !indeterminate && checked, id: uuid }, rest, { ref: ref })), jsxRuntime.jsx("span", { id: uuid, tabIndex: isReadonly ? -1 : tabIndex, className: cvaCheckbox({
|
|
500
|
+
return (jsxRuntime.jsxs("label", { "data-testid": dataTestId && `${dataTestId}-container`, htmlFor: uuid, className: cvaCheckboxContainer({ className }), ref: internalRef, onKeyDown: onKeyPress, onClick: e => stopPropagation && e.stopPropagation(), children: [jsxRuntime.jsx("input", Object.assign({ type: "checkbox", className: cvaCheckboxInput(), checked: !indeterminate && checked, onChange: onChange, disabled: disabled, "data-testid": dataTestId, readOnly: readOnly, "aria-checked": !indeterminate && checked, id: uuid }, rest, { ref: ref })), jsxRuntime.jsx("span", { id: uuid, tabIndex: isReadonly ? -1 : tabIndex, className: cvaCheckbox({
|
|
500
501
|
disabled: isReadonly,
|
|
501
502
|
invalid: isReadonly ? false : isInvalid,
|
|
502
503
|
state: indeterminate ? "indeterminate" : checked ? "selected" : "deselected",
|
|
@@ -1511,6 +1512,9 @@ const PhoneInput = React.forwardRef((_a, ref) => {
|
|
|
1511
1512
|
*/
|
|
1512
1513
|
const validatePhoneNumber = ({ phone, countryCode, national, }) => {
|
|
1513
1514
|
const phoneNumber = phone ? phone : countryCode || national ? `${countryCode}${national}` : undefined;
|
|
1515
|
+
if (phoneNumber && parsePhoneNumberFromString.isValidPhoneNumber(phoneNumber)) {
|
|
1516
|
+
return undefined;
|
|
1517
|
+
}
|
|
1514
1518
|
if (!phoneNumber) {
|
|
1515
1519
|
return "REQUIRED";
|
|
1516
1520
|
}
|
|
@@ -1530,10 +1534,7 @@ const validatePhoneNumber = ({ phone, countryCode, national, }) => {
|
|
|
1530
1534
|
if (!number) {
|
|
1531
1535
|
return "NOT_A_NUMBER";
|
|
1532
1536
|
}
|
|
1533
|
-
|
|
1534
|
-
return parsePhoneNumberFromString.validatePhoneNumberLength(number.number, number.country);
|
|
1535
|
-
}
|
|
1536
|
-
return undefined;
|
|
1537
|
+
return "INVALID_NUMBER";
|
|
1537
1538
|
};
|
|
1538
1539
|
/**
|
|
1539
1540
|
* Checks if the country code is valid and required
|
|
@@ -1574,9 +1575,7 @@ const PhoneField = React.forwardRef((_a, ref) => {
|
|
|
1574
1575
|
setLocalError(Boolean(phoneValidationResult) ? t(`phoneField.error.${phoneValidationResult}`) : undefined);
|
|
1575
1576
|
};
|
|
1576
1577
|
const onChangeValueHandler = (phoneNumberValue) => {
|
|
1577
|
-
|
|
1578
|
-
validate(phoneNumberValue);
|
|
1579
|
-
}
|
|
1578
|
+
validate(phoneNumberValue);
|
|
1580
1579
|
onChangeValue && onChangeValue(Object.assign(Object.assign({}, phoneNumberValue), { isValid }));
|
|
1581
1580
|
};
|
|
1582
1581
|
const handleOnFieldBlur = (phoneNumberValue) => {
|
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, parsePhoneNumberFromString as parsePhoneNumberFromString$1
|
|
9
|
+
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode, isValidPhoneNumber, parsePhoneNumberFromString as parsePhoneNumberFromString$1 } 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';
|
|
@@ -16,6 +16,7 @@ import ReactAsyncSelect from 'react-select/async';
|
|
|
16
16
|
var defaultTranslations = {
|
|
17
17
|
"phoneField.error.INVALID_COUNTRY": "The country code is not valid",
|
|
18
18
|
"phoneField.error.INVALID_LENGTH": "The phone number is not valid",
|
|
19
|
+
"phoneField.error.INVALID_NUMBER": "The phone number is not valid",
|
|
19
20
|
"phoneField.error.NOT_A_NUMBER": "The phone number can contain numbers only",
|
|
20
21
|
"phoneField.error.REQUIRED": "The phone number is required",
|
|
21
22
|
"phoneField.error.REQUIRED_COUNTRY": "The country code is required",
|
|
@@ -447,7 +448,7 @@ const IndeterminateIcon = ({ className }) => (jsx("svg", { xmlns: "http://www.w3
|
|
|
447
448
|
* @returns {JSX.Element} Checkbox component
|
|
448
449
|
*/
|
|
449
450
|
const Checkbox = React.forwardRef((_a, ref) => {
|
|
450
|
-
var { className, dataTestId = "checkbox", onChange, checked = false, disabled = false, isInvalid = false, readOnly, indeterminate = false, suffix, label, tabIndex = 0, onLabelRefChange } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "checked", "disabled", "isInvalid", "readOnly", "indeterminate", "suffix", "label", "tabIndex", "onLabelRefChange"]);
|
|
451
|
+
var { className, dataTestId = "checkbox", onChange, checked = false, disabled = false, isInvalid = false, readOnly, indeterminate = false, suffix, label, tabIndex = 0, onLabelRefChange, stopPropagation } = _a, rest = __rest(_a, ["className", "dataTestId", "onChange", "checked", "disabled", "isInvalid", "readOnly", "indeterminate", "suffix", "label", "tabIndex", "onLabelRefChange", "stopPropagation"]);
|
|
451
452
|
const icon = indeterminate ? (jsx(IndeterminateIcon, { className: cvaCheckboxIcon() })) : (checked && jsx(CheckIcon, { className: cvaCheckboxIcon() }));
|
|
452
453
|
const internalRef = React.useRef(null);
|
|
453
454
|
const isReadonly = disabled || readOnly;
|
|
@@ -466,7 +467,7 @@ const Checkbox = React.forwardRef((_a, ref) => {
|
|
|
466
467
|
onLabelRefChange && labelRef && onLabelRefChange(labelRef);
|
|
467
468
|
}, [labelRef, onLabelRefChange]);
|
|
468
469
|
const uuid = rest.id;
|
|
469
|
-
return (jsxs("label", { "data-testid": dataTestId && `${dataTestId}-container`, htmlFor: uuid, className: cvaCheckboxContainer({ className }), ref: internalRef, onKeyDown: onKeyPress, children: [jsx("input", Object.assign({ type: "checkbox", className: cvaCheckboxInput(), checked: !indeterminate && checked, onChange: onChange, disabled: disabled, "data-testid": dataTestId, readOnly: readOnly, "aria-checked": !indeterminate && checked, id: uuid }, rest, { ref: ref })), jsx("span", { id: uuid, tabIndex: isReadonly ? -1 : tabIndex, className: cvaCheckbox({
|
|
470
|
+
return (jsxs("label", { "data-testid": dataTestId && `${dataTestId}-container`, htmlFor: uuid, className: cvaCheckboxContainer({ className }), ref: internalRef, onKeyDown: onKeyPress, onClick: e => stopPropagation && e.stopPropagation(), children: [jsx("input", Object.assign({ type: "checkbox", className: cvaCheckboxInput(), checked: !indeterminate && checked, onChange: onChange, disabled: disabled, "data-testid": dataTestId, readOnly: readOnly, "aria-checked": !indeterminate && checked, id: uuid }, rest, { ref: ref })), jsx("span", { id: uuid, tabIndex: isReadonly ? -1 : tabIndex, className: cvaCheckbox({
|
|
470
471
|
disabled: isReadonly,
|
|
471
472
|
invalid: isReadonly ? false : isInvalid,
|
|
472
473
|
state: indeterminate ? "indeterminate" : checked ? "selected" : "deselected",
|
|
@@ -1481,6 +1482,9 @@ const PhoneInput = forwardRef((_a, ref) => {
|
|
|
1481
1482
|
*/
|
|
1482
1483
|
const validatePhoneNumber = ({ phone, countryCode, national, }) => {
|
|
1483
1484
|
const phoneNumber = phone ? phone : countryCode || national ? `${countryCode}${national}` : undefined;
|
|
1485
|
+
if (phoneNumber && isValidPhoneNumber(phoneNumber)) {
|
|
1486
|
+
return undefined;
|
|
1487
|
+
}
|
|
1484
1488
|
if (!phoneNumber) {
|
|
1485
1489
|
return "REQUIRED";
|
|
1486
1490
|
}
|
|
@@ -1500,10 +1504,7 @@ const validatePhoneNumber = ({ phone, countryCode, national, }) => {
|
|
|
1500
1504
|
if (!number) {
|
|
1501
1505
|
return "NOT_A_NUMBER";
|
|
1502
1506
|
}
|
|
1503
|
-
|
|
1504
|
-
return validatePhoneNumberLength(number.number, number.country);
|
|
1505
|
-
}
|
|
1506
|
-
return undefined;
|
|
1507
|
+
return "INVALID_NUMBER";
|
|
1507
1508
|
};
|
|
1508
1509
|
/**
|
|
1509
1510
|
* Checks if the country code is valid and required
|
|
@@ -1544,9 +1545,7 @@ const PhoneField = forwardRef((_a, ref) => {
|
|
|
1544
1545
|
setLocalError(Boolean(phoneValidationResult) ? t(`phoneField.error.${phoneValidationResult}`) : undefined);
|
|
1545
1546
|
};
|
|
1546
1547
|
const onChangeValueHandler = (phoneNumberValue) => {
|
|
1547
|
-
|
|
1548
|
-
validate(phoneNumberValue);
|
|
1549
|
-
}
|
|
1548
|
+
validate(phoneNumberValue);
|
|
1550
1549
|
onChangeValue && onChangeValue(Object.assign(Object.assign({}, phoneNumberValue), { isValid }));
|
|
1551
1550
|
};
|
|
1552
1551
|
const handleOnFieldBlur = (phoneNumberValue) => {
|
package/package.json
CHANGED
|
@@ -34,6 +34,10 @@ export interface CheckboxProps extends CommonProps, React.InputHTMLAttributes<HT
|
|
|
34
34
|
* A function returning the label ref
|
|
35
35
|
*/
|
|
36
36
|
onLabelRefChange?: (label: HTMLElement) => void;
|
|
37
|
+
/**
|
|
38
|
+
* An boolean flag to stop propagation of the click event
|
|
39
|
+
*/
|
|
40
|
+
stopPropagation?: boolean;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Checkboxes are used when there are multiple items to select in a list. Users can select zero, one, or any number of items.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidatePhoneNumberLengthResult } from "libphonenumber-js";
|
|
2
|
-
export type PhoneInputValidationError = "REQUIRED" | "REQUIRED_COUNTRY" | ValidatePhoneNumberLengthResult | undefined;
|
|
2
|
+
export type PhoneInputValidationError = "REQUIRED" | "REQUIRED_COUNTRY" | "INVALID_NUMBER" | ValidatePhoneNumberLengthResult | undefined;
|
|
3
3
|
export interface PhoneNumberValueForValidation {
|
|
4
4
|
phone?: string | undefined | null;
|
|
5
5
|
national?: string | undefined | null;
|
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.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">;
|
|
18
|
+
export declare const useTranslation: () => [TransForLibs<"phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "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.INVALID_NUMBER" | "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
|
};
|
package/translation.cjs7.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var translation = {
|
|
4
|
-
"phoneField.error.INVALID_COUNTRY": "
|
|
5
|
-
"phoneField.error.INVALID_LENGTH": "
|
|
6
|
-
"phoneField.error.NOT_A_NUMBER": "
|
|
7
|
-
"phoneField.error.REQUIRED": "
|
|
8
|
-
"phoneField.error.REQUIRED_COUNTRY": "
|
|
9
|
-
"phoneField.error.TOO_LONG": "
|
|
10
|
-
"phoneField.error.TOO_SHORT": "
|
|
4
|
+
"phoneField.error.INVALID_COUNTRY": "Az országkód érvénytelen",
|
|
5
|
+
"phoneField.error.INVALID_LENGTH": "A telefonszám érvénytelen",
|
|
6
|
+
"phoneField.error.NOT_A_NUMBER": "A telefonszám csak számokat tartalmazhat",
|
|
7
|
+
"phoneField.error.REQUIRED": "A telefonszám megadása kötelező",
|
|
8
|
+
"phoneField.error.REQUIRED_COUNTRY": "Az országkód megadása kötelező",
|
|
9
|
+
"phoneField.error.TOO_LONG": "A telefonszám túl hosszú",
|
|
10
|
+
"phoneField.error.TOO_SHORT": "A telefonszám túl rövid",
|
|
11
11
|
"phoneField.error.undefined": ""
|
|
12
12
|
};
|
|
13
13
|
|
package/translation.esm7.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var translation = {
|
|
2
|
-
"phoneField.error.INVALID_COUNTRY": "
|
|
3
|
-
"phoneField.error.INVALID_LENGTH": "
|
|
4
|
-
"phoneField.error.NOT_A_NUMBER": "
|
|
5
|
-
"phoneField.error.REQUIRED": "
|
|
6
|
-
"phoneField.error.REQUIRED_COUNTRY": "
|
|
7
|
-
"phoneField.error.TOO_LONG": "
|
|
8
|
-
"phoneField.error.TOO_SHORT": "
|
|
2
|
+
"phoneField.error.INVALID_COUNTRY": "Az országkód érvénytelen",
|
|
3
|
+
"phoneField.error.INVALID_LENGTH": "A telefonszám érvénytelen",
|
|
4
|
+
"phoneField.error.NOT_A_NUMBER": "A telefonszám csak számokat tartalmazhat",
|
|
5
|
+
"phoneField.error.REQUIRED": "A telefonszám megadása kötelező",
|
|
6
|
+
"phoneField.error.REQUIRED_COUNTRY": "Az országkód megadása kötelező",
|
|
7
|
+
"phoneField.error.TOO_LONG": "A telefonszám túl hosszú",
|
|
8
|
+
"phoneField.error.TOO_SHORT": "A telefonszám túl rövid",
|
|
9
9
|
"phoneField.error.undefined": ""
|
|
10
10
|
};
|
|
11
11
|
|