@@ -14,7 +14,7 @@ export type ExtraProps = {
14
14
const getType = (
15
15
field : z . ZodTypeAny
16
16
) : 'array' | 'object' | 'number' | 'date' | 'select' | 'text' => {
17
- if ( field . _def . typeName === 'ZodDefault' ) {
17
+ if ( [ 'ZodDefault' , 'ZodOptional' ] . includes ( field . _def . typeName ) ) {
18
18
return getType ( field . _def . innerType )
19
19
}
20
20
@@ -27,6 +27,7 @@ const getType = (
27
27
return 'number'
28
28
case 'ZodDate' :
29
29
return 'date'
30
+ case 'ZodNativeEnum' :
30
31
case 'ZodEnum' :
31
32
return 'select'
32
33
case 'ZodString' :
@@ -73,6 +74,8 @@ export const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {
73
74
props . options = def . values . map ( ( value : string ) => {
74
75
return { label : value , value }
75
76
} )
77
+ } else if ( def . typeName === 'ZodNativeEnum' ) {
78
+ props . options = Object . entries ( def . values ) . map ( ( [ label , value ] ) => ( { label, value : value as string } ) )
76
79
}
77
80
78
81
const meta = field . description && zodParseMeta ( field . description )
@@ -81,6 +84,8 @@ export const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {
81
84
name,
82
85
label : meta ?. label || field . description || name ,
83
86
type : meta ?. type || getType ( field ) ,
87
+ help : meta ?. help ,
88
+ placeholder : meta ?. placeholder ,
84
89
defaultValue : field . _def . defaultValue ?.( ) ,
85
90
...props ,
86
91
} )
@@ -108,22 +113,37 @@ export interface ZodMeta {
108
113
* The label of the field
109
114
*/
110
115
label : string
116
+
111
117
/**
112
118
* The type of the field
113
119
*/
114
120
type ?: string
121
+
122
+ /**
123
+ * The placeholder of the field
124
+ */
125
+ placeholder ?: string
126
+
127
+ /**
128
+ * The help text of the field
129
+ */
130
+ help ?: string
131
+
115
132
/**
116
133
* Object field column count
117
134
*/
118
135
columns ?: number
136
+
119
137
/**
120
138
* Array field min rows
121
139
*/
122
140
min ?: number
141
+
123
142
/**
124
143
* Array field max rows
125
144
*/
126
145
max ?: number
146
+
127
147
[ key : string ] : any
128
148
}
129
149
0 commit comments