@trackunit/react-form-components 0.0.360 → 0.0.362

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
@@ -534,19 +534,6 @@ const Checkbox = React__namespace.forwardRef((_a, ref) => {
534
534
  }), id: `checkbox-label-${label}`, ref: labelReference => setLabelRef(labelReference), children: label }) })), suffix] }));
535
535
  });
536
536
 
537
- /**
538
- * A wrapper around BaseInput with a pop-up day picker.
539
- *
540
- * NOTE: If shown with a label, please use the `DateField` component instead.
541
- */
542
- const DateInput = React.forwardRef((_a, ref) => {
543
- var { min, max, defaultValue, value } = _a, rest = __rest(_a, ["min", "max", "defaultValue", "value"]);
544
- const formatDateToInputString = (date) => date instanceof Date ? dateFns.format(date, "yyyy-MM-dd") : date;
545
- // Chrome and Firefox need their default icon to have datepicker functionality.
546
- const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
547
- return (jsxRuntime.jsx(BaseInput, Object.assign({ defaultValue: formatDateToInputString(defaultValue), max: formatDateToInputString(max), min: formatDateToInputString(min), ref: ref, suffix: showIcon && jsxRuntime.jsx(reactComponents.Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }), type: "date", value: formatDateToInputString(value) }, rest)));
548
- });
549
-
550
537
  /**
551
538
  * The Label component is used for labels for input fields.
552
539
  * This component is **not used directly**, but is part of the FormGroup and Field components.
@@ -588,6 +575,30 @@ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId,
588
575
  return (jsxRuntime.jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { className: cvaFormGroupContainerBefore(), children: [jsxRuntime.jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), tip && (jsxRuntime.jsx(reactComponents.Tooltip, { dataTestId: dataTestId && `${dataTestId}-tooltip`, iconProps: tipIconProps, label: tip, placement: "bottom" }))] }), children, jsxRuntime.jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText && jsxRuntime.jsx("span", { "data-testid": dataTestId && `${dataTestId}-helpText`, children: helpText }), helpAddon && (jsxRuntime.jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId && `${dataTestId}-helpAddon`, children: helpAddon }))] })] }));
589
576
  };
590
577
 
578
+ /**
579
+ * The checkbox field component is used for entering boolean values.
580
+ *
581
+ * _**Do use**_ the CheckboxField for boolean input.
582
+ */
583
+ const CheckboxField = React.forwardRef((_a, ref) => {
584
+ var { label, id, tip, helpText, helpAddon, isInvalid, className, checked, dataTestId, checkboxLabel, onChange } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "helpAddon", "isInvalid", "className", "checked", "dataTestId", "checkboxLabel", "onChange"]);
585
+ const htmlForId = id ? id : "checkboxField-" + uuid.v4();
586
+ return (jsxRuntime.jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.disabled, helpAddon: helpAddon, helpText: helpText, htmlFor: htmlForId, label: label, tip: tip, children: jsxRuntime.jsx(Checkbox, Object.assign({ checked: checked, className: className, dataTestId: dataTestId, id: htmlForId, label: checkboxLabel, onChange: onChange, ref: ref }, rest)) }));
587
+ });
588
+
589
+ /**
590
+ * A wrapper around BaseInput with a pop-up day picker.
591
+ *
592
+ * NOTE: If shown with a label, please use the `DateField` component instead.
593
+ */
594
+ const DateInput = React.forwardRef((_a, ref) => {
595
+ var { min, max, defaultValue, value } = _a, rest = __rest(_a, ["min", "max", "defaultValue", "value"]);
596
+ const formatDateToInputString = (date) => date instanceof Date ? dateFns.format(date, "yyyy-MM-dd") : date;
597
+ // Chrome and Firefox need their default icon to have datepicker functionality.
598
+ const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
599
+ return (jsxRuntime.jsx(BaseInput, Object.assign({ defaultValue: formatDateToInputString(defaultValue), max: formatDateToInputString(max), min: formatDateToInputString(min), ref: ref, suffix: showIcon && jsxRuntime.jsx(reactComponents.Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }), type: "date", value: formatDateToInputString(value) }, rest)));
600
+ });
601
+
591
602
  /**
592
603
  * The date field component is used for entering date values.
593
604
  *
@@ -2191,6 +2202,30 @@ const UrlField = React.forwardRef((_a, ref) => {
2191
2202
  return (jsxRuntime.jsx(FormGroup, { dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.disabled, helpAddon: helpAddon, helpText: renderAsInvalid ? errorMessage : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsxRuntime.jsx(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", disabled: rest.disabled, id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
2192
2203
  });
2193
2204
 
2205
+ /**
2206
+ * Custom hook to get phone number validation rules.
2207
+ *
2208
+ * @returns {object} An object containing the `getPhoneNumberValidationRules` method.
2209
+ * @example
2210
+ * const { getPhoneNumberValidationRules } = useGetPhoneValidationRules();
2211
+ * const validationRules = getPhoneNumberValidationRules(false);
2212
+ */
2213
+ const useGetPhoneValidationRules = () => {
2214
+ const [t] = useTranslation();
2215
+ const getPhoneNumberValidationRules = React.useCallback((skipValidation = false) => {
2216
+ const defaultRules = {};
2217
+ const pattern = {
2218
+ validate: (value) => {
2219
+ const validationResult = t(`phoneField.error.${validatePhoneNumber(value)}`);
2220
+ return !validationResult || value === "" || value === undefined || value === null || validationResult;
2221
+ },
2222
+ };
2223
+ return !skipValidation
2224
+ ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
2225
+ }, [t]);
2226
+ return { getPhoneNumberValidationRules };
2227
+ };
2228
+
2194
2229
  /**
2195
2230
  * A custom hook for managing phone number input state and validation.
2196
2231
  *
@@ -2262,30 +2297,6 @@ const useZodValidators = () => {
2262
2297
  return React.useMemo(() => ({ ZodPhoneValidator }), [ZodPhoneValidator]);
2263
2298
  };
2264
2299
 
2265
- /**
2266
- * Custom hook to get phone number validation rules.
2267
- *
2268
- * @returns {object} An object containing the `getPhoneNumberValidationRules` method.
2269
- * @example
2270
- * const { getPhoneNumberValidationRules } = useGetPhoneValidationRules();
2271
- * const validationRules = getPhoneNumberValidationRules(false);
2272
- */
2273
- const useGetPhoneValidationRules = () => {
2274
- const [t] = useTranslation();
2275
- const getPhoneNumberValidationRules = React.useCallback((skipValidation = false) => {
2276
- const defaultRules = {};
2277
- const pattern = {
2278
- validate: (value) => {
2279
- const validationResult = t(`phoneField.error.${validatePhoneNumber(value)}`);
2280
- return !validationResult || value === "" || value === undefined || value === null || validationResult;
2281
- },
2282
- };
2283
- return !skipValidation
2284
- ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
2285
- }, [t]);
2286
- return { getPhoneNumberValidationRules };
2287
- };
2288
-
2289
2300
  /*
2290
2301
  * ----------------------------
2291
2302
  * | SETUP TRANSLATIONS START |
@@ -2302,6 +2313,7 @@ Object.defineProperty(exports, 'ValueType', {
2302
2313
  exports.ActionButton = ActionButton;
2303
2314
  exports.BaseInput = BaseInput;
2304
2315
  exports.Checkbox = Checkbox;
2316
+ exports.CheckboxField = CheckboxField;
2305
2317
  exports.CreatableSelect = CreatableSelect;
2306
2318
  exports.CreatableSelectField = CreatableSelectField;
2307
2319
  exports.DateField = DateField;
package/index.esm.js CHANGED
@@ -504,19 +504,6 @@ const Checkbox = React.forwardRef((_a, ref) => {
504
504
  }), id: `checkbox-label-${label}`, ref: labelReference => setLabelRef(labelReference), children: label }) })), suffix] }));
505
505
  });
506
506
 
507
- /**
508
- * A wrapper around BaseInput with a pop-up day picker.
509
- *
510
- * NOTE: If shown with a label, please use the `DateField` component instead.
511
- */
512
- const DateInput = forwardRef((_a, ref) => {
513
- var { min, max, defaultValue, value } = _a, rest = __rest(_a, ["min", "max", "defaultValue", "value"]);
514
- const formatDateToInputString = (date) => date instanceof Date ? format(date, "yyyy-MM-dd") : date;
515
- // Chrome and Firefox need their default icon to have datepicker functionality.
516
- const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
517
- return (jsx(BaseInput, Object.assign({ defaultValue: formatDateToInputString(defaultValue), max: formatDateToInputString(max), min: formatDateToInputString(min), ref: ref, suffix: showIcon && jsx(Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }), type: "date", value: formatDateToInputString(value) }, rest)));
518
- });
519
-
520
507
  /**
521
508
  * The Label component is used for labels for input fields.
522
509
  * This component is **not used directly**, but is part of the FormGroup and Field components.
@@ -558,6 +545,30 @@ const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId,
558
545
  return (jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxs("div", { className: cvaFormGroupContainerBefore(), children: [jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), tip && (jsx(Tooltip, { dataTestId: dataTestId && `${dataTestId}-tooltip`, iconProps: tipIconProps, label: tip, placement: "bottom" }))] }), children, jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText && jsx("span", { "data-testid": dataTestId && `${dataTestId}-helpText`, children: helpText }), helpAddon && (jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId && `${dataTestId}-helpAddon`, children: helpAddon }))] })] }));
559
546
  };
560
547
 
548
+ /**
549
+ * The checkbox field component is used for entering boolean values.
550
+ *
551
+ * _**Do use**_ the CheckboxField for boolean input.
552
+ */
553
+ const CheckboxField = forwardRef((_a, ref) => {
554
+ var { label, id, tip, helpText, helpAddon, isInvalid, className, checked, dataTestId, checkboxLabel, onChange } = _a, rest = __rest(_a, ["label", "id", "tip", "helpText", "helpAddon", "isInvalid", "className", "checked", "dataTestId", "checkboxLabel", "onChange"]);
555
+ const htmlForId = id ? id : "checkboxField-" + v4();
556
+ return (jsx(FormGroup, { className: "flex flex-col gap-1", dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.disabled, helpAddon: helpAddon, helpText: helpText, htmlFor: htmlForId, label: label, tip: tip, children: jsx(Checkbox, Object.assign({ checked: checked, className: className, dataTestId: dataTestId, id: htmlForId, label: checkboxLabel, onChange: onChange, ref: ref }, rest)) }));
557
+ });
558
+
559
+ /**
560
+ * A wrapper around BaseInput with a pop-up day picker.
561
+ *
562
+ * NOTE: If shown with a label, please use the `DateField` component instead.
563
+ */
564
+ const DateInput = forwardRef((_a, ref) => {
565
+ var { min, max, defaultValue, value } = _a, rest = __rest(_a, ["min", "max", "defaultValue", "value"]);
566
+ const formatDateToInputString = (date) => date instanceof Date ? format(date, "yyyy-MM-dd") : date;
567
+ // Chrome and Firefox need their default icon to have datepicker functionality.
568
+ const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
569
+ return (jsx(BaseInput, Object.assign({ defaultValue: formatDateToInputString(defaultValue), max: formatDateToInputString(max), min: formatDateToInputString(min), ref: ref, suffix: showIcon && jsx(Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }), type: "date", value: formatDateToInputString(value) }, rest)));
570
+ });
571
+
561
572
  /**
562
573
  * The date field component is used for entering date values.
563
574
  *
@@ -2161,6 +2172,30 @@ const UrlField = forwardRef((_a, ref) => {
2161
2172
  return (jsx(FormGroup, { dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.disabled, helpAddon: helpAddon, helpText: renderAsInvalid ? errorMessage : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsx(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", disabled: rest.disabled, id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
2162
2173
  });
2163
2174
 
2175
+ /**
2176
+ * Custom hook to get phone number validation rules.
2177
+ *
2178
+ * @returns {object} An object containing the `getPhoneNumberValidationRules` method.
2179
+ * @example
2180
+ * const { getPhoneNumberValidationRules } = useGetPhoneValidationRules();
2181
+ * const validationRules = getPhoneNumberValidationRules(false);
2182
+ */
2183
+ const useGetPhoneValidationRules = () => {
2184
+ const [t] = useTranslation();
2185
+ const getPhoneNumberValidationRules = useCallback((skipValidation = false) => {
2186
+ const defaultRules = {};
2187
+ const pattern = {
2188
+ validate: (value) => {
2189
+ const validationResult = t(`phoneField.error.${validatePhoneNumber(value)}`);
2190
+ return !validationResult || value === "" || value === undefined || value === null || validationResult;
2191
+ },
2192
+ };
2193
+ return !skipValidation
2194
+ ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
2195
+ }, [t]);
2196
+ return { getPhoneNumberValidationRules };
2197
+ };
2198
+
2164
2199
  /**
2165
2200
  * A custom hook for managing phone number input state and validation.
2166
2201
  *
@@ -2232,30 +2267,6 @@ const useZodValidators = () => {
2232
2267
  return useMemo(() => ({ ZodPhoneValidator }), [ZodPhoneValidator]);
2233
2268
  };
2234
2269
 
2235
- /**
2236
- * Custom hook to get phone number validation rules.
2237
- *
2238
- * @returns {object} An object containing the `getPhoneNumberValidationRules` method.
2239
- * @example
2240
- * const { getPhoneNumberValidationRules } = useGetPhoneValidationRules();
2241
- * const validationRules = getPhoneNumberValidationRules(false);
2242
- */
2243
- const useGetPhoneValidationRules = () => {
2244
- const [t] = useTranslation();
2245
- const getPhoneNumberValidationRules = useCallback((skipValidation = false) => {
2246
- const defaultRules = {};
2247
- const pattern = {
2248
- validate: (value) => {
2249
- const validationResult = t(`phoneField.error.${validatePhoneNumber(value)}`);
2250
- return !validationResult || value === "" || value === undefined || value === null || validationResult;
2251
- },
2252
- };
2253
- return !skipValidation
2254
- ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
2255
- }, [t]);
2256
- return { getPhoneNumberValidationRules };
2257
- };
2258
-
2259
2270
  /*
2260
2271
  * ----------------------------
2261
2272
  * | SETUP TRANSLATIONS START |
@@ -2265,4 +2276,4 @@ const useGetPhoneValidationRules = () => {
2265
2276
  */
2266
2277
  setupLibraryTranslations();
2267
2278
 
2268
- export { ActionButton, BaseInput, Checkbox, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, 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, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
2279
+ export { ActionButton, BaseInput, Checkbox, CheckboxField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, 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, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.360",
3
+ "version": "0.0.362",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./components/ActionButton";
2
2
  export * from "./components/BaseInput";
3
3
  export * from "./components/Checkbox";
4
+ export * from "./components/CheckboxField/CheckboxField";
4
5
  export * from "./components/DateField/DateField";
5
6
  export * from "./components/DateInput/DateInput";
6
7
  export * from "./components/DropZone/DropZone";
@@ -38,6 +39,6 @@ export * from "./components/UploadInput/UploadInput";
38
39
  export * from "./components/UrlField/UrlField";
39
40
  export * from "./components/UrlInput/UrlInput";
40
41
  export * from "./utilities/emailUtils";
42
+ export * from "./utilities/useGetPhoneValidationRules";
41
43
  export * from "./utilities/usePhoneInput";
42
44
  export * from "./utilities/useZodValidators";
43
- export * from "./utilities/useGetPhoneValidationRules";