@trackunit/react-form-components 0.0.331 → 0.0.332

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.331",
3
+ "version": "0.0.332",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -19,7 +19,9 @@
19
19
  "@testing-library/react": "14.0.0",
20
20
  "jest-fetch-mock": "^3.0.3",
21
21
  "@trackunit/css-class-variance-utilities": "*",
22
- "@trackunit/i18n-library-translation": "*"
22
+ "@trackunit/i18n-library-translation": "*",
23
+ "zod": "3.22.4",
24
+ "react-hook-form": "7.40.0"
23
25
  },
24
26
  "module": "./index.esm.js",
25
27
  "main": "./index.cjs.js"
@@ -32,6 +32,7 @@ export interface FormGroupProps extends CommonProps {
32
32
  * The props for setting the icon on tip.
33
33
  */
34
34
  tipIconProps?: IconProps;
35
+ name?: string;
35
36
  }
36
37
  /**
37
38
  * The FormGroup component should be used to wrap any Input element that needs a label.
@@ -1,13 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { FormGroupProps } from "../FormGroup/FormGroup";
3
3
  import { PhoneInputProps } from "../PhoneInput/PhoneInput";
4
- type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon">;
4
+ type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon" | "name">;
5
5
  export interface PhoneFieldProps extends FormGroupExposedProps, PhoneInputProps {
6
6
  /**
7
7
  * If a value is set, the field is rendered in its invalid state.
8
8
  */
9
9
  errorMessage?: string;
10
- isCountryCodeClearable?: boolean;
11
10
  }
12
11
  /**
13
12
  * The PhoneField component is used to enter phone number.
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ import { Control, ControllerProps } from "react-hook-form";
3
+ import { PhoneFieldProps } from "../PhoneField/PhoneField";
4
+ export interface PhoneFieldWithControllerProps extends PhoneFieldProps {
5
+ /**
6
+ * Instance of `Control` from `react-hook-form`.
7
+ */
8
+ control: Control<any, any>;
9
+ /**
10
+ * Represents the name of the form field used to register the component with `react-hook-form`.
11
+ */
12
+ name: string;
13
+ /**
14
+ * Used to overwrite controller props.
15
+ */
16
+ controllerProps?: Partial<Omit<ControllerProps<any>, "render">>;
17
+ }
18
+ /**
19
+ * The PhoneFieldWithController component is a wrapper for the PhoneField component to connect it to react-hook-form.
20
+ *
21
+ * @returns {JSX.Element} - The PhoneFieldWithController component.
22
+ */
23
+ export declare const PhoneFieldWithController: import("react").ForwardRefExoticComponent<PhoneFieldWithControllerProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -1,13 +1,6 @@
1
- import React, { FocusEventHandler } from "react";
2
- import { SingleValue } from "react-select";
1
+ import React from "react";
3
2
  import { BaseInputProps } from "../BaseInput";
4
3
  type BaseInputExposedProps = Omit<BaseInputProps, "actions">;
5
- export interface PhoneNumberValue {
6
- phone?: string;
7
- national?: string;
8
- countryCode?: string;
9
- isValid?: boolean;
10
- }
11
4
  export interface PhoneInputProps extends BaseInputExposedProps {
12
5
  /**
13
6
  * To disable the action button.
@@ -15,40 +8,9 @@ export interface PhoneInputProps extends BaseInputExposedProps {
15
8
  * @default false
16
9
  * @memberof PhoneInputProps
17
10
  * @example
18
- * <PhoneInput disableAction />
11
+ // * <PhoneInput disableAction />
19
12
  */
20
13
  disableAction?: boolean;
21
- /**
22
- * On blur handler for country code component.
23
- */
24
- onBlurCountryCode?: FocusEventHandler<HTMLInputElement> | undefined;
25
- /**
26
- * On change handler for country code component.
27
- */
28
- onChangeCountryCode?: (value: SingleValue<{
29
- label: string;
30
- value: string;
31
- }>) => void;
32
- /**
33
- * On click handler for country code component.
34
- */
35
- onClickCountryCode?: (value: SingleValue<{
36
- label: string;
37
- value: string;
38
- }>) => void;
39
- /**
40
- * A placeholder value for country code.
41
- */
42
- countryCodePlaceholder?: string;
43
- /**
44
- * An custom handler will be called when country code select or phone number input lost focus
45
- */
46
- onFieldsBlur?: ({ phone, national, countryCode }: PhoneNumberValue) => void;
47
- /**
48
- * An custom handler will be called when country code select or phone number input were changed
49
- */
50
- onChangeValue?: ({ phone, national, countryCode }: PhoneNumberValue) => void;
51
- isCountryCodeClearable?: boolean;
52
14
  /**
53
15
  * A ReactNode to render at the end of the input field before the addonAfter.
54
16
  * Mainly meant for the icon button actions for special input types.
@@ -1,14 +1,9 @@
1
1
  import { ValidatePhoneNumberLengthResult } from "libphonenumber-js";
2
2
  export type PhoneInputValidationError = "REQUIRED" | "REQUIRED_COUNTRY" | "INVALID_NUMBER" | ValidatePhoneNumberLengthResult | undefined;
3
- export interface PhoneNumberValueForValidation {
4
- phone?: string | undefined | null;
5
- national?: string | undefined | null;
6
- countryCode?: string | undefined | null;
7
- }
8
3
  /**
9
4
  * Validates a phone number
10
5
  */
11
- export declare const validatePhoneNumber: ({ phone, countryCode, national, }: PhoneNumberValueForValidation) => PhoneInputValidationError;
6
+ export declare const validatePhoneNumber: (phoneNumber: string | undefined) => PhoneInputValidationError;
12
7
  /**
13
8
  * Checks if the country code is valid and required
14
9
  */
package/src/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from "./components/OptionCard/OptionCard";
14
14
  export * from "./components/PasswordField";
15
15
  export * from "./components/PasswordInput/PasswordInput";
16
16
  export * from "./components/PhoneField/PhoneField";
17
+ export * from "./components/PhoneFieldWithController/PhoneFieldWithController";
17
18
  export * from "./components/PhoneInput/PhoneInput";
18
19
  export * from "./components/PhoneInput/PhoneInputValidationUtils";
19
20
  export * from "./components/PhoneInput/PhoneNumberUtilities";
@@ -38,3 +39,5 @@ export * from "./components/UrlField/UrlField";
38
39
  export * from "./components/UrlInput/UrlInput";
39
40
  export * from "./utilities/emailUtils";
40
41
  export * from "./utilities/usePhoneInput";
42
+ export * from "./utilities/useZodValidators";
43
+ export * from "./utilities/useGetPhoneValidationRules";
@@ -0,0 +1,12 @@
1
+ import { RegisterOptions } from "react-hook-form";
2
+ /**
3
+ * Custom hook to get phone number validation rules.
4
+ *
5
+ * @returns {object} An object containing the `getPhoneNumberValidationRules` method.
6
+ * @example
7
+ * const { getPhoneNumberValidationRules } = useGetPhoneValidationRules();
8
+ * const validationRules = getPhoneNumberValidationRules(false);
9
+ */
10
+ export declare const useGetPhoneValidationRules: () => {
11
+ getPhoneNumberValidationRules: (skipValidation?: boolean) => RegisterOptions;
12
+ };
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Provides Zod validation schemas with custom validators.
4
+ *
5
+ * @returns {object} An object containing various Zod validators.
6
+ * @example
7
+ * const { ZodPhoneValidator } = useZodValidators();
8
+ */
9
+ export declare const useZodValidators: () => {
10
+ ZodPhoneValidator: z.ZodEffects<z.ZodString, string, string>;
11
+ };