mui-custom-form 0.1.4 → 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.4",
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
  )
package/demo/README.md DELETED
@@ -1,27 +0,0 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## Expanding the ESLint configuration
11
-
12
- If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13
-
14
- - Configure the top-level `parserOptions` property like this:
15
-
16
- ```js
17
- parserOptions: {
18
- ecmaVersion: 'latest',
19
- sourceType: 'module',
20
- project: ['./tsconfig.json', './tsconfig.node.json'],
21
- tsconfigRootDir: __dirname,
22
- },
23
- ```
24
-
25
- - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
26
- - Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
27
- - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
package/demo/package.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "name": "demo",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "tsc && vite build",
9
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10
- "preview": "vite preview"
11
- },
12
- "dependencies": {
13
- "@hookform/resolvers": "^3.2.0",
14
- "react": "^18.2.0",
15
- "react-dom": "^18.2.0",
16
- "react-hook-form": "^7.45.4",
17
- "zod": "^3.22.2"
18
- },
19
- "devDependencies": {
20
- "@types/react": "^18.2.15",
21
- "@types/react-dom": "^18.2.7",
22
- "@typescript-eslint/eslint-plugin": "^6.0.0",
23
- "@typescript-eslint/parser": "^6.0.0",
24
- "@vitejs/plugin-react": "^4.0.3",
25
- "eslint": "^8.45.0",
26
- "eslint-plugin-react-hooks": "^4.6.0",
27
- "eslint-plugin-react-refresh": "^0.4.3",
28
- "typescript": "^5.0.2",
29
- "vite": "^4.4.5"
30
- }
31
- }