@trackunit/react-form-components 0.0.101-alpha-ea50faef71.0 → 0.0.101
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
CHANGED
|
@@ -6063,7 +6063,7 @@ const usePhoneInput = (value) => {
|
|
|
6063
6063
|
const [combinedValue, setCombinedValue] = React.useState(value !== null && value !== void 0 ? value : "");
|
|
6064
6064
|
React.useEffect(() => {
|
|
6065
6065
|
var _a, _b;
|
|
6066
|
-
if (value) {
|
|
6066
|
+
if (value && ((!countryCode && !phoneNumber) || !combinedValue)) {
|
|
6067
6067
|
const safePhoneNumber = getPhoneNumberWithPlus(value);
|
|
6068
6068
|
const number = parsePhoneNumber(safePhoneNumber);
|
|
6069
6069
|
setCountryCode((_a = number === null || number === void 0 ? void 0 : number.countryCallingCode.toString()) !== null && _a !== void 0 ? _a : "");
|
|
@@ -14147,7 +14147,7 @@ var AsyncSelect$1 = AsyncSelect;
|
|
|
14147
14147
|
*/
|
|
14148
14148
|
const Select = (props) => {
|
|
14149
14149
|
const { className } = props, propsNoClassName = __rest(props, ["className"]);
|
|
14150
|
-
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId ? dataTestId : "select", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable, } = props;
|
|
14150
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId ? dataTestId : "select", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable, readOnly, } = props;
|
|
14151
14151
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
14152
14152
|
const selectProps = {
|
|
14153
14153
|
value,
|
|
@@ -14161,11 +14161,11 @@ const Select = (props) => {
|
|
|
14161
14161
|
tabSelectsValue: false,
|
|
14162
14162
|
blurInputOnSelect: !isMulti,
|
|
14163
14163
|
menuPortalTarget: props.menuPortalTarget || document.body,
|
|
14164
|
-
isSearchable: disabled ? false : isSearchable,
|
|
14164
|
+
isSearchable: disabled || readOnly ? false : isSearchable,
|
|
14165
14165
|
menuShouldBlockScroll: true,
|
|
14166
14166
|
menuShouldScrollIntoView: true,
|
|
14167
14167
|
openMenuOnFocus: true,
|
|
14168
|
-
menuIsOpen,
|
|
14168
|
+
menuIsOpen: !readOnly ? menuIsOpen : false,
|
|
14169
14169
|
openMenuOnClick: true,
|
|
14170
14170
|
closeMenuOnSelect: false,
|
|
14171
14171
|
isMulti,
|
|
@@ -14176,12 +14176,13 @@ const Select = (props) => {
|
|
|
14176
14176
|
onMenuScrollToBottom,
|
|
14177
14177
|
onInputChange,
|
|
14178
14178
|
};
|
|
14179
|
-
return (jsxRuntime.jsxs(SelectContainer, { ref: refContainer, className: className, "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": disabled, children: [prefix !== undefined && (jsxRuntime.jsx(SelectPrefix, { "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix, children: prefix })), async ? (jsxRuntime.jsx(AsyncSelect$1, Object.assign({}, propsNoClassName, selectProps, async, { onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler }))) : (jsxRuntime.jsx(StateManagedSelect$1, Object.assign({}, propsNoClassName, selectProps, { options: filterOption ? orderedOptions : options, isMulti: isMulti, hideSelectedOptions: false, onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler })))] }));
|
|
14179
|
+
return (jsxRuntime.jsxs(SelectContainer, { ref: refContainer, className: className, "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": disabled, "$isReadOnly": readOnly, children: [prefix !== undefined && (jsxRuntime.jsx(SelectPrefix, { "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix, children: prefix })), async ? (jsxRuntime.jsx(AsyncSelect$1, Object.assign({}, propsNoClassName, selectProps, async, { onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler }))) : (jsxRuntime.jsx(StateManagedSelect$1, Object.assign({}, propsNoClassName, selectProps, { options: filterOption ? orderedOptions : options, isMulti: isMulti, hideSelectedOptions: false, onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler })))] }));
|
|
14180
14180
|
};
|
|
14181
14181
|
const SelectContainer = tailwindStyledComponents.tw.div `
|
|
14182
14182
|
tu-select
|
|
14183
14183
|
${({ $hasError }) => ($hasError ? tailwindStyledComponents.tws `tu-select--invalid` : null)}
|
|
14184
14184
|
${({ $isDisabled }) => ($isDisabled ? tailwindStyledComponents.tws `tu-select--disabled` : null)}
|
|
14185
|
+
${({ $isReadOnly }) => ($isReadOnly ? tailwindStyledComponents.tws `tu-select--readonly` : null)}
|
|
14185
14186
|
`;
|
|
14186
14187
|
Select.displayName = "Select";
|
|
14187
14188
|
|
|
@@ -14229,7 +14230,7 @@ const countryCodes = countryCodesSet.map(code => ({ label: `+${code}`, value: `+
|
|
|
14229
14230
|
* @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
|
|
14230
14231
|
* @returns {JSX.Element} CountryCodeSelect component
|
|
14231
14232
|
*/
|
|
14232
|
-
const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, dataTestId, placeholder, }) => {
|
|
14233
|
+
const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, }) => {
|
|
14233
14234
|
const [isCountryCodeMissing, setIsCountryCodeMissing] = React.useState(false);
|
|
14234
14235
|
React.useEffect(() => {
|
|
14235
14236
|
countryCode && setIsCountryCodeMissing(false);
|
|
@@ -14237,7 +14238,7 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
|
|
|
14237
14238
|
const filteredCodes = countryCodes.filter(code => {
|
|
14238
14239
|
return !(excludedCountries === null || excludedCountries === void 0 ? void 0 : excludedCountries.some(excludedCode => excludedCode.value === code.value));
|
|
14239
14240
|
});
|
|
14240
|
-
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 }));
|
|
14241
|
+
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 }));
|
|
14241
14242
|
};
|
|
14242
14243
|
|
|
14243
14244
|
/**
|
|
@@ -14251,9 +14252,9 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
|
|
|
14251
14252
|
* @returns {JSX.Element} - The PhoneInput component.
|
|
14252
14253
|
*/
|
|
14253
14254
|
const PhoneInput = React.forwardRef((_a, ref) => {
|
|
14254
|
-
var { dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, onChangeGetSeparateValues } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "value", "defaultValue", "fieldSize", "disableAction", "onChange", "onChangeGetSeparateValues"]);
|
|
14255
|
+
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"]);
|
|
14255
14256
|
const hiddenInputRef = React.useRef(null);
|
|
14256
|
-
const { countryCode, phoneNumber, isCountryCodeInvalid, isPhoneNumberInvalid, handleCountryCodeChange, handlePhoneNumberChange, combinedValue, isCombinedValueInvalid, } = usePhoneInput(value
|
|
14257
|
+
const { countryCode, phoneNumber, isCountryCodeInvalid, isPhoneNumberInvalid, handleCountryCodeChange, handlePhoneNumberChange, combinedValue, isCombinedValueInvalid, } = usePhoneInput(!!value ? value : defaultValue);
|
|
14257
14258
|
React.useEffect(() => {
|
|
14258
14259
|
const element = hiddenInputRef.current;
|
|
14259
14260
|
const event = new Event("change");
|
|
@@ -14265,7 +14266,7 @@ const PhoneInput = React.forwardRef((_a, ref) => {
|
|
|
14265
14266
|
React.useEffect(() => {
|
|
14266
14267
|
onChangeGetSeparateValues && onChangeGetSeparateValues({ countryCode, phoneNumber });
|
|
14267
14268
|
}, [countryCode, onChangeGetSeparateValues, phoneNumber]);
|
|
14268
|
-
return (jsxRuntime.jsxs(Container, { "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, 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, 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))] }));
|
|
14269
|
+
return (jsxRuntime.jsxs(Container, { "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))] }));
|
|
14269
14270
|
});
|
|
14270
14271
|
const Container = tailwindStyledComponents.tw.div `
|
|
14271
14272
|
grid
|
|
@@ -14294,7 +14295,7 @@ const PhoneField = React.forwardRef((_a, ref) => {
|
|
|
14294
14295
|
const { isCombinedValueInvalid, isPhoneNumberInvalid, isCountryCodeInvalid, combinedValue } = usePhoneInput(value);
|
|
14295
14296
|
const renderAsInvalid = isCombinedValueInvalid || isPhoneNumberInvalid || isCountryCodeInvalid || isInvalid || Boolean(errorMessage);
|
|
14296
14297
|
const htmlForId = id ? id : "phoneField-" + v4();
|
|
14297
|
-
return (jsxRuntime.jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || 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: combinedValue, defaultValue: defaultValue, ref: ref }, rest)) }));
|
|
14298
|
+
return (jsxRuntime.jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || 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: combinedValue, defaultValue: defaultValue, ref: ref, dataTestId: dataTestId }, rest)) }));
|
|
14298
14299
|
});
|
|
14299
14300
|
|
|
14300
14301
|
const RadioGroupContext = React__namespace.createContext(null);
|
package/index.js
CHANGED
|
@@ -6037,7 +6037,7 @@ const usePhoneInput = (value) => {
|
|
|
6037
6037
|
const [combinedValue, setCombinedValue] = useState(value !== null && value !== void 0 ? value : "");
|
|
6038
6038
|
useEffect(() => {
|
|
6039
6039
|
var _a, _b;
|
|
6040
|
-
if (value) {
|
|
6040
|
+
if (value && ((!countryCode && !phoneNumber) || !combinedValue)) {
|
|
6041
6041
|
const safePhoneNumber = getPhoneNumberWithPlus(value);
|
|
6042
6042
|
const number = parsePhoneNumber(safePhoneNumber);
|
|
6043
6043
|
setCountryCode((_a = number === null || number === void 0 ? void 0 : number.countryCallingCode.toString()) !== null && _a !== void 0 ? _a : "");
|
|
@@ -14121,7 +14121,7 @@ var AsyncSelect$1 = AsyncSelect;
|
|
|
14121
14121
|
*/
|
|
14122
14122
|
const Select = (props) => {
|
|
14123
14123
|
const { className } = props, propsNoClassName = __rest(props, ["className"]);
|
|
14124
|
-
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId ? dataTestId : "select", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable, } = props;
|
|
14124
|
+
const { id, dataTestId = "select", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId ? dataTestId : "select", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable, readOnly, } = props;
|
|
14125
14125
|
const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
|
|
14126
14126
|
const selectProps = {
|
|
14127
14127
|
value,
|
|
@@ -14135,11 +14135,11 @@ const Select = (props) => {
|
|
|
14135
14135
|
tabSelectsValue: false,
|
|
14136
14136
|
blurInputOnSelect: !isMulti,
|
|
14137
14137
|
menuPortalTarget: props.menuPortalTarget || document.body,
|
|
14138
|
-
isSearchable: disabled ? false : isSearchable,
|
|
14138
|
+
isSearchable: disabled || readOnly ? false : isSearchable,
|
|
14139
14139
|
menuShouldBlockScroll: true,
|
|
14140
14140
|
menuShouldScrollIntoView: true,
|
|
14141
14141
|
openMenuOnFocus: true,
|
|
14142
|
-
menuIsOpen,
|
|
14142
|
+
menuIsOpen: !readOnly ? menuIsOpen : false,
|
|
14143
14143
|
openMenuOnClick: true,
|
|
14144
14144
|
closeMenuOnSelect: false,
|
|
14145
14145
|
isMulti,
|
|
@@ -14150,12 +14150,13 @@ const Select = (props) => {
|
|
|
14150
14150
|
onMenuScrollToBottom,
|
|
14151
14151
|
onInputChange,
|
|
14152
14152
|
};
|
|
14153
|
-
return (jsxs(SelectContainer, { ref: refContainer, className: className, "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": disabled, children: [prefix !== undefined && (jsx$1(SelectPrefix, { "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix, children: prefix })), async ? (jsx$1(AsyncSelect$1, Object.assign({}, propsNoClassName, selectProps, async, { onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler }))) : (jsx$1(StateManagedSelect$1, Object.assign({}, propsNoClassName, selectProps, { options: filterOption ? orderedOptions : options, isMulti: isMulti, hideSelectedOptions: false, onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler })))] }));
|
|
14153
|
+
return (jsxs(SelectContainer, { ref: refContainer, className: className, "data-testid": dataTestId, "$hasError": hasError, "$isDisabled": disabled, "$isReadOnly": readOnly, children: [prefix !== undefined && (jsx$1(SelectPrefix, { "data-testid": dataTestId && `${dataTestId}-prefix`, ref: refPrefix, children: prefix })), async ? (jsx$1(AsyncSelect$1, Object.assign({}, propsNoClassName, selectProps, async, { onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler }))) : (jsx$1(StateManagedSelect$1, Object.assign({}, propsNoClassName, selectProps, { options: filterOption ? orderedOptions : options, isMulti: isMulti, hideSelectedOptions: false, onMenuOpen: openMenuHandler, onMenuClose: closeMenuHandler })))] }));
|
|
14154
14154
|
};
|
|
14155
14155
|
const SelectContainer = tw.div `
|
|
14156
14156
|
tu-select
|
|
14157
14157
|
${({ $hasError }) => ($hasError ? tws `tu-select--invalid` : null)}
|
|
14158
14158
|
${({ $isDisabled }) => ($isDisabled ? tws `tu-select--disabled` : null)}
|
|
14159
|
+
${({ $isReadOnly }) => ($isReadOnly ? tws `tu-select--readonly` : null)}
|
|
14159
14160
|
`;
|
|
14160
14161
|
Select.displayName = "Select";
|
|
14161
14162
|
|
|
@@ -14203,7 +14204,7 @@ const countryCodes = countryCodesSet.map(code => ({ label: `+${code}`, value: `+
|
|
|
14203
14204
|
* @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
|
|
14204
14205
|
* @returns {JSX.Element} CountryCodeSelect component
|
|
14205
14206
|
*/
|
|
14206
|
-
const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, dataTestId, placeholder, }) => {
|
|
14207
|
+
const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, }) => {
|
|
14207
14208
|
const [isCountryCodeMissing, setIsCountryCodeMissing] = useState(false);
|
|
14208
14209
|
useEffect(() => {
|
|
14209
14210
|
countryCode && setIsCountryCodeMissing(false);
|
|
@@ -14211,7 +14212,7 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
|
|
|
14211
14212
|
const filteredCodes = countryCodes.filter(code => {
|
|
14212
14213
|
return !(excludedCountries === null || excludedCountries === void 0 ? void 0 : excludedCountries.some(excludedCode => excludedCode.value === code.value));
|
|
14213
14214
|
});
|
|
14214
|
-
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 }));
|
|
14215
|
+
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 }));
|
|
14215
14216
|
};
|
|
14216
14217
|
|
|
14217
14218
|
/**
|
|
@@ -14225,9 +14226,9 @@ const CountryCodeSelect = ({ excludedCountries, countryCode, isInvalid, onChange
|
|
|
14225
14226
|
* @returns {JSX.Element} - The PhoneInput component.
|
|
14226
14227
|
*/
|
|
14227
14228
|
const PhoneInput = forwardRef((_a, ref) => {
|
|
14228
|
-
var { dataTestId, isInvalid, disabled = false, value, defaultValue, fieldSize = "medium", disableAction = false, onChange, onChangeGetSeparateValues } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "value", "defaultValue", "fieldSize", "disableAction", "onChange", "onChangeGetSeparateValues"]);
|
|
14229
|
+
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"]);
|
|
14229
14230
|
const hiddenInputRef = useRef(null);
|
|
14230
|
-
const { countryCode, phoneNumber, isCountryCodeInvalid, isPhoneNumberInvalid, handleCountryCodeChange, handlePhoneNumberChange, combinedValue, isCombinedValueInvalid, } = usePhoneInput(value
|
|
14231
|
+
const { countryCode, phoneNumber, isCountryCodeInvalid, isPhoneNumberInvalid, handleCountryCodeChange, handlePhoneNumberChange, combinedValue, isCombinedValueInvalid, } = usePhoneInput(!!value ? value : defaultValue);
|
|
14231
14232
|
useEffect(() => {
|
|
14232
14233
|
const element = hiddenInputRef.current;
|
|
14233
14234
|
const event = new Event("change");
|
|
@@ -14239,7 +14240,7 @@ const PhoneInput = forwardRef((_a, ref) => {
|
|
|
14239
14240
|
useEffect(() => {
|
|
14240
14241
|
onChangeGetSeparateValues && onChangeGetSeparateValues({ countryCode, phoneNumber });
|
|
14241
14242
|
}, [countryCode, onChangeGetSeparateValues, phoneNumber]);
|
|
14242
|
-
return (jsxs(Container, { "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, 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, 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))] }));
|
|
14243
|
+
return (jsxs(Container, { "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))] }));
|
|
14243
14244
|
});
|
|
14244
14245
|
const Container = tw.div `
|
|
14245
14246
|
grid
|
|
@@ -14268,7 +14269,7 @@ const PhoneField = forwardRef((_a, ref) => {
|
|
|
14268
14269
|
const { isCombinedValueInvalid, isPhoneNumberInvalid, isCountryCodeInvalid, combinedValue } = usePhoneInput(value);
|
|
14269
14270
|
const renderAsInvalid = isCombinedValueInvalid || isPhoneNumberInvalid || isCountryCodeInvalid || isInvalid || Boolean(errorMessage);
|
|
14270
14271
|
const htmlForId = id ? id : "phoneField-" + v4();
|
|
14271
|
-
return (jsx$1(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsx$1(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: combinedValue, defaultValue: defaultValue, ref: ref }, rest)) }));
|
|
14272
|
+
return (jsx$1(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, className: className, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsx$1(PhoneInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", value: combinedValue, defaultValue: defaultValue, ref: ref, dataTestId: dataTestId }, rest)) }));
|
|
14272
14273
|
});
|
|
14273
14274
|
|
|
14274
14275
|
const RadioGroupContext = React.createContext(null);
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-components",
|
|
3
|
-
"version": "0.0.101
|
|
3
|
+
"version": "0.0.101",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=18.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/css-class-variance-utilities": "0.0.
|
|
11
|
-
"@trackunit/i18n-library-translation": "0.0.
|
|
12
|
-
"@trackunit/react-components": "0.1.
|
|
13
|
-
"@trackunit/tailwind-styled-components": "0.0.
|
|
10
|
+
"@trackunit/css-class-variance-utilities": "0.0.11",
|
|
11
|
+
"@trackunit/i18n-library-translation": "0.0.67",
|
|
12
|
+
"@trackunit/react-components": "0.1.137",
|
|
13
|
+
"@trackunit/tailwind-styled-components": "0.0.60",
|
|
14
14
|
"date-fns": "2.29.3",
|
|
15
15
|
"libphonenumber-js": "1.10.36",
|
|
16
16
|
"react": "18.2.0",
|
|
@@ -11,6 +11,7 @@ interface CountryCodeSelectProps extends CommonProps {
|
|
|
11
11
|
value: string;
|
|
12
12
|
}>) => void;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
+
readOnly?: boolean;
|
|
14
15
|
placeholder?: string;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
@@ -19,5 +20,5 @@ interface CountryCodeSelectProps extends CommonProps {
|
|
|
19
20
|
* @param {CountryCodeSelectProps} props - The props for the CountryCodeSelect component
|
|
20
21
|
* @returns {JSX.Element} CountryCodeSelect component
|
|
21
22
|
*/
|
|
22
|
-
export declare const CountryCodeSelect: ({ excludedCountries, countryCode, isInvalid, onChange, disabled, dataTestId, placeholder, }: CountryCodeSelectProps) => JSX.Element;
|
|
23
|
+
export declare const CountryCodeSelect: ({ excludedCountries, countryCode, isInvalid, onChange, disabled, readOnly, dataTestId, placeholder, }: CountryCodeSelectProps) => JSX.Element;
|
|
23
24
|
export {};
|
|
@@ -31,6 +31,13 @@ export interface SelectProps<Option, IsAsync extends boolean, IsMulti extends bo
|
|
|
31
31
|
* @memberof SelectProps
|
|
32
32
|
*/
|
|
33
33
|
disabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* An boolean flag to make the field readonly
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
* @memberof SelectProps
|
|
39
|
+
*/
|
|
40
|
+
readOnly?: boolean;
|
|
34
41
|
/**
|
|
35
42
|
* An field id
|
|
36
43
|
*
|