@arturton/react-form-constructor 0.1.5 → 0.2.0

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/dist/index.d.mts CHANGED
@@ -2,11 +2,21 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { FieldValues, UseFormRegister, FieldErrors, Control } from 'react-hook-form';
3
3
  import React$1, { ReactNode } from 'react';
4
4
 
5
- type FormField<T extends object = any> = {
5
+ type FormFieldType = "text" | "password" | "email" | "number" | "date" | "textarea" | "select" | "checkbox" | "radio" | "file" | "range" | "mask";
6
+ interface SelectOption$1 {
7
+ value: string | number;
8
+ label: string;
9
+ }
10
+ interface RadioOption {
11
+ value: string | number;
6
12
  label: string;
7
- placeholder: string;
13
+ }
14
+ type FormField<T extends object = any> = {
8
15
  key: keyof T;
9
- required?: string;
16
+ label?: string;
17
+ placeholder?: string;
18
+ type?: FormFieldType;
19
+ required?: string | boolean;
10
20
  minLength?: {
11
21
  value: number;
12
22
  message: string;
@@ -19,27 +29,44 @@ type FormField<T extends object = any> = {
19
29
  value: RegExp;
20
30
  message: string;
21
31
  };
22
- validate?: any;
23
- type?: string;
32
+ validate?: (value: any) => boolean | string;
24
33
  maska?: {
25
34
  required: string;
26
35
  format: string;
27
36
  mask: string;
28
37
  };
29
- textarea?: boolean;
30
- register?: {
31
- [key: string]: any;
32
- };
33
- inputClass?: any;
34
- errorClass?: any;
35
- labelClass?: any;
38
+ options?: SelectOption$1[];
39
+ multiple?: boolean;
40
+ radioOptions?: RadioOption[];
41
+ defaultChecked?: boolean;
42
+ accept?: string;
43
+ min?: number;
44
+ max?: number;
45
+ step?: number;
46
+ showValue?: boolean;
47
+ containerClass?: string;
48
+ labelClass?: string;
49
+ inputClass?: string;
50
+ errorClass?: string;
51
+ classNameError?: string;
52
+ render?: (props: any) => React.ReactNode;
53
+ disabled?: boolean;
54
+ [key: string]: any;
36
55
  };
37
56
  type FormLayoutProps<T extends object = any> = {
57
+ formData: FormField<T>[];
38
58
  funSubmit: (data: T) => void;
59
+ defaultValues?: T | Partial<T>;
60
+ onError?: (errors: any) => void;
39
61
  formClass?: string;
62
+ containerClass?: string;
40
63
  buttonClass?: string;
41
64
  buttonName?: string;
42
- formData: FormField<T>[];
65
+ labelClass?: string;
66
+ inputClass?: string;
67
+ errorClass?: string;
68
+ submitButtonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>;
69
+ disabledOnError?: boolean;
43
70
  };
44
71
  type FormProviderProps<T extends object = any> = {
45
72
  setFormApi?: (formMethods: any) => void;
@@ -55,7 +82,26 @@ type FormContextType<T extends FieldValues = any> = {
55
82
  values?: T;
56
83
  };
57
84
 
58
- declare function FormLayout<T extends object = any>({ formData, funSubmit, formClass, buttonClass, buttonName, }: FormLayoutProps<T>): react_jsx_runtime.JSX.Element;
85
+ /**
86
+ * FormLayout - конфигурационный способ создания форм через JSON
87
+ * @example
88
+ * const fields: FormField<LoginForm>[] = [
89
+ * {
90
+ * key: "email",
91
+ * label: "Email",
92
+ * type: "email",
93
+ * placeholder: "your@email.com",
94
+ * required: "Email is required",
95
+ * },
96
+ * ];
97
+ *
98
+ * <FormLayout<LoginForm>
99
+ * formData={fields}
100
+ * funSubmit={(data) => console.log(data)}
101
+ * buttonName="Login"
102
+ * />
103
+ */
104
+ declare function FormLayout<T extends object = any>({ formData, funSubmit, defaultValues, onError, formClass, containerClass, buttonClass, buttonName, labelClass, inputClass, errorClass, submitButtonProps, disabledOnError, }: FormLayoutProps<T>): react_jsx_runtime.JSX.Element;
59
105
 
60
106
  declare function InputForm({ register, type, placeholder, error, name, label, required, control, maska, inputClass, labelClass, errorClass, }: {
61
107
  register: any;
@@ -222,4 +268,4 @@ declare function FormLabel({ children, className, classNameError, }: {
222
268
  classNameError?: string;
223
269
  }): react_jsx_runtime.JSX.Element;
224
270
 
225
- export { FormButton, FormCheckbox, type FormContextType, FormDate, FormError, type FormField, FormFileInput, FormInput, FormInputLayout, FormLabel, FormLayout, type FormLayoutProps, FormMaskedInput, FormNumber, FormPasswordInput, FormProvider, FormRadio, FormRange, FormSelect, FormTextarea, InputForm, useFormContext };
271
+ export { FormButton, FormCheckbox, type FormContextType, FormDate, FormError, type FormField, FormFileInput, FormInput, FormInputLayout, FormLabel, FormLayout, type FormLayoutProps, FormMaskedInput, FormNumber, FormPasswordInput, FormProvider, FormRadio, FormRange, FormSelect, FormTextarea, InputForm, type RadioOption, type SelectOption$1 as SelectOption, useFormContext };
package/dist/index.d.ts CHANGED
@@ -2,11 +2,21 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { FieldValues, UseFormRegister, FieldErrors, Control } from 'react-hook-form';
3
3
  import React$1, { ReactNode } from 'react';
4
4
 
5
- type FormField<T extends object = any> = {
5
+ type FormFieldType = "text" | "password" | "email" | "number" | "date" | "textarea" | "select" | "checkbox" | "radio" | "file" | "range" | "mask";
6
+ interface SelectOption$1 {
7
+ value: string | number;
8
+ label: string;
9
+ }
10
+ interface RadioOption {
11
+ value: string | number;
6
12
  label: string;
7
- placeholder: string;
13
+ }
14
+ type FormField<T extends object = any> = {
8
15
  key: keyof T;
9
- required?: string;
16
+ label?: string;
17
+ placeholder?: string;
18
+ type?: FormFieldType;
19
+ required?: string | boolean;
10
20
  minLength?: {
11
21
  value: number;
12
22
  message: string;
@@ -19,27 +29,44 @@ type FormField<T extends object = any> = {
19
29
  value: RegExp;
20
30
  message: string;
21
31
  };
22
- validate?: any;
23
- type?: string;
32
+ validate?: (value: any) => boolean | string;
24
33
  maska?: {
25
34
  required: string;
26
35
  format: string;
27
36
  mask: string;
28
37
  };
29
- textarea?: boolean;
30
- register?: {
31
- [key: string]: any;
32
- };
33
- inputClass?: any;
34
- errorClass?: any;
35
- labelClass?: any;
38
+ options?: SelectOption$1[];
39
+ multiple?: boolean;
40
+ radioOptions?: RadioOption[];
41
+ defaultChecked?: boolean;
42
+ accept?: string;
43
+ min?: number;
44
+ max?: number;
45
+ step?: number;
46
+ showValue?: boolean;
47
+ containerClass?: string;
48
+ labelClass?: string;
49
+ inputClass?: string;
50
+ errorClass?: string;
51
+ classNameError?: string;
52
+ render?: (props: any) => React.ReactNode;
53
+ disabled?: boolean;
54
+ [key: string]: any;
36
55
  };
37
56
  type FormLayoutProps<T extends object = any> = {
57
+ formData: FormField<T>[];
38
58
  funSubmit: (data: T) => void;
59
+ defaultValues?: T | Partial<T>;
60
+ onError?: (errors: any) => void;
39
61
  formClass?: string;
62
+ containerClass?: string;
40
63
  buttonClass?: string;
41
64
  buttonName?: string;
42
- formData: FormField<T>[];
65
+ labelClass?: string;
66
+ inputClass?: string;
67
+ errorClass?: string;
68
+ submitButtonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>;
69
+ disabledOnError?: boolean;
43
70
  };
44
71
  type FormProviderProps<T extends object = any> = {
45
72
  setFormApi?: (formMethods: any) => void;
@@ -55,7 +82,26 @@ type FormContextType<T extends FieldValues = any> = {
55
82
  values?: T;
56
83
  };
57
84
 
58
- declare function FormLayout<T extends object = any>({ formData, funSubmit, formClass, buttonClass, buttonName, }: FormLayoutProps<T>): react_jsx_runtime.JSX.Element;
85
+ /**
86
+ * FormLayout - конфигурационный способ создания форм через JSON
87
+ * @example
88
+ * const fields: FormField<LoginForm>[] = [
89
+ * {
90
+ * key: "email",
91
+ * label: "Email",
92
+ * type: "email",
93
+ * placeholder: "your@email.com",
94
+ * required: "Email is required",
95
+ * },
96
+ * ];
97
+ *
98
+ * <FormLayout<LoginForm>
99
+ * formData={fields}
100
+ * funSubmit={(data) => console.log(data)}
101
+ * buttonName="Login"
102
+ * />
103
+ */
104
+ declare function FormLayout<T extends object = any>({ formData, funSubmit, defaultValues, onError, formClass, containerClass, buttonClass, buttonName, labelClass, inputClass, errorClass, submitButtonProps, disabledOnError, }: FormLayoutProps<T>): react_jsx_runtime.JSX.Element;
59
105
 
60
106
  declare function InputForm({ register, type, placeholder, error, name, label, required, control, maska, inputClass, labelClass, errorClass, }: {
61
107
  register: any;
@@ -222,4 +268,4 @@ declare function FormLabel({ children, className, classNameError, }: {
222
268
  classNameError?: string;
223
269
  }): react_jsx_runtime.JSX.Element;
224
270
 
225
- export { FormButton, FormCheckbox, type FormContextType, FormDate, FormError, type FormField, FormFileInput, FormInput, FormInputLayout, FormLabel, FormLayout, type FormLayoutProps, FormMaskedInput, FormNumber, FormPasswordInput, FormProvider, FormRadio, FormRange, FormSelect, FormTextarea, InputForm, useFormContext };
271
+ export { FormButton, FormCheckbox, type FormContextType, FormDate, FormError, type FormField, FormFileInput, FormInput, FormInputLayout, FormLabel, FormLayout, type FormLayoutProps, FormMaskedInput, FormNumber, FormPasswordInput, FormProvider, FormRadio, FormRange, FormSelect, FormTextarea, InputForm, type RadioOption, type SelectOption$1 as SelectOption, useFormContext };