mui-custom-form 0.1.5 → 0.1.6

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.
@@ -17,7 +17,7 @@ export interface ICustomField<T = string> {
17
17
  interface ICustomForm {
18
18
  fieldsGroups: ICustomField<any>[][];
19
19
  onSubmit: ReturnType<this["formControl"]["handleSubmit"]>;
20
- formControl: ReturnType<typeof useForm>;
20
+ formControl: ReturnType<typeof useForm<any>>;
21
21
  submitButton?: boolean;
22
22
  otherProps?: any;
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mui-custom-form",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A versatile React form component utilizing MUI components and react-hook-form.",
5
5
  "main": "dist/CustomForm.js",
6
6
  "types": "dist/CustomForm.d.ts",
@@ -28,6 +28,9 @@
28
28
  "peerDependencies": {
29
29
  "@mui/material": "5.14.2",
30
30
  "@mui/x-date-pickers": "^6.10.2",
31
+ "date-fns": "^2.30.0",
32
+ "dayjs": "^1.11.9",
33
+ "moment": "^2.29.4",
31
34
  "react-hook-form": "^7.45.2"
32
35
  },
33
36
  "devDependencies": {
@@ -36,5 +39,6 @@
36
39
  "@types/node": "^20.5.1",
37
40
  "@types/react": "^18.2.20",
38
41
  "typescript": "^5.1.6"
39
- }
42
+ },
43
+ "dependencies": {}
40
44
  }
package/readme.md CHANGED
@@ -55,7 +55,7 @@ import { CustomForm } from "your-package-name"
55
55
  const MyComponent = () => {
56
56
  const formControl = useForm()
57
57
 
58
- const fieldsGroups = [
58
+ const fieldsGroups: ICustomField[][] = [
59
59
  [
60
60
  {
61
61
  label: "Username",
@@ -71,14 +71,52 @@ const MyComponent = () => {
71
71
  ],
72
72
  ]
73
73
 
74
- const handleSubmit = (data) => {
74
+ const handleSubmit = (data: unknown) => {
75
75
  console.log(data)
76
76
  }
77
77
 
78
78
  return (
79
79
  <CustomForm
80
80
  fieldsGroups={fieldsGroups}
81
- onSubmit={handleSubmit}
81
+ onSubmit={formControl.handleSubmit(handleSubmit)}
82
+ formControl={formControl}
83
+ />
84
+ )
85
+ }
86
+
87
+ export default MyComponent
88
+ ```
89
+
90
+ Usage with zod
91
+
92
+ ```typescript
93
+ const MyComponent = () => {
94
+ const formControl = useForm()
95
+
96
+ const fieldsGroups: ICustomField[][] = [
97
+ [
98
+ {
99
+ label: "Username",
100
+ name: "username",
101
+ type: "text",
102
+ required: true,
103
+ },
104
+ {
105
+ label: "Birthdate",
106
+ name: "birthdate",
107
+ type: "date",
108
+ },
109
+ ],
110
+ ]
111
+
112
+ const handleSubmit = (data: unknown) => {
113
+ console.log(data)
114
+ }
115
+
116
+ return (
117
+ <CustomForm
118
+ fieldsGroups={fieldsGroups}
119
+ onSubmit={formControl.handleSubmit(handleSubmit)}
82
120
  formControl={formControl}
83
121
  />
84
122
  )