@react-fabric/form 1.0.0-beta.31 → 1.0.0-beta.33

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.
Files changed (61) hide show
  1. package/dist/cjs/builder/FileField.js +4 -4
  2. package/dist/cjs/builder/FormField.js +41 -31
  3. package/dist/cjs/builder/SchemaEditor.js +428 -0
  4. package/dist/cjs/form/Controller.js +1 -1
  5. package/dist/cjs/form/Form.js +3 -4
  6. package/dist/cjs/hooks/useFormBuilder.js +27 -15
  7. package/dist/cjs/index.js +8 -2
  8. package/dist/cjs/input/Checkbox.js +4 -3
  9. package/dist/cjs/input/DateInput.js +183 -0
  10. package/dist/cjs/input/Field.js +1 -1
  11. package/dist/cjs/input/{Range.js → RangeSlider.js} +2 -2
  12. package/dist/cjs/input/Switch.js +4 -3
  13. package/dist/cjs/internal/Field.module.css +1 -1
  14. package/dist/cjs/internal/InputWrapper.js +6 -4
  15. package/dist/cjs/types/schema.js +40 -0
  16. package/dist/esm/builder/FileField.js +4 -4
  17. package/dist/esm/builder/FormField.js +41 -31
  18. package/dist/esm/builder/SchemaEditor.js +428 -0
  19. package/dist/esm/form/Controller.js +1 -1
  20. package/dist/esm/form/Form.js +4 -5
  21. package/dist/esm/hooks/useFormBuilder.js +25 -13
  22. package/dist/esm/index.js +4 -1
  23. package/dist/esm/input/Checkbox.js +4 -3
  24. package/dist/esm/input/DateInput.js +183 -0
  25. package/dist/esm/input/Field.js +1 -1
  26. package/dist/esm/input/{Range.js → RangeSlider.js} +2 -2
  27. package/dist/esm/input/Switch.js +4 -3
  28. package/dist/esm/internal/Field.module.css +1 -1
  29. package/dist/esm/internal/InputWrapper.js +6 -4
  30. package/dist/esm/types/schema.js +40 -0
  31. package/dist/types/builder/FileField.d.ts +2 -2
  32. package/dist/types/builder/FormField.d.ts +3 -1
  33. package/dist/types/builder/SchemaEditor.d.ts +10 -0
  34. package/dist/types/form/Controller.d.ts +1 -1
  35. package/dist/types/form/Form.d.ts +5 -1
  36. package/dist/types/hooks/useFormBuilder.d.ts +3 -1
  37. package/dist/types/index.d.ts +4 -2
  38. package/dist/types/input/Checkbox.d.ts +4 -3
  39. package/dist/types/input/DateInput.d.ts +19 -0
  40. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
  41. package/dist/types/input/Switch.d.ts +1 -1
  42. package/dist/types/internal/InputWrapper.d.ts +1 -1
  43. package/dist/types/types/index.d.ts +6 -2
  44. package/dist/types/types/schema.d.ts +52 -33
  45. package/package.json +5 -4
  46. package/src/builder/FileField.tsx +5 -4
  47. package/src/builder/FormField.tsx +42 -29
  48. package/src/builder/SchemaEditor.tsx +441 -0
  49. package/src/form/Controller.tsx +2 -2
  50. package/src/form/Form.tsx +6 -4
  51. package/src/hooks/useFormBuilder.tsx +29 -15
  52. package/src/index.ts +5 -2
  53. package/src/input/Checkbox.tsx +4 -3
  54. package/src/input/DateInput.tsx +248 -0
  55. package/src/input/Field.tsx +2 -1
  56. package/src/input/{Range.tsx → RangeSlider.tsx} +1 -1
  57. package/src/input/Switch.tsx +2 -0
  58. package/src/internal/Field.module.css +12 -1
  59. package/src/internal/InputWrapper.tsx +7 -2
  60. package/src/types/index.ts +8 -4
  61. package/src/types/schema.ts +65 -41
@@ -0,0 +1,441 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import {
25
+ Button,
26
+ Collapsable,
27
+ Content,
28
+ CoreIcons,
29
+ Footer,
30
+ Modal,
31
+ ToggleButtonGroup,
32
+ useOverlayService,
33
+ } from "@react-fabric/core";
34
+ import { EMPTY_ARRAY } from "@react-fabric/utilities";
35
+ import { Fragment, useCallback, useEffect, useRef, useState } from "react";
36
+ import { Controller } from "../form/Controller";
37
+ import { Form, type FormRef } from "../form/Form";
38
+ import { ArrayInput } from "../input/ArrayInput";
39
+ import { Checkbox } from "../input/Checkbox";
40
+ import { DateInput } from "../input/DateInput";
41
+ import { Field } from "../input/Field";
42
+ import { Input } from "../input/Input";
43
+ import { Number } from "../input/Number";
44
+ import { Select } from "../select/Select";
45
+ import {
46
+ DATA_TYPES,
47
+ type DateSchema,
48
+ type DefaultSchema,
49
+ type FormSchema,
50
+ type NumberSchema,
51
+ type SchemaDef,
52
+ type StringSchema,
53
+ type ValueType,
54
+ } from "../types/schema";
55
+
56
+ interface Props {
57
+ schemaDef: FormSchema;
58
+ allowRemove?: boolean;
59
+ acceptableTypes?: DATA_TYPES[];
60
+
61
+ optionLists?: string[];
62
+
63
+ onChange: (schema: FormSchema) => void;
64
+ }
65
+
66
+ const CUSTOM_LIST = "--CUSTOM--";
67
+
68
+ const SchemaField = ({
69
+ field,
70
+ getModel,
71
+ optionLists = EMPTY_ARRAY,
72
+ allowRemove,
73
+ onTypeChange,
74
+ acceptableTypes,
75
+ }: {
76
+ field: string;
77
+ getModel: () => KeyValue;
78
+ onTypeChange: (val: KeyValue) => void;
79
+ } & Omit<Props, "schemaDef" | "onChange">) => {
80
+ const [type, setType] = useState<DATA_TYPES>();
81
+ const [multiple, setMultiple] = useState(false);
82
+ const [hasOptions, setHasOptions] = useState(false);
83
+ const [customOptions, setCustomOptions] = useState(false);
84
+
85
+ const [OptionModal, openOptionModal] = useOverlayService((props) => (
86
+ <Modal {...props}>
87
+ <Content>
88
+ <ArrayInput name={`${field}.options`} onAdd={() => String("")}>
89
+ <Controller>
90
+ <Input />
91
+ </Controller>
92
+ </ArrayInput>
93
+ </Content>
94
+ <Footer
95
+ flex
96
+ justify="end"
97
+ className="sticky bottom-0 border-t bg-base px-6 py-2"
98
+ >
99
+ <Button variant="link" onClick={props.onClose}>
100
+ Close
101
+ </Button>
102
+ </Footer>
103
+ </Modal>
104
+ ));
105
+
106
+ useEffect(() => {
107
+ setTimeout(() => {
108
+ const model = getModel();
109
+ setType(model.datatype);
110
+ setMultiple(model.multiple);
111
+ setHasOptions(!!model.optionList);
112
+ setCustomOptions(model.optionList === CUSTOM_LIST);
113
+ }, 10);
114
+ }, []);
115
+
116
+ useEffect(() => {
117
+ if (type) {
118
+ const modelRef = getModel();
119
+ let reset = {
120
+ datatype: type,
121
+ id: field,
122
+ label: modelRef.label,
123
+ defaultValue: modelRef.defaultValue,
124
+ required: modelRef.required,
125
+ multiple: type === DATA_TYPES.AVATAR ? false : modelRef.multiple,
126
+ minItems: modelRef.minItems,
127
+ maxItems: modelRef.maxItems,
128
+ } as DefaultSchema & ValueType;
129
+ if (type === DATA_TYPES.STRING) {
130
+ reset = Object.assign(reset, {
131
+ optionList: modelRef.optionList,
132
+ options: modelRef.options,
133
+ regex: modelRef.regex,
134
+ } as StringSchema);
135
+ } else if (type === DATA_TYPES.DATE) {
136
+ reset = Object.assign(reset, {
137
+ type: "date",
138
+ } as DateSchema);
139
+ } else if (type === DATA_TYPES.NUMBER || type === DATA_TYPES.RANGE) {
140
+ reset = Object.assign(reset, {
141
+ min: modelRef.min,
142
+ max: modelRef.max,
143
+ step: modelRef.step,
144
+ } as NumberSchema);
145
+ }
146
+ if (type === DATA_TYPES.AVATAR) {
147
+ setMultiple(false);
148
+ }
149
+ onTypeChange(reset);
150
+ }
151
+ }, [type]);
152
+
153
+ return (
154
+ <Collapsable key={field} open>
155
+ <div className="flex flex-nowrap group/field">
156
+ <span className="flex-1 truncate">{field}</span>
157
+ {allowRemove && (
158
+ <Button
159
+ size="sm"
160
+ color="danger"
161
+ variant="link"
162
+ aria-label="Delete"
163
+ stopPropagation
164
+ icon={CoreIcons.trash}
165
+ className="invisible group-hover/field:visible"
166
+ />
167
+ )}
168
+ </div>
169
+ <div className="flex flex-col gap-1 pb-4">
170
+ <Controller name={`${field}.datatype`}>
171
+ <Select
172
+ inline
173
+ label="Type"
174
+ placeholder="Data type"
175
+ options={acceptableTypes}
176
+ onChange={(val) => setType(val as unknown as DATA_TYPES)}
177
+ />
178
+ </Controller>
179
+ <Controller name={`${field}.label`}>
180
+ <Input
181
+ inline
182
+ label="Label"
183
+ allowClear
184
+ placeholder="Label..."
185
+ decorateEndShowWhenEmpty
186
+ decorateEnd={
187
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
188
+ }
189
+ />
190
+ </Controller>
191
+ {type === DATA_TYPES.STRING && (
192
+ <Fragment>
193
+ <Controller name={`${field}.regex`}>
194
+ <Input
195
+ inline
196
+ label="Regex validation"
197
+ allowClear
198
+ placeholder="Regex value..."
199
+ decorateEndShowWhenEmpty
200
+ decorateEnd={
201
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
202
+ }
203
+ />
204
+ </Controller>
205
+ <Field inline label="Option list">
206
+ <Controller name={`${field}.optionList`}>
207
+ <Select
208
+ allowClear
209
+ options={[CUSTOM_LIST, ...optionLists]}
210
+ onChange={(v) => setCustomOptions(v === CUSTOM_LIST)}
211
+ />
212
+ </Controller>
213
+ {customOptions && (
214
+ <Button
215
+ icon={CoreIcons.list}
216
+ aria-label="Custom options"
217
+ onClick={() => {
218
+ void openOptionModal();
219
+ }}
220
+ />
221
+ )}
222
+ </Field>
223
+ {OptionModal}
224
+ </Fragment>
225
+ )}
226
+ {type === DATA_TYPES.FILE && (
227
+ <Fragment>
228
+ <Controller name={`${field}.accept`}>
229
+ <Input
230
+ inline
231
+ label="Accept types"
232
+ allowClear
233
+ placeholder="Accept value..."
234
+ decorateEndShowWhenEmpty
235
+ decorateEnd={
236
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
237
+ }
238
+ />
239
+ </Controller>
240
+ </Fragment>
241
+ )}
242
+ {[DATA_TYPES.NUMBER, DATA_TYPES.RANGE].includes(
243
+ type as unknown as DATA_TYPES,
244
+ ) && (
245
+ <Fragment>
246
+ <Controller name={`${field}.min`}>
247
+ <Number
248
+ inline
249
+ label="Min value"
250
+ allowClear
251
+ placeholder="Minimum value..."
252
+ decorateEndShowWhenEmpty
253
+ decorateEnd={
254
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
255
+ }
256
+ />
257
+ </Controller>
258
+ <Controller name={`${field}.max`}>
259
+ <Number
260
+ inline
261
+ label="Max value"
262
+ allowClear
263
+ placeholder="Maximum value..."
264
+ decorateEndShowWhenEmpty
265
+ decorateEnd={
266
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
267
+ }
268
+ />
269
+ </Controller>
270
+ <Controller name={`${field}.step`}>
271
+ <Number
272
+ inline
273
+ label="Step value"
274
+ allowClear
275
+ placeholder="Step value..."
276
+ decorateEndShowWhenEmpty
277
+ decorateEnd={
278
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
279
+ }
280
+ />
281
+ </Controller>
282
+ </Fragment>
283
+ )}
284
+ {type === DATA_TYPES.DATE && (
285
+ <Fragment>
286
+ <Field inline label="Type" plain>
287
+ <Controller name={`${field}.type`}>
288
+ <ToggleButtonGroup value="" fullWidth className="flex-1">
289
+ <Button className="flex-1" value="date">
290
+ Date
291
+ </Button>
292
+ <Button className="flex-1" value="datetime">
293
+ Date Time
294
+ </Button>
295
+ </ToggleButtonGroup>
296
+ </Controller>
297
+ </Field>
298
+ <Controller name={`${field}.min`}>
299
+ <DateInput
300
+ inline
301
+ label="Min value"
302
+ allowClear
303
+ placeholder="Minimum value..."
304
+ decorateEndShowWhenEmpty
305
+ decorateEnd={
306
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
307
+ }
308
+ />
309
+ </Controller>
310
+ <Controller name={`${field}.max`}>
311
+ <DateInput
312
+ inline
313
+ label="Max value"
314
+ allowClear
315
+ placeholder="Maximum value..."
316
+ decorateEndShowWhenEmpty
317
+ decorateEnd={
318
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
319
+ }
320
+ />
321
+ </Controller>
322
+ </Fragment>
323
+ )}
324
+ <Field label=" " inline plain>
325
+ <Controller name={`${field}.required`}>
326
+ <Checkbox label="Required" />
327
+ </Controller>
328
+ {type !== DATA_TYPES.AVATAR && (
329
+ <Controller name={`${field}.multiple`}>
330
+ <Checkbox label="Multiple" onChange={setMultiple} />
331
+ </Controller>
332
+ )}
333
+ {hasOptions && (
334
+ <Controller name={`${field}.allowCustom`}>
335
+ <Checkbox label="Allow custom value" />
336
+ </Controller>
337
+ )}
338
+ </Field>
339
+ {multiple && (
340
+ <Fragment>
341
+ <Controller name={`${field}.minItems`}>
342
+ <Number
343
+ inline
344
+ label="Min items"
345
+ allowClear
346
+ placeholder="Minimum items..."
347
+ decorateEndShowWhenEmpty
348
+ decorateEnd={
349
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
350
+ }
351
+ />
352
+ </Controller>
353
+ <Controller name={`${field}.maxItems`}>
354
+ <Number
355
+ inline
356
+ label="Max items"
357
+ allowClear
358
+ placeholder="Maximum items..."
359
+ decorateEndShowWhenEmpty
360
+ decorateEnd={
361
+ <span className="text-sm text-muted/50 px-1">OPTIONAL</span>
362
+ }
363
+ />
364
+ </Controller>
365
+ </Fragment>
366
+ )}
367
+ </div>
368
+ </Collapsable>
369
+ );
370
+ };
371
+
372
+ export const SchemaEditor = ({
373
+ schemaDef,
374
+ allowRemove,
375
+ acceptableTypes,
376
+ optionLists = EMPTY_ARRAY,
377
+ onChange,
378
+ }: Props) => {
379
+ const formRef = useRef<FormRef<KeyValue>>(null);
380
+ const schemaRef = useRef<KeyValue>({});
381
+ const [schema, setSchema] = useState<KeyValue<SchemaDef>>({});
382
+ const [schemaFields, setSchemaFields] = useState<string[]>([]);
383
+
384
+ useEffect(() => {
385
+ const schemaMap = Object.fromEntries(
386
+ schemaDef.map((schema) => [schema.id, schema]),
387
+ );
388
+
389
+ const schema = Object.fromEntries(
390
+ Object.keys(schemaMap).map((field) => [
391
+ field,
392
+ schemaRef.current[field] ?? schemaMap[field],
393
+ ]),
394
+ );
395
+ setSchema(schema);
396
+ setSchemaFields(Object.keys(schema));
397
+ }, [schemaDef]);
398
+
399
+ const handleChange = useCallback((model: KeyValue<SchemaDef>) => {
400
+ onChange?.(Object.values(model));
401
+ }, []);
402
+
403
+ const handleTypeChange = useCallback((field: string, val: KeyValue) => {
404
+ formRef.current?.setValue(field, val);
405
+ }, []);
406
+
407
+ return (
408
+ <Form
409
+ formRef={formRef}
410
+ values={schema}
411
+ defaultValues={schema}
412
+ onSubmit={handleChange}
413
+ >
414
+ <Content className="divide-y">
415
+ {schemaFields.map((field) => (
416
+ <SchemaField
417
+ key={field}
418
+ field={field}
419
+ allowRemove={allowRemove}
420
+ optionLists={optionLists}
421
+ getModel={() => formRef.current?.getValues()[field]}
422
+ onTypeChange={(val: KeyValue) => handleTypeChange(field, val)}
423
+ acceptableTypes={acceptableTypes ?? Object.values(DATA_TYPES)}
424
+ />
425
+ ))}
426
+ </Content>
427
+ <Footer
428
+ flex
429
+ justify="end"
430
+ className="sticky bottom-0 border-t bg-base px-6 py-2"
431
+ >
432
+ <Button type="reset" variant="link">
433
+ Reset
434
+ </Button>
435
+ <Button type="submit" variant="solid">
436
+ Submit
437
+ </Button>
438
+ </Footer>
439
+ </Form>
440
+ );
441
+ };
@@ -46,7 +46,7 @@ export interface ControllerProps {
46
46
  disabled?: boolean;
47
47
  onBlur: () => void;
48
48
  onChange: (value: AnyObject) => void;
49
- inputRef?: React.Ref<HTMLInputElement>;
49
+ ref?: React.Ref<HTMLInputElement>;
50
50
  }) => ReactElement);
51
51
  }
52
52
 
@@ -86,7 +86,7 @@ export const Controller = ({ name, children, ...rest }: ControllerProps) => {
86
86
  : children({
87
87
  ...field,
88
88
  ...rest,
89
- inputRef: (el: AnyObject) => {
89
+ ref: (el: AnyObject) => {
90
90
  el && ref(el);
91
91
  },
92
92
  readOnly: isSubmitting,
package/src/form/Form.tsx CHANGED
@@ -57,6 +57,10 @@ export interface FormProps<K extends KeyValue = KeyValue> {
57
57
  * form data schema
58
58
  */
59
59
  schema?: yup.ObjectSchema<K>;
60
+ /**
61
+ * current form model
62
+ */
63
+ values?: K;
60
64
  /**
61
65
  * default data values
62
66
  */
@@ -77,6 +81,7 @@ export const Form = <K extends KeyValue>({
77
81
  formRef,
78
82
  schema,
79
83
  children,
84
+ values,
80
85
  defaultValues,
81
86
  onSubmit = DEFAULT_SUBMIT,
82
87
  onChange,
@@ -84,15 +89,12 @@ export const Form = <K extends KeyValue>({
84
89
  }: PropsWithChildren<FormProps<K>>) => {
85
90
  const ref = useRef<HTMLFormElement>(null);
86
91
  const form = useForm<K>({
92
+ values,
87
93
  shouldFocusError: true,
88
94
  resolver: schema && (yupResolver(schema) as AnyObject),
89
95
  defaultValues: defaultValues as DefaultValues<K>,
90
96
  });
91
97
 
92
- useEffect(() => {
93
- form.reset();
94
- }, []);
95
-
96
98
  const [, startTransition] = useTransition();
97
99
  const changeHandler = useDebounce(onChange, [onChange]);
98
100
  useEffect(() => {
@@ -21,38 +21,47 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
+ import { EmptyContent } from "@react-fabric/core";
24
25
  import { isEmpty, isNil, yup } from "@react-fabric/utilities";
25
26
  import { Fragment, useMemo } from "react";
26
27
  import { FormField } from "../builder/FormField";
27
- import { type FormSchema } from "../types/schema";
28
+ import { type BaseSelectProps } from "../types";
29
+ import { DATA_TYPES, type FormSchema, type SchemaDef } from "../types/schema";
28
30
  import { type UploadHandler } from "./useFileUploader";
29
31
 
30
- const makeYupField = (field: FormSchema) => {
31
- let yupField: AnyObject = yup.string();
32
- if (field.datatype === "schema") {
32
+ const makeYupField = (field: SchemaDef) => {
33
+ let yupField: AnyObject = yup.string().trim();
34
+ if (field.datatype === DATA_TYPES.SCHEMA) {
33
35
  const child: yup.ObjectShape = Object.fromEntries(
34
36
  field.schema.map((field) => [field.id, makeYupField(field)]),
35
37
  );
36
38
  yupField = yup.object(child);
37
39
  }
38
- if (field.datatype === "boolean") yupField = yup.boolean();
40
+ if (field.datatype === DATA_TYPES.BOOL) {
41
+ yupField = yup.boolean();
42
+ if (field.required)
43
+ yupField = yupField.test({
44
+ test: (value: boolean) => !!value,
45
+ });
46
+ }
39
47
  if (
40
- field.datatype === "decimal" ||
41
- field.datatype === "number" ||
42
- field.datatype === "range"
48
+ field.datatype === DATA_TYPES.NUMBER ||
49
+ field.datatype === DATA_TYPES.RANGE
43
50
  ) {
44
51
  yupField = yup.number();
45
52
  !isNil(field.min) && (yupField = yupField.min(field.min));
46
53
  !isNil(field.max) && (yupField = yupField.max(field.max));
47
54
 
48
- if (field.datatype === "range") yupField = yup.array(yupField);
55
+ if (field.datatype === DATA_TYPES.RANGE) yupField = yup.array(yupField);
49
56
  }
50
- if (field.datatype === "string") {
51
- field.options && (yupField = yupField.oneOf(field.options));
57
+ if (field.datatype === DATA_TYPES.STRING) {
58
+ field.options &&
59
+ !field.allowCustom &&
60
+ (yupField = yupField.oneOf(field.options));
52
61
  field.regex && (yupField = yupField.matches(new RegExp(field.regex)));
53
62
  }
54
63
 
55
- if (field.datatype === "file") {
64
+ if (field.datatype === DATA_TYPES.FILE) {
56
65
  yupField = yup
57
66
  .object({
58
67
  filename: yup.string().required(),
@@ -83,13 +92,14 @@ const makeYupField = (field: FormSchema) => {
83
92
  return yupField.label(field.label);
84
93
  };
85
94
 
86
- export const useFormBuilder = (
87
- schema: FormSchema[],
95
+ export const useFormBuilder = <T extends AnyObject = string>(
96
+ schema: FormSchema,
88
97
  options: {
89
98
  prefix?: string;
90
99
  inline?: boolean;
91
100
  fileUrl?: (path: string) => string;
92
101
  uploadHandler?: UploadHandler;
102
+ optionLists?: KeyValue<BaseSelectProps<T>>;
93
103
  } = {},
94
104
  ) => {
95
105
  const filteredSchema = useMemo(
@@ -106,11 +116,12 @@ export const useFormBuilder = (
106
116
  <Fragment>
107
117
  {filteredSchema.map((field, idx) => (
108
118
  <div className="mb-4" key={field.id}>
109
- {field.datatype === "schema" ? null : (
119
+ {field.datatype === DATA_TYPES.SCHEMA ? null : (
110
120
  <FormField
111
121
  {...field}
112
122
  autoFocus={idx === 0}
113
123
  fileUrl={options.fileUrl}
124
+ optionLists={options.optionLists}
114
125
  uploadHandler={options.uploadHandler}
115
126
  inline={options.inline}
116
127
  prefix={options.prefix}
@@ -118,6 +129,9 @@ export const useFormBuilder = (
118
129
  )}
119
130
  </div>
120
131
  ))}
132
+ {filteredSchema.length === 0 && (
133
+ <EmptyContent message="No schema defined" />
134
+ )}
121
135
  </Fragment>
122
136
  );
123
137
 
package/src/index.ts CHANGED
@@ -26,15 +26,18 @@ import "./i18n";
26
26
  export { Controller } from "./form/Controller";
27
27
  export { Form, type FormRef } from "./form/Form";
28
28
 
29
+ export { SchemaEditor } from "./builder/SchemaEditor";
30
+
29
31
  export { useFileUploader } from "./hooks/useFileUploader";
30
32
  export { useFormBuilder } from "./hooks/useFormBuilder";
31
33
 
32
- export { type FormSchema } from "./types/schema";
34
+ export { DATA_TYPES, type FormSchema, type SchemaDef } from "./types/schema";
33
35
 
34
36
  export { ArrayInput } from "./input/ArrayInput";
35
37
  export { Checkbox } from "./input/Checkbox";
36
38
  export { ColorInput } from "./input/ColorInput";
37
39
  export { ColorPicker } from "./input/ColorPicker";
40
+ export { DateInput } from "./input/DateInput";
38
41
  export { Field } from "./input/Field";
39
42
  export { FileInput } from "./input/File";
40
43
  export { HiddenInput } from "./input/Hidden";
@@ -43,7 +46,7 @@ export { Number } from "./input/Number";
43
46
  export { Password } from "./input/Password";
44
47
  export { Radio } from "./input/Radio";
45
48
  export { RadioGroup } from "./input/RadioGroup";
46
- export { Range } from "./input/Range";
49
+ export { RangeSlider } from "./input/RangeSlider";
47
50
  export { Search } from "./input/Search";
48
51
  export { Slider } from "./input/Slider";
49
52
  export { Switch } from "./input/Switch";
@@ -34,7 +34,7 @@ import {
34
34
  } from "react";
35
35
  import { ErrorIcon } from "../internal/ErrorIcon";
36
36
 
37
- export interface CheckboxProps extends RefProp<HTMLInputElement> {
37
+ interface CheckboxProps extends RefProp<HTMLInputElement> {
38
38
  /**
39
39
  * checkbox label
40
40
  */
@@ -50,8 +50,7 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
50
50
  /**
51
51
  * on checked change
52
52
  */
53
- onChange?: (checked: boolean | string | number) => void;
54
-
53
+ onChange?: (checked: boolean) => void;
55
54
  /**
56
55
  * disabled input
57
56
  */
@@ -94,6 +93,8 @@ export const Checkbox = ({
94
93
  width,
95
94
  icon,
96
95
  iconChecked,
96
+ // @ts-expect-error ignore
97
+ required,
97
98
  onChange,
98
99
  ...rest
99
100
  }: CheckboxProps) => {