@trackunit/react-form-components 0.0.188 → 0.0.190
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 +22 -7
- package/index.esm.js +22 -8
- package/package.json +3 -3
- package/src/index.d.ts +1 -0
- package/src/utilities/emailUtils.d.ts +7 -0
package/index.cjs.js
CHANGED
|
@@ -3068,6 +3068,22 @@ const DropZone = (_a) => {
|
|
|
3068
3068
|
} }, rest, { children: [jsxRuntime.jsx("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxRuntime.jsxs("label", { className: cvaDropZoneLabel(), htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label`, children: [jsxRuntime.jsx(reactComponents.Icon, { type: "solid", name: "ArrowUpCircle", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsxRuntime.jsx("span", { children: label })] })] })));
|
|
3069
3069
|
};
|
|
3070
3070
|
|
|
3071
|
+
/**
|
|
3072
|
+
* @description Validate given email id.
|
|
3073
|
+
* @param email The address to validate.
|
|
3074
|
+
* @returns {boolean} Returns true if the email address is valid else false.
|
|
3075
|
+
* @example validateEmailAddress(test@gmail.com) // true
|
|
3076
|
+
*/
|
|
3077
|
+
const validateEmailAddress = (email) => {
|
|
3078
|
+
if (!email) {
|
|
3079
|
+
return false;
|
|
3080
|
+
}
|
|
3081
|
+
// Doing the same check as we do on the backend
|
|
3082
|
+
// Using OWASP pattern from: https://owasp.org/www-community/OWASP_Validation_Regex_Repository
|
|
3083
|
+
const emailValidationPattern = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
3084
|
+
return emailValidationPattern.test(email);
|
|
3085
|
+
};
|
|
3086
|
+
|
|
3071
3087
|
/**
|
|
3072
3088
|
* A Email Input component is used for input of the type Email.
|
|
3073
3089
|
*
|
|
@@ -3079,12 +3095,13 @@ const DropZone = (_a) => {
|
|
|
3079
3095
|
* For specific input types make sure to use the corresponding input component.
|
|
3080
3096
|
*/
|
|
3081
3097
|
const EmailInput = React__namespace.forwardRef((_a, ref) => {
|
|
3082
|
-
var { fieldSize = "medium", disabled = false, dataTestId } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId"]);
|
|
3098
|
+
var { fieldSize = "medium", disabled = false, dataTestId, isInvalid = false } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId", "isInvalid"]);
|
|
3083
3099
|
const [email, setEmail] = React__namespace.useState("");
|
|
3084
3100
|
const sendEmail = () => {
|
|
3085
3101
|
return window.open(`mailto:${email}`);
|
|
3086
3102
|
};
|
|
3087
|
-
|
|
3103
|
+
const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
|
|
3104
|
+
return (jsxRuntime.jsx(BaseInput, Object.assign({ dataTestId: dataTestId, ref: ref, type: "email", placeholder: rest.placeholder || "mail@example.com", onChange: e => setEmail(e.target.value), isInvalid: renderAsInvalid }, rest, { actions: jsxRuntime.jsx(ActionButton, { disabled: disabled, value: email, type: "EMAIL", onClick: sendEmail, dataTestId: dataTestId && `${dataTestId}-emailIcon`, iconSize: fieldSize }) })));
|
|
3088
3105
|
});
|
|
3089
3106
|
|
|
3090
3107
|
/**
|
|
@@ -3093,17 +3110,14 @@ const EmailInput = React__namespace.forwardRef((_a, ref) => {
|
|
|
3093
3110
|
*
|
|
3094
3111
|
*/
|
|
3095
3112
|
const EmailField = React.forwardRef((_a, ref) => {
|
|
3096
|
-
var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId"]);
|
|
3113
|
+
var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId, isInvalid = false } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId", "isInvalid"]);
|
|
3097
3114
|
const [value, setValue] = React.useState(defaultValue || "");
|
|
3098
3115
|
const htmlForId = id ? id : "emailField-" + v4();
|
|
3099
3116
|
// Type guard to check if value is a string
|
|
3100
3117
|
function isString(inputValue) {
|
|
3101
3118
|
return typeof inputValue === "string";
|
|
3102
3119
|
}
|
|
3103
|
-
|
|
3104
|
-
// Using OWASP pattern from: https://owasp.org/www-community/OWASP_Validation_Regex_Repository
|
|
3105
|
-
const emailValidationPattern = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
3106
|
-
const renderAsInvalid = !!errorMessage || (isString(value) && emailValidationPattern.test(value));
|
|
3120
|
+
const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateEmailAddress(value)) || isInvalid;
|
|
3107
3121
|
return (jsxRuntime.jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsxRuntime.jsx(EmailInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, value: value, onChange: e => setValue(e.target.value), isInvalid: renderAsInvalid, disabled: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
3108
3122
|
});
|
|
3109
3123
|
|
|
@@ -15291,5 +15305,6 @@ exports.parseSchedule = parseSchedule;
|
|
|
15291
15305
|
exports.serializeSchedule = serializeSchedule;
|
|
15292
15306
|
exports.useCustomComponents = useCustomComponents;
|
|
15293
15307
|
exports.usePhoneInput = usePhoneInput;
|
|
15308
|
+
exports.validateEmailAddress = validateEmailAddress;
|
|
15294
15309
|
exports.validatePhoneNumber = validatePhoneNumber;
|
|
15295
15310
|
exports.weekDay = weekDay;
|
package/index.esm.js
CHANGED
|
@@ -3042,6 +3042,22 @@ const DropZone = (_a) => {
|
|
|
3042
3042
|
} }, rest, { children: [jsx$1("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxs("label", { className: cvaDropZoneLabel(), htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label`, children: [jsx$1(Icon, { type: "solid", name: "ArrowUpCircle", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsx$1("span", { children: label })] })] })));
|
|
3043
3043
|
};
|
|
3044
3044
|
|
|
3045
|
+
/**
|
|
3046
|
+
* @description Validate given email id.
|
|
3047
|
+
* @param email The address to validate.
|
|
3048
|
+
* @returns {boolean} Returns true if the email address is valid else false.
|
|
3049
|
+
* @example validateEmailAddress(test@gmail.com) // true
|
|
3050
|
+
*/
|
|
3051
|
+
const validateEmailAddress = (email) => {
|
|
3052
|
+
if (!email) {
|
|
3053
|
+
return false;
|
|
3054
|
+
}
|
|
3055
|
+
// Doing the same check as we do on the backend
|
|
3056
|
+
// Using OWASP pattern from: https://owasp.org/www-community/OWASP_Validation_Regex_Repository
|
|
3057
|
+
const emailValidationPattern = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
3058
|
+
return emailValidationPattern.test(email);
|
|
3059
|
+
};
|
|
3060
|
+
|
|
3045
3061
|
/**
|
|
3046
3062
|
* A Email Input component is used for input of the type Email.
|
|
3047
3063
|
*
|
|
@@ -3053,12 +3069,13 @@ const DropZone = (_a) => {
|
|
|
3053
3069
|
* For specific input types make sure to use the corresponding input component.
|
|
3054
3070
|
*/
|
|
3055
3071
|
const EmailInput = React.forwardRef((_a, ref) => {
|
|
3056
|
-
var { fieldSize = "medium", disabled = false, dataTestId } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId"]);
|
|
3072
|
+
var { fieldSize = "medium", disabled = false, dataTestId, isInvalid = false } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId", "isInvalid"]);
|
|
3057
3073
|
const [email, setEmail] = React.useState("");
|
|
3058
3074
|
const sendEmail = () => {
|
|
3059
3075
|
return window.open(`mailto:${email}`);
|
|
3060
3076
|
};
|
|
3061
|
-
|
|
3077
|
+
const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
|
|
3078
|
+
return (jsx$1(BaseInput, Object.assign({ dataTestId: dataTestId, ref: ref, type: "email", placeholder: rest.placeholder || "mail@example.com", onChange: e => setEmail(e.target.value), isInvalid: renderAsInvalid }, rest, { actions: jsx$1(ActionButton, { disabled: disabled, value: email, type: "EMAIL", onClick: sendEmail, dataTestId: dataTestId && `${dataTestId}-emailIcon`, iconSize: fieldSize }) })));
|
|
3062
3079
|
});
|
|
3063
3080
|
|
|
3064
3081
|
/**
|
|
@@ -3067,17 +3084,14 @@ const EmailInput = React.forwardRef((_a, ref) => {
|
|
|
3067
3084
|
*
|
|
3068
3085
|
*/
|
|
3069
3086
|
const EmailField = forwardRef((_a, ref) => {
|
|
3070
|
-
var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId"]);
|
|
3087
|
+
var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId, isInvalid = false } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId", "isInvalid"]);
|
|
3071
3088
|
const [value, setValue] = useState(defaultValue || "");
|
|
3072
3089
|
const htmlForId = id ? id : "emailField-" + v4();
|
|
3073
3090
|
// Type guard to check if value is a string
|
|
3074
3091
|
function isString(inputValue) {
|
|
3075
3092
|
return typeof inputValue === "string";
|
|
3076
3093
|
}
|
|
3077
|
-
|
|
3078
|
-
// Using OWASP pattern from: https://owasp.org/www-community/OWASP_Validation_Regex_Repository
|
|
3079
|
-
const emailValidationPattern = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
3080
|
-
const renderAsInvalid = !!errorMessage || (isString(value) && emailValidationPattern.test(value));
|
|
3094
|
+
const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateEmailAddress(value)) || isInvalid;
|
|
3081
3095
|
return (jsx$1(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsx$1(EmailInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, value: value, onChange: e => setValue(e.target.value), isInvalid: renderAsInvalid, disabled: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) }));
|
|
3082
3096
|
});
|
|
3083
3097
|
|
|
@@ -15204,4 +15218,4 @@ const UploadField = forwardRef((_a, ref) => {
|
|
|
15204
15218
|
*/
|
|
15205
15219
|
setupLibraryTranslations();
|
|
15206
15220
|
|
|
15207
|
-
export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, StateManagedSelect$1 as ValueType, checkIfPhoneNumberHasPlus, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, parseSchedule, serializeSchedule, useCustomComponents, usePhoneInput, validatePhoneNumber, weekDay };
|
|
15221
|
+
export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, StateManagedSelect$1 as ValueType, checkIfPhoneNumberHasPlus, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, parseSchedule, serializeSchedule, useCustomComponents, usePhoneInput, validateEmailAddress, validatePhoneNumber, weekDay };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.190",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@trackunit/css-class-variance-utilities": "0.0.15",
|
|
11
11
|
"@trackunit/i18n-library-translation": "0.0.89",
|
|
12
|
-
"@trackunit/react-components": "0.1.
|
|
13
|
-
"@trackunit/shared-utils": "0.0.
|
|
12
|
+
"@trackunit/react-components": "0.1.189",
|
|
13
|
+
"@trackunit/shared-utils": "0.0.15",
|
|
14
14
|
"@trackunit/ui-icons": "0.0.78",
|
|
15
15
|
"date-fns": "2.29.3",
|
|
16
16
|
"libphonenumber-js": "1.10.36",
|
package/src/index.d.ts
CHANGED
|
@@ -29,4 +29,5 @@ export * from "./components/TimeRangeField/TimeRangeField";
|
|
|
29
29
|
export * from "./components/Toggle";
|
|
30
30
|
export * from "./components/UploadField/UploadField";
|
|
31
31
|
export * from "./components/UploadInput/UploadInput";
|
|
32
|
+
export * from "./utilities/emailUtils";
|
|
32
33
|
export * from "./utilities/usePhoneInput";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Validate given email id.
|
|
3
|
+
* @param email The address to validate.
|
|
4
|
+
* @returns {boolean} Returns true if the email address is valid else false.
|
|
5
|
+
* @example validateEmailAddress(test@gmail.com) // true
|
|
6
|
+
*/
|
|
7
|
+
export declare const validateEmailAddress: (email: string) => boolean;
|