@trackunit/react-form-components 0.0.265 → 0.0.267

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
@@ -2178,6 +2178,49 @@ const UploadField = React.forwardRef((_a, ref) => {
2178
2178
  return (jsxRuntime.jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, dataTestId: `${dataTestId}-FormGroup`, children: jsxRuntime.jsx(UploadInput, Object.assign({ ref: ref, id: htmlForId, "aria-labelledby": htmlForId + "-label", isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) }));
2179
2179
  });
2180
2180
 
2181
+ /**
2182
+ * @description Validate given url id.
2183
+ * @param url The address to validate.
2184
+ * @returns {boolean} Returns true if the url address is valid else false.
2185
+ * @example validateUrlAddress(https://www.example.com) // true
2186
+ */
2187
+ const validateUrlAddress = (url) => {
2188
+ if (!url) {
2189
+ return false;
2190
+ }
2191
+ // Using pattern from libs/custom-field/components/src/getValidationRules.ts
2192
+ const urlPattern = new RegExp("^(((https?|ftps?)://)(%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:|:blank:]])?$");
2193
+ return urlPattern.test(url);
2194
+ };
2195
+
2196
+ /**
2197
+ * A thin wrapper around the `BaseInput` component for URL input fields.
2198
+ *
2199
+ * NOTE: If shown with a label, please use the `UrlField` component instead.
2200
+ */
2201
+ const UrlInput = React.forwardRef((_a, ref) => {
2202
+ var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction", "value", "defaultValue"]);
2203
+ const [url, setUrl] = React.useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
2204
+ const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
2205
+ return (jsxRuntime.jsx(BaseInput, Object.assign({ id: "url-input", dataTestId: dataTestId && `${dataTestId}-url-input`, ref: ref, type: "url", placeholder: rest.placeholder || "https://www.example.com", onChange: e => setUrl(e.target.value), isInvalid: renderAsInvalid, value: url, disabled: disabled }, rest, { actions: !disableAction && (jsxRuntime.jsx(ActionButton, { disabled: renderAsInvalid || disabled, value: url, type: "WEB_ADDRESS", dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", iconSize: fieldSize })) })));
2206
+ });
2207
+
2208
+ /**
2209
+ * The UrlField component is used to enter url.
2210
+ * UrlField validates that user enters a valid web address.
2211
+ *
2212
+ */
2213
+ const UrlField = React.forwardRef((_a, ref) => {
2214
+ var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId, isInvalid = false, value } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId", "isInvalid", "value"]);
2215
+ const htmlForId = id ? id : "urlField-" + uuid.v4();
2216
+ // Type guard to check if value is a string
2217
+ function isString(inputValue) {
2218
+ return typeof inputValue === "string";
2219
+ }
2220
+ const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
2221
+ 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(UrlInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, value: value || defaultValue, isInvalid: renderAsInvalid, disabled: rest.disabled }, rest, { className: className, dataTestId: dataTestId })) }));
2222
+ });
2223
+
2181
2224
  /*
2182
2225
  * ----------------------------
2183
2226
  * | SETUP TRANSLATIONS START |
@@ -2225,6 +2268,8 @@ exports.TimeRangeField = TimeRangeField;
2225
2268
  exports.Toggle = Toggle;
2226
2269
  exports.UploadField = UploadField;
2227
2270
  exports.UploadInput = UploadInput;
2271
+ exports.UrlField = UrlField;
2272
+ exports.UrlInput = UrlInput;
2228
2273
  exports.checkIfPhoneNumberHasPlus = checkIfPhoneNumberHasPlus;
2229
2274
  exports.countryCodeToFlagEmoji = countryCodeToFlagEmoji;
2230
2275
  exports.cvaInput = cvaInput;
package/index.esm.js CHANGED
@@ -2148,6 +2148,49 @@ const UploadField = forwardRef((_a, ref) => {
2148
2148
  return (jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, dataTestId: `${dataTestId}-FormGroup`, children: jsx(UploadInput, Object.assign({ ref: ref, id: htmlForId, "aria-labelledby": htmlForId + "-label", isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) }));
2149
2149
  });
2150
2150
 
2151
+ /**
2152
+ * @description Validate given url id.
2153
+ * @param url The address to validate.
2154
+ * @returns {boolean} Returns true if the url address is valid else false.
2155
+ * @example validateUrlAddress(https://www.example.com) // true
2156
+ */
2157
+ const validateUrlAddress = (url) => {
2158
+ if (!url) {
2159
+ return false;
2160
+ }
2161
+ // Using pattern from libs/custom-field/components/src/getValidationRules.ts
2162
+ const urlPattern = new RegExp("^(((https?|ftps?)://)(%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:|:blank:]])?$");
2163
+ return urlPattern.test(url);
2164
+ };
2165
+
2166
+ /**
2167
+ * A thin wrapper around the `BaseInput` component for URL input fields.
2168
+ *
2169
+ * NOTE: If shown with a label, please use the `UrlField` component instead.
2170
+ */
2171
+ const UrlInput = forwardRef((_a, ref) => {
2172
+ var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction", "value", "defaultValue"]);
2173
+ const [url, setUrl] = useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
2174
+ const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
2175
+ return (jsx(BaseInput, Object.assign({ id: "url-input", dataTestId: dataTestId && `${dataTestId}-url-input`, ref: ref, type: "url", placeholder: rest.placeholder || "https://www.example.com", onChange: e => setUrl(e.target.value), isInvalid: renderAsInvalid, value: url, disabled: disabled }, rest, { actions: !disableAction && (jsx(ActionButton, { disabled: renderAsInvalid || disabled, value: url, type: "WEB_ADDRESS", dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", iconSize: fieldSize })) })));
2176
+ });
2177
+
2178
+ /**
2179
+ * The UrlField component is used to enter url.
2180
+ * UrlField validates that user enters a valid web address.
2181
+ *
2182
+ */
2183
+ const UrlField = forwardRef((_a, ref) => {
2184
+ var { label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, dataTestId, isInvalid = false, value } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "errorMessage", "helpAddon", "className", "defaultValue", "dataTestId", "isInvalid", "value"]);
2185
+ const htmlForId = id ? id : "urlField-" + v4();
2186
+ // Type guard to check if value is a string
2187
+ function isString(inputValue) {
2188
+ return typeof inputValue === "string";
2189
+ }
2190
+ const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
2191
+ return (jsx(FormGroup, { htmlFor: htmlForId, label: label, tip: tip, isInvalid: renderAsInvalid, helpText: renderAsInvalid ? errorMessage : helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup`, children: jsx(UrlInput, Object.assign({ id: htmlForId, "aria-labelledby": htmlForId + "-label", ref: ref, value: value || defaultValue, isInvalid: renderAsInvalid, disabled: rest.disabled }, rest, { className: className, dataTestId: dataTestId })) }));
2192
+ });
2193
+
2151
2194
  /*
2152
2195
  * ----------------------------
2153
2196
  * | SETUP TRANSLATIONS START |
@@ -2157,4 +2200,4 @@ const UploadField = forwardRef((_a, ref) => {
2157
2200
  */
2158
2201
  setupLibraryTranslations();
2159
2202
 
2160
- export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getCountryAbbreviation, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, parseSchedule, serializeSchedule, useCustomComponents, usePhoneInput, validateEmailAddress, validatePhoneNumber, weekDay };
2203
+ export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getCountryAbbreviation, 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.265",
3
+ "version": "0.0.267",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { FormGroupProps } from "../FormGroup/FormGroup";
3
+ import { UrlInputProps } from "../UrlInput/UrlInput";
4
+ type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon">;
5
+ export interface UrlFieldProps extends FormGroupExposedProps, UrlInputProps {
6
+ /**
7
+ * If a value is set, the field is rendered in its invalid state.
8
+ */
9
+ errorMessage?: string;
10
+ }
11
+ /**
12
+ * The UrlField component is used to enter url.
13
+ * UrlField validates that user enters a valid web address.
14
+ *
15
+ */
16
+ export declare const UrlField: import("react").ForwardRefExoticComponent<UrlFieldProps & import("react").RefAttributes<HTMLInputElement>>;
17
+ export {};
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { BaseInputProps } from "../BaseInput";
3
+ type BaseInputExposedProps = Omit<BaseInputProps, "type">;
4
+ export interface UrlInputProps extends BaseInputExposedProps {
5
+ /**
6
+ * To disable the action button.
7
+ *
8
+ * @default false
9
+ * @memberof UrlInputProps
10
+ * @example
11
+ * <UrLInput disableAction />
12
+ */
13
+ disableAction?: boolean;
14
+ }
15
+ /**
16
+ * A thin wrapper around the `BaseInput` component for URL input fields.
17
+ *
18
+ * NOTE: If shown with a label, please use the `UrlField` component instead.
19
+ */
20
+ export declare const UrlInput: import("react").ForwardRefExoticComponent<UrlInputProps & import("react").RefAttributes<HTMLInputElement>>;
21
+ export {};
package/src/index.d.ts CHANGED
@@ -31,5 +31,7 @@ export * from "./components/TimeRangeField/TimeRangeField";
31
31
  export * from "./components/Toggle";
32
32
  export * from "./components/UploadField/UploadField";
33
33
  export * from "./components/UploadInput/UploadInput";
34
+ export * from "./components/UrlField/UrlField";
35
+ export * from "./components/UrlInput/UrlInput";
34
36
  export * from "./utilities/emailUtils";
35
37
  export * from "./utilities/usePhoneInput";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description Validate given url id.
3
+ * @param url The address to validate.
4
+ * @returns {boolean} Returns true if the url address is valid else false.
5
+ * @example validateUrlAddress(https://www.example.com) // true
6
+ */
7
+ export declare const validateUrlAddress: (url: string) => boolean;