@react-fabric/form 1.0.0-beta.9 → 1.0.2

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 (215) hide show
  1. package/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
  2. package/css/_colorPicker.css +95 -0
  3. package/{src/internal/Field.module.css → css/_field.css} +94 -33
  4. package/{src/input/File.module.css → css/_file.css} +21 -6
  5. package/css/styles.css +27 -0
  6. package/dist/cjs/builder/FileField.js +107 -78
  7. package/dist/cjs/builder/FormField.js +60 -39
  8. package/dist/cjs/builder/SchemaEditor.js +72 -0
  9. package/dist/cjs/builder/components/AddSchemaFields.js +64 -0
  10. package/dist/cjs/builder/components/SchemaArrayForm.js +146 -0
  11. package/dist/cjs/builder/components/SchemaField.js +423 -0
  12. package/dist/cjs/form/Controller.js +66 -19
  13. package/dist/cjs/form/Form.js +97 -39
  14. package/dist/cjs/form/useForm.js +32 -0
  15. package/dist/cjs/hooks/useFileUploader.js +74 -45
  16. package/dist/cjs/hooks/useFormBuilder.js +85 -31
  17. package/dist/cjs/i18n/{ar.json.js → ar/form.json.js} +5 -4
  18. package/dist/cjs/i18n/{en.json.js → en/form.json.js} +5 -5
  19. package/dist/cjs/i18n/index.js +4 -4
  20. package/dist/cjs/index.js +41 -2
  21. package/dist/cjs/input/ArrayInput.js +259 -135
  22. package/dist/cjs/input/AvatarInput.js +99 -63
  23. package/dist/cjs/input/Checkbox.js +24 -25
  24. package/dist/cjs/input/ColorInput.js +138 -81
  25. package/dist/cjs/input/ColorPicker.js +78 -95
  26. package/dist/cjs/input/DateInput.js +192 -0
  27. package/dist/cjs/input/Field.js +21 -20
  28. package/dist/cjs/input/File.js +85 -80
  29. package/dist/cjs/input/Hidden.js +27 -13
  30. package/dist/cjs/input/Input.js +49 -48
  31. package/dist/cjs/input/Number.js +46 -44
  32. package/dist/cjs/input/Password.js +51 -49
  33. package/dist/cjs/input/Radio.js +26 -16
  34. package/dist/cjs/input/RadioGroup.js +26 -11
  35. package/dist/cjs/input/{Range.js → RangeSlider.js} +61 -66
  36. package/dist/cjs/input/Search.js +58 -64
  37. package/dist/cjs/input/Slider.js +57 -66
  38. package/dist/cjs/input/Switch.js +29 -27
  39. package/dist/cjs/input/Textarea.js +65 -53
  40. package/dist/cjs/internal/ErrorIcon.js +9 -9
  41. package/dist/cjs/internal/FieldWrapper.js +23 -13
  42. package/dist/cjs/internal/InputWrapper.js +85 -87
  43. package/dist/cjs/ranger/index.js +7 -7
  44. package/dist/cjs/ranger/utils.js +9 -4
  45. package/dist/cjs/select/AutoComplete.js +93 -76
  46. package/dist/cjs/select/DualList.js +235 -154
  47. package/dist/cjs/select/List.js +122 -89
  48. package/dist/cjs/select/Options.js +58 -54
  49. package/dist/cjs/select/Select.js +119 -89
  50. package/dist/cjs/select/helpers.js +5 -5
  51. package/dist/cjs/select/useSelect.js +83 -58
  52. package/dist/cjs/types/schema.js +43 -0
  53. package/dist/cjs/utils/eventHandlers.js +16 -6
  54. package/dist/cjs/utils/getColor.js +6 -6
  55. package/dist/cjs/utils/getProps.js +49 -0
  56. package/dist/esm/builder/FileField.js +109 -80
  57. package/dist/esm/builder/FormField.js +60 -39
  58. package/dist/esm/builder/SchemaEditor.js +72 -0
  59. package/dist/esm/builder/components/AddSchemaFields.js +64 -0
  60. package/dist/esm/builder/components/SchemaArrayForm.js +146 -0
  61. package/dist/esm/builder/components/SchemaField.js +423 -0
  62. package/dist/esm/form/Controller.js +66 -19
  63. package/dist/esm/form/Form.js +97 -39
  64. package/dist/esm/form/useForm.js +32 -0
  65. package/dist/esm/hooks/useFileUploader.js +75 -46
  66. package/dist/esm/hooks/useFormBuilder.js +84 -30
  67. package/dist/esm/i18n/{ar.json.js → ar/form.json.js} +5 -4
  68. package/dist/esm/i18n/{en.json.js → en/form.json.js} +5 -5
  69. package/dist/esm/i18n/index.js +2 -2
  70. package/dist/esm/index.js +36 -1
  71. package/dist/esm/input/ArrayInput.js +260 -136
  72. package/dist/esm/input/AvatarInput.js +99 -63
  73. package/dist/esm/input/Checkbox.js +26 -27
  74. package/dist/esm/input/ColorInput.js +141 -84
  75. package/dist/esm/input/ColorPicker.js +80 -97
  76. package/dist/esm/input/DateInput.js +192 -0
  77. package/dist/esm/input/Field.js +21 -20
  78. package/dist/esm/input/File.js +89 -84
  79. package/dist/esm/input/Hidden.js +28 -14
  80. package/dist/esm/input/Input.js +51 -50
  81. package/dist/esm/input/Number.js +48 -46
  82. package/dist/esm/input/Password.js +54 -52
  83. package/dist/esm/input/Radio.js +27 -17
  84. package/dist/esm/input/RadioGroup.js +27 -12
  85. package/dist/esm/input/{Range.js → RangeSlider.js} +62 -67
  86. package/dist/esm/input/Search.js +61 -67
  87. package/dist/esm/input/Slider.js +58 -67
  88. package/dist/esm/input/Switch.js +31 -29
  89. package/dist/esm/input/Textarea.js +67 -55
  90. package/dist/esm/internal/ErrorIcon.js +11 -11
  91. package/dist/esm/internal/FieldWrapper.js +23 -13
  92. package/dist/esm/internal/InputWrapper.js +88 -90
  93. package/dist/esm/ranger/index.js +7 -7
  94. package/dist/esm/ranger/utils.js +9 -4
  95. package/dist/esm/select/AutoComplete.js +95 -78
  96. package/dist/esm/select/DualList.js +233 -152
  97. package/dist/esm/select/List.js +125 -92
  98. package/dist/esm/select/Options.js +58 -54
  99. package/dist/esm/select/Select.js +122 -92
  100. package/dist/esm/select/helpers.js +5 -5
  101. package/dist/esm/select/useSelect.js +84 -59
  102. package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
  103. package/dist/esm/utils/eventHandlers.js +16 -6
  104. package/dist/esm/utils/getColor.js +6 -6
  105. package/dist/esm/utils/getProps.js +49 -0
  106. package/dist/types/builder/FileField.d.ts +7 -4
  107. package/dist/types/builder/FormField.d.ts +4 -2
  108. package/dist/types/builder/SchemaEditor.d.ts +6 -0
  109. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  110. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  111. package/dist/types/builder/components/SchemaField.d.ts +12 -0
  112. package/dist/types/form/Controller.d.ts +45 -3
  113. package/dist/types/form/Form.d.ts +38 -7
  114. package/dist/types/form/useForm.d.ts +6 -0
  115. package/dist/types/hooks/useFileUploader.d.ts +24 -3
  116. package/dist/types/hooks/useFormBuilder.d.ts +41 -3
  117. package/dist/types/index.d.ts +32 -2
  118. package/dist/types/input/ArrayInput.d.ts +68 -13
  119. package/dist/types/input/AvatarInput.d.ts +23 -6
  120. package/dist/types/input/Checkbox.d.ts +12 -10
  121. package/dist/types/input/ColorInput.d.ts +15 -5
  122. package/dist/types/input/ColorPicker.d.ts +10 -2
  123. package/dist/types/input/DateInput.d.ts +21 -0
  124. package/dist/types/input/Field.d.ts +9 -36
  125. package/dist/types/input/File.d.ts +16 -4
  126. package/dist/types/input/Hidden.d.ts +7 -6
  127. package/dist/types/input/Input.d.ts +11 -4
  128. package/dist/types/input/Number.d.ts +9 -4
  129. package/dist/types/input/Password.d.ts +9 -4
  130. package/dist/types/input/Radio.d.ts +9 -4
  131. package/dist/types/input/RadioGroup.d.ts +14 -6
  132. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +11 -6
  133. package/dist/types/input/Search.d.ts +14 -4
  134. package/dist/types/input/Slider.d.ts +9 -6
  135. package/dist/types/input/Switch.d.ts +13 -8
  136. package/dist/types/input/Textarea.d.ts +15 -4
  137. package/dist/types/internal/ErrorIcon.d.ts +4 -1
  138. package/dist/types/internal/FieldWrapper.d.ts +10 -1
  139. package/dist/types/internal/InputWrapper.d.ts +19 -1
  140. package/dist/types/ranger/index.d.ts +7 -3
  141. package/dist/types/ranger/utils.d.ts +2 -2
  142. package/dist/types/select/AutoComplete.d.ts +7 -2
  143. package/dist/types/select/DualList.d.ts +11 -37
  144. package/dist/types/select/List.d.ts +7 -2
  145. package/dist/types/select/Options.d.ts +8 -7
  146. package/dist/types/select/Select.d.ts +7 -2
  147. package/dist/types/select/helpers.d.ts +2 -2
  148. package/dist/types/select/useSelect.d.ts +10 -28
  149. package/dist/types/types/index.d.ts +73 -39
  150. package/dist/types/types/schema.d.ts +78 -32
  151. package/dist/types/utils/eventHandlers.d.ts +4 -4
  152. package/dist/types/utils/getColor.d.ts +4 -4
  153. package/dist/types/utils/getProps.d.ts +26 -0
  154. package/dist/types/utils/index.d.ts +1 -0
  155. package/package.json +25 -25
  156. package/src/builder/FileField.tsx +73 -56
  157. package/src/builder/FormField.tsx +66 -58
  158. package/src/builder/SchemaEditor.tsx +78 -0
  159. package/src/builder/components/AddSchemaFields.tsx +64 -0
  160. package/src/builder/components/SchemaArrayForm.tsx +146 -0
  161. package/src/builder/components/SchemaField.tsx +405 -0
  162. package/src/form/Controller.tsx +61 -24
  163. package/src/form/Form.tsx +74 -50
  164. package/src/form/useForm.ts +53 -0
  165. package/src/hooks/useFileUploader.ts +115 -84
  166. package/src/hooks/useFormBuilder.tsx +80 -41
  167. package/src/i18n/{ar.json → ar/form.json} +5 -4
  168. package/src/i18n/{en.json → en/form.json} +5 -5
  169. package/src/i18n/index.ts +2 -2
  170. package/src/index.ts +34 -20
  171. package/src/input/ArrayInput.tsx +255 -173
  172. package/src/input/AvatarInput.tsx +82 -39
  173. package/src/input/Checkbox.tsx +30 -54
  174. package/src/input/ColorInput.tsx +146 -105
  175. package/src/input/ColorPicker.tsx +76 -102
  176. package/src/input/DateInput.tsx +225 -0
  177. package/src/input/Field.tsx +23 -65
  178. package/src/input/File.tsx +76 -98
  179. package/src/input/Hidden.tsx +36 -24
  180. package/src/input/Input.tsx +55 -53
  181. package/src/input/Number.tsx +49 -54
  182. package/src/input/Password.tsx +61 -66
  183. package/src/input/Radio.tsx +28 -37
  184. package/src/input/RadioGroup.tsx +30 -25
  185. package/src/input/{Range.tsx → RangeSlider.tsx} +81 -109
  186. package/src/input/Search.tsx +64 -77
  187. package/src/input/Slider.tsx +80 -109
  188. package/src/input/Switch.tsx +39 -53
  189. package/src/input/Textarea.tsx +72 -59
  190. package/src/internal/ErrorIcon.tsx +22 -21
  191. package/src/internal/FieldWrapper.tsx +33 -23
  192. package/src/internal/InputWrapper.tsx +132 -143
  193. package/src/ranger/index.tsx +37 -117
  194. package/src/ranger/utils.ts +12 -11
  195. package/src/select/AutoComplete.tsx +113 -123
  196. package/src/select/DualList.tsx +218 -204
  197. package/src/select/List.tsx +130 -97
  198. package/src/select/Options.tsx +59 -57
  199. package/src/select/Select.tsx +148 -122
  200. package/src/select/helpers.ts +13 -8
  201. package/src/select/useSelect.tsx +110 -127
  202. package/src/types/index.ts +76 -45
  203. package/src/types/schema.ts +97 -40
  204. package/src/utils/eventHandlers.ts +24 -26
  205. package/src/utils/getColor.ts +9 -8
  206. package/src/utils/getProps.ts +47 -0
  207. package/src/utils/index.ts +1 -0
  208. package/dist/cjs/input/ArrayInput.module.css +0 -1
  209. package/dist/cjs/input/ColorPicker.module.css +0 -1
  210. package/dist/cjs/input/File.module.css +0 -1
  211. package/dist/cjs/internal/Field.module.css +0 -1
  212. package/dist/esm/input/ArrayInput.module.css +0 -1
  213. package/dist/esm/input/ColorPicker.module.css +0 -1
  214. package/dist/esm/input/File.module.css +0 -1
  215. package/dist/esm/internal/Field.module.css +0 -1
@@ -1,6 +1,8 @@
1
- import { type yup } from "@react-fabric/utilities";
2
1
  import { type PropsWithChildren, type Ref } from "react";
3
- import { type FormState } from "react-hook-form";
2
+ import { type FormState, type Resolver } from "react-hook-form";
3
+ type NestedKeyOf<T extends object> = {
4
+ [K in keyof T & (string | number)]: T[K] extends object ? `${K}` | `${K}.${NestedKeyOf<T[K]>}` : K;
5
+ }[keyof T & (string | number)];
4
6
  export interface FormRef<K extends KeyValue> {
5
7
  state: FormState<K>;
6
8
  reset: () => void;
@@ -8,19 +10,24 @@ export interface FormRef<K extends KeyValue> {
8
10
  submit: () => void;
9
11
  validate: () => Promise<boolean>;
10
12
  getValues: () => K;
11
- setValue: (key: keyof K, value: AnyObject) => void;
13
+ setValue: (key: NestedKeyOf<K>, value: unknown) => void;
12
14
  setValues: (values: K) => void;
13
15
  }
14
16
  export interface FormProps<K extends KeyValue = KeyValue> {
15
17
  formRef?: Ref<FormRef<K>>;
16
18
  /**
17
- * form data schema
19
+ * react-hook-form resolver for validation
20
+ * @see {@link https://react-hook-form.com/ts#Resolver}
18
21
  */
19
- schema?: yup.ObjectSchema<K>;
22
+ resolver?: Resolver<K>;
20
23
  /**
21
24
  * default data values
22
25
  */
23
- defaultValues?: K;
26
+ defaultValues?: K | Promise<K>;
27
+ /**
28
+ * reset values on defaultValues change (workaround for using fetch result)
29
+ */
30
+ resetOnChange?: boolean;
24
31
  /**
25
32
  * change callback
26
33
  */
@@ -30,4 +37,28 @@ export interface FormProps<K extends KeyValue = KeyValue> {
30
37
  */
31
38
  onSubmit?: (values: K) => void;
32
39
  }
33
- export declare const Form: <K extends KeyValue<any>>({ formRef, schema, children, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
40
+ /**
41
+ * Form component for managing form state and validation using react-hook-form and yup.
42
+ * It provides a simple interface for form handling, including submission, validation, and value management.
43
+ * It supports nested form structures and allows for custom validation schemas using Yup.
44
+ *
45
+ * @example
46
+ * ```jsx
47
+ * <Form
48
+ * formRef={formRef}
49
+ * resolver={hookformResolver(schema)}
50
+ * defaultValues={{ name: "", email: "" }}
51
+ * onSubmit={(values) => {
52
+ * console.log("Form submitted with values:", values);
53
+ * }}
54
+ * >
55
+ * <input name="name" ref={form.register} placeholder="Name" />
56
+ * <input name="email" ref={form.register} placeholder="Email" />
57
+ * <button type="submit">Submit</button>
58
+ * </Form>
59
+ * ```
60
+ *
61
+ * @see {@link https://react-hook-form.com/docs/useform} for more details on the properties.
62
+ */
63
+ export declare function Form<K extends KeyValue>({ formRef, resolver, children, resetOnChange, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>): import("react").JSX.Element;
64
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { FieldValues, UseFormReturn } from "react-hook-form";
2
+ export type UseCustomFormReturn<K extends FieldValues = FieldValues> = Pick<UseFormReturn<K>, "formState" | "getValues" | "setValue" | "watch" | "reset" | "resetField" | "setError" | "setFocus"> & {
3
+ values: K;
4
+ watch: UseFormReturn<K>["watch"];
5
+ };
6
+ export declare function useForm<K extends KeyValue = KeyValue>(): UseCustomFormReturn<K>;
@@ -1,4 +1,4 @@
1
- import { type AxiosRequestConfig } from "axios";
1
+ import type { AxiosRequestConfig } from "axios";
2
2
  export type UploadHandler = (data: FormData, config: AxiosRequestConfig) => Promise<string>;
3
3
  interface FileInfo {
4
4
  key: string;
@@ -12,12 +12,33 @@ interface FileInfo {
12
12
  progress?: number;
13
13
  abort?: AbortController["abort"];
14
14
  }
15
- export declare const useFileUploader: (uploader: UploadHandler, initialList?: string | FileInfo | FileInfo[], multiple?: boolean) => {
15
+ /**
16
+ * useFileUploader hook provides a way to handle file uploads
17
+ * with progress tracking, error handling, and file management.
18
+ * It uses a reducer to manage the state of uploaded files and their statuses.
19
+ *
20
+ * @param uploader - The function that handles the file upload.
21
+ * @param initialList - Initial list of files to be managed by the uploader.
22
+ * @param multiple - Whether to allow multiple file uploads or not.
23
+ * @returns An object containing methods to upload, remove, retry files,
24
+ * and the current state of the uploader including pending uploads and file list.
25
+ *
26
+ * @example
27
+ * ```jsx
28
+ * const { upload, remove, retry, state } = useFileUploader(uploader, initialList, multiple);
29
+ * ```
30
+ */
31
+ export declare function useFileUploader(uploader: UploadHandler, initialList?: string | FileInfo | FileInfo[], { multiple, onChange, }?: {
32
+ multiple?: true;
33
+ onChange?: (files: FileInfo[] | null) => void;
34
+ } | {
35
+ multiple: false;
36
+ onChange?: (files: FileInfo | null) => void;
37
+ }): {
16
38
  upload: (files: FileList | null) => void;
17
39
  remove: (key: string) => void;
18
40
  retry: (key: string) => void;
19
41
  pending: number;
20
- list: FileInfo[];
21
42
  files: FileInfo[];
22
43
  };
23
44
  export {};
@@ -1,13 +1,51 @@
1
1
  import { yup } from "@react-fabric/utilities";
2
+ import { type BaseSelectProps } from "../types";
2
3
  import { type FormSchema } from "../types/schema";
3
4
  import { type UploadHandler } from "./useFileUploader";
4
- export declare const useFormBuilder: (schema: FormSchema[], options?: {
5
+ /**
6
+ * useFormBuilder hook to create a form definition based on a schema.
7
+ * It generates a Yup validation schema and a form definition component.
8
+ *
9
+ * @param {FormSchema} schema - The schema defining the form fields.
10
+ * @param {Object} options - Optional parameters for the form builder.
11
+ * @returns An object containing the form definition and the Yup validation schema.
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * const { formDef, schemaDef } = useFormBuilder(schema, {
16
+ * prefix: "form",
17
+ * inline: true,
18
+ * fileUrl: (path) => `/files/${path}`,
19
+ * uploadHandler: async (file) => {
20
+ * // handle file upload
21
+ * },
22
+ * optionLists: {
23
+ * // define option lists for select fields
24
+ * }
25
+ * * });
26
+ * <FormBuilder
27
+ * schema={schemaDef}
28
+ * onSubmit={(data) => console.log(data)}
29
+ * >
30
+ * {formDef}
31
+ * </FormBuilder>
32
+ * ```
33
+ */
34
+ export declare function useFormBuilder<T extends AnyObject = string>(schema: FormSchema, options?: {
5
35
  prefix?: string;
6
36
  inline?: boolean;
7
37
  fileUrl?: (path: string) => string;
8
38
  uploadHandler?: UploadHandler;
9
- }) => {
10
- formDef: import("react/jsx-runtime").JSX.Element;
39
+ optionLists?: KeyValue<BaseSelectProps<T>>;
40
+ }): {
41
+ formDef: import("react").JSX.Element;
42
+ resolver: import("react-hook-form").Resolver<{
43
+ [x: string]: any;
44
+ [x: number]: any;
45
+ }, unknown, {
46
+ [x: string]: any;
47
+ [x: number]: any;
48
+ }>;
11
49
  schemaDef: yup.ObjectSchema<{
12
50
  [x: string]: any;
13
51
  }, yup.AnyObject, {
@@ -1,13 +1,41 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ export declare const FORM_PACKAGE = "@react-fabric/form";
26
+ export declare const FORM_VERSION = "1.0.1";
1
27
  import "./i18n";
2
28
  export { Controller } from "./form/Controller";
3
29
  export { Form, type FormRef } from "./form/Form";
30
+ export { useForm } from "./form/useForm";
4
31
  export { useFileUploader } from "./hooks/useFileUploader";
5
32
  export { useFormBuilder } from "./hooks/useFormBuilder";
6
- export { type FormSchema } from "./types/schema";
7
33
  export { ArrayInput } from "./input/ArrayInput";
34
+ export { AvatarInput } from "./input/AvatarInput";
8
35
  export { Checkbox } from "./input/Checkbox";
9
36
  export { ColorInput } from "./input/ColorInput";
10
37
  export { ColorPicker } from "./input/ColorPicker";
38
+ export { DateInput } from "./input/DateInput";
11
39
  export { Field } from "./input/Field";
12
40
  export { FileInput } from "./input/File";
13
41
  export { HiddenInput } from "./input/Hidden";
@@ -16,7 +44,7 @@ export { Number } from "./input/Number";
16
44
  export { Password } from "./input/Password";
17
45
  export { Radio } from "./input/Radio";
18
46
  export { RadioGroup } from "./input/RadioGroup";
19
- export { Range } from "./input/Range";
47
+ export { RangeSlider } from "./input/RangeSlider";
20
48
  export { Search } from "./input/Search";
21
49
  export { Slider } from "./input/Slider";
22
50
  export { Switch } from "./input/Switch";
@@ -25,3 +53,5 @@ export { AutoComplete } from "./select/AutoComplete";
25
53
  export { DualList } from "./select/DualList";
26
54
  export { List } from "./select/List";
27
55
  export { Select } from "./select/Select";
56
+ export { SchemaEditor } from "./builder/SchemaEditor";
57
+ export { DATA_TYPES, SCHEMA_CUSTOM_LIST, type FormSchema, type SchemaDef } from "./types/schema";
@@ -1,5 +1,5 @@
1
- import { type ReactNode, type RefObject } from "react";
2
- export interface ArrayInputProps {
1
+ import { type Ref } from "react";
2
+ export interface ArrayInputProps<T extends AnyObject = string> {
3
3
  /**
4
4
  * input label
5
5
  */
@@ -7,7 +7,7 @@ export interface ArrayInputProps {
7
7
  /**
8
8
  * append to label end
9
9
  */
10
- appendLabel?: JSX.Element | string | number | boolean;
10
+ appendLabel?: React.ReactElement | string | number | boolean;
11
11
  /**
12
12
  * info label at bottom
13
13
  */
@@ -32,6 +32,10 @@ export interface ArrayInputProps {
32
32
  * minimum required length
33
33
  */
34
34
  minItems?: number;
35
+ /**
36
+ * maximum length
37
+ */
38
+ maxItems?: number;
35
39
  /**
36
40
  * field name to focus on add
37
41
  */
@@ -43,23 +47,38 @@ export interface ArrayInputProps {
43
47
  children: React.ReactNode | ((props: {
44
48
  index: number;
45
49
  name: string;
46
- }) => ReactNode);
50
+ item: T;
51
+ onChange: (val: false | undefined | T) => void;
52
+ }) => React.ReactNode);
47
53
  /**
48
54
  * add item button label
49
55
  */
50
56
  addLabel?: string;
51
- /**
52
- * fixed length list
53
- */
54
- fixedList?: boolean;
55
- arrayRef?: RefObject<{
56
- addItem: (item: AnyObject) => void;
57
+ buttonPosition?: "top" | "bottom" | "both";
58
+ arrayRef?: Ref<{
59
+ addItem: (item: false | undefined | T | Promise<false | undefined | T>) => void;
57
60
  removeItem: (idx: number) => void;
58
61
  }>;
59
62
  /**
60
- * Add item
63
+ * add new item
64
+ */
65
+ onAdd?: () => false | undefined | T | Promise<false | undefined | T>;
66
+ /**
67
+ * on item remove
61
68
  */
62
- onAdd?: () => AnyObject;
69
+ onRemove?: (item: T, idx: number) => void;
70
+ /**
71
+ * before item remove
72
+ */
73
+ onBeforeRemove?: (item: T, idx: number) => Promise<boolean> | boolean;
74
+ /**
75
+ * can remove item
76
+ */
77
+ canRemove?: false | "newonly" | ((props: {
78
+ item: T;
79
+ index: number;
80
+ lastItem: boolean;
81
+ }) => boolean);
63
82
  /**
64
83
  * field width
65
84
  */
@@ -73,4 +92,40 @@ export interface ArrayInputProps {
73
92
  */
74
93
  labelWidth?: string;
75
94
  }
76
- export declare const ArrayInput: ({ name, children, addLabel, fixedList, focusName, onAdd, arrayRef, enableSorting, disabled, readOnly, minItems, ...rest }: ArrayInputProps) => import("react/jsx-runtime").JSX.Element;
95
+ /**
96
+ * ArrayInput component for managing an array of items in a form.
97
+ * It allows adding, removing, and sorting items within the array.
98
+ * It integrates with react-hook-form for form state management and validation.
99
+ * It supports fixed-length lists, custom add/remove handlers, and can display validation errors.
100
+ * It also provides options for inline display and custom button positioning.
101
+ *
102
+ * It uses the `useFieldArray` hook from `react-hook-form` to manage the array state and provides a simple interface for adding and removing items.
103
+ *
104
+ * It also supports drag-and-drop sorting using `@dnd-kit/core` and `@dnd-kit/sortable` for a better user experience when reordering items.
105
+ *
106
+ * @example
107
+ * ```jsx
108
+ * <ArrayInput
109
+ * name="items"
110
+ * label="Items"
111
+ * addLabel="Add Item"
112
+ * onAdd={() => ({ name: "", value: "" })}
113
+ * onRemove={(item, index) => console.log("Removed item:", item, "at index:", index)}
114
+ * onBeforeRemove={(item, index) => confirm(`Are you sure you want to remove item at index ${index}?`)}
115
+ * canRemove={({ item, index, lastItem }) => !lastItem} // Prevent removing the last item
116
+ * >
117
+ * {({ index, name }) => (
118
+ * <Input
119
+ * name={name}
120
+ * label={`Item ${index + 1}`}
121
+ * placeholder="Enter item value"
122
+ * required={index === 0} // Make the first item required
123
+ * />
124
+ * )}
125
+ * </ArrayInput>
126
+ * ```
127
+ *
128
+ * @see {@link https://react-hook-form.com/api/usefieldarray} for more details on `useFieldArray`.
129
+ * @see {@link https://react-dnd.github.io/react-dnd/about} for more details on DnD context and sorting.
130
+ */
131
+ export declare function ArrayInput<T extends AnyObject = string>({ name, children, addLabel, focusName, buttonPosition, onAdd, onRemove, onBeforeRemove, canRemove, arrayRef, enableSorting, disabled, readOnly, minItems, maxItems, ...rest }: ArrayInputProps<T>): import("react").JSX.Element;
@@ -1,5 +1,6 @@
1
- import { type RefProp } from "@react-fabric/core/dist/types/types";
2
- import { type UploadHandler } from "../hooks/useFileUploader";
1
+ import type { AvatarProps } from "@react-fabric/core/dist/types/components/avatar/Avatar";
2
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
3
+ import type { UploadHandler } from "../hooks/useFileUploader";
3
4
  export interface Props extends RefProp {
4
5
  /**
5
6
  * field name
@@ -10,14 +11,25 @@ export interface Props extends RefProp {
10
11
  */
11
12
  value?: string;
12
13
  /**
13
- * avatar stream src
14
+ * default avatar image
14
15
  */
15
- src?: string;
16
+ defaultValue?: string;
17
+ /**
18
+ * avatar name
19
+ */
20
+ avatarName?: string;
21
+ rounded?: boolean;
22
+ variant?: AvatarProps["variant"];
23
+ fallbackIcon?: AvatarProps["fallbackIcon"];
24
+ avatarClassName?: AvatarProps["className"];
16
25
  size?: string | number;
17
26
  /**
18
27
  * upload handler to store file in temp storage
19
28
  */
20
29
  uploadHandler: UploadHandler;
30
+ /**
31
+ * file stream path
32
+ */
21
33
  fileUrl?: (path: string) => string;
22
34
  /**
23
35
  * change handler
@@ -26,6 +38,11 @@ export interface Props extends RefProp {
26
38
  * @param base64
27
39
  * @returns storage path
28
40
  */
29
- onChange?: (path: string) => void;
41
+ onChange?: (path: string | null) => void;
30
42
  }
31
- export declare const AvatarInput: ({ src, size, fileUrl, uploadHandler, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
43
+ /**
44
+ * Avatar input component for uploading and displaying user avatars.
45
+ * It allows users to select an image file, upload it, and display the avatar.
46
+ * It also provides a way to remove the uploaded file and shows upload progress.
47
+ */
48
+ export declare const AvatarInput: ({ size, avatarName, avatarClassName, value, rounded, defaultValue, fallbackIcon, variant, fileUrl, uploadHandler, onChange, ...rest }: Props) => React.ReactElement;
@@ -1,22 +1,17 @@
1
- /// <reference types="react" />
2
- import { type RefProp } from "@react-fabric/core/dist/types/types";
3
- export interface CheckboxProps extends RefProp<HTMLInputElement> {
1
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
2
+ interface CheckboxProps extends RefProp<HTMLInputElement> {
4
3
  /**
5
4
  * checkbox label
6
5
  */
7
- label?: JSX.Element | string;
6
+ label?: React.ReactElement | string;
8
7
  /**
9
8
  * checked
10
9
  */
11
10
  checked?: boolean;
12
- /**
13
- * value
14
- */
15
- value?: string | number;
16
11
  /**
17
12
  * on checked change
18
13
  */
19
- onChange?: (checked: boolean | string | number) => void;
14
+ onChange?: (checked: boolean) => void;
20
15
  /**
21
16
  * disabled input
22
17
  */
@@ -43,4 +38,11 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
43
38
  iconChecked?: string;
44
39
  name?: string;
45
40
  }
46
- export declare const Checkbox: ({ ref, label, value, name, checked, invalid, disabled, error, width, icon, iconChecked, onChange, ...rest }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
41
+ /**
42
+ * Checkbox component for rendering a checkbox input with label and error handling.
43
+ * It supports custom icons for checked and unchecked states, and handles disabled and invalid states.
44
+ * The component uses a deferred value to manage the checked state, ensuring smooth updates.
45
+ * It also provides an error icon to indicate validation errors.
46
+ */
47
+ export declare function Checkbox({ ref, label, name, checked, invalid, disabled, error, width, icon, iconChecked, onChange, ...rest }: CheckboxProps): import("react").JSX.Element;
48
+ export {};
@@ -1,10 +1,20 @@
1
- import { type RefProp } from "@react-fabric/core/dist/types/types";
2
- import { type InputProps } from "../types";
3
- import { type ColorProps } from "./ColorPicker";
4
- export interface ColorInputProps extends InputProps, ColorProps, RefProp {
1
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
2
+ import type { InputProps, WrapperProps } from "../types";
3
+ import type { ColorProps } from "./ColorPicker";
4
+ export interface ColorInputProps extends InputProps, WrapperProps, Omit<ColorProps, "onChange">, RefProp<HTMLButtonElement> {
5
5
  /**
6
6
  * show eydrop picker
7
7
  */
8
8
  showPicker?: boolean;
9
9
  }
10
- export declare const ColorInput: ({ ref, required, disabled, allowClear, invalid, error, value, showPicker, defaultColor, decorateEnd, decorateStart, onChange, noOutline, ...rest }: ColorInputProps) => import("react/jsx-runtime").JSX.Element;
10
+ /**
11
+ * Color input component that allows users to select a color
12
+ * and optionally use an eye dropper to pick a color from the screen.
13
+ * It uses the Floating UI library for positioning the color picker.
14
+ * It also provides a button to clear the selected color.
15
+ *
16
+ * This component is a wrapper around the `ColorPicker` component
17
+ * and provides additional functionality such as showing an eye dropper
18
+ * and handling the color selection state.
19
+ */
20
+ export declare function ColorInput(props: ColorInputProps): import("react").JSX.Element;
@@ -1,4 +1,3 @@
1
- import { type FC } from "react";
2
1
  export interface ColorProps {
3
2
  /**
4
3
  * color swatches
@@ -12,6 +11,10 @@ export interface ColorProps {
12
11
  * hide alpha value
13
12
  */
14
13
  hideAlpha?: boolean;
14
+ /**
15
+ * show only swatches, hide the color picker
16
+ */
17
+ picker?: "default" | "swatches";
15
18
  /**
16
19
  * color value
17
20
  */
@@ -21,4 +24,9 @@ export interface ColorProps {
21
24
  */
22
25
  onChange?: (color?: string) => void;
23
26
  }
24
- export declare const ColorPicker: FC<ColorProps>;
27
+ /**
28
+ * ColorPicker component allows users to select a color using a color picker UI.
29
+ * It supports swatches, alpha transparency, and custom styles.
30
+ * The component uses the `react-color` library for the color picker functionality.
31
+ */
32
+ export declare const ColorPicker: import("react").MemoExoticComponent<({ value, onChange, hideAlpha, defaultColor, swatches, picker, }: ColorProps) => import("react").JSX.Element>;
@@ -0,0 +1,21 @@
1
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
2
+ import type { DateLike } from "@react-fabric/date";
3
+ import type { InputProps, WrapperProps } from "../types";
4
+ export interface DateProps extends InputProps<DateLike>, WrapperProps, RefProp<HTMLInputElement> {
5
+ type?: "date" | "datetime";
6
+ /**
7
+ * minimum value
8
+ */
9
+ min?: DateLike;
10
+ /**
11
+ * maximum value
12
+ */
13
+ max?: DateLike;
14
+ }
15
+ /**
16
+ * Date input component that allows users to select a date or datetime.
17
+ * It uses the Floating UI library for positioning the date picker.
18
+ * It also provides a button to clear the selected date.
19
+ * The component supports both date and datetime types, with appropriate formatting.
20
+ */
21
+ export declare function DateInput(props: DateProps): import("react").JSX.Element;
@@ -1,42 +1,15 @@
1
- /// <reference types="react" />
2
- import { type ChildrenProp, type CssProp } from "@react-fabric/core/dist/types/types";
3
- export interface FieldProps extends ChildrenProp, CssProp {
4
- /**
5
- * input label
6
- */
7
- label?: string;
8
- /**
9
- * append to label end
10
- */
11
- appendLabel?: JSX.Element | string | number | boolean;
12
- /**
13
- * info label at bottom
14
- */
15
- info?: string;
16
- /**
17
- * required
18
- */
19
- required?: boolean;
20
- /**
21
- * hide outline
22
- */
23
- noOutline?: boolean;
24
- /**
25
- * field width
26
- */
27
- width?: number | string;
28
- /**
29
- * inline label and input
30
- */
31
- inline?: boolean;
32
- /**
33
- * label width for inline
34
- */
35
- labelWidth?: string;
1
+ import type { ChildrenProp, CssProp } from "@react-fabric/core/dist/types/types";
2
+ import type { WrapperProps } from "../types";
3
+ export interface FieldProps extends ChildrenProp, WrapperProps, CssProp {
36
4
  /**
37
5
  * dont apply bg and outline
38
6
  */
39
7
  plain?: boolean;
40
8
  vertical?: boolean;
41
9
  }
42
- export declare const Field: ({ children, vertical, noOutline, plain, ...rest }: FieldProps) => import("react/jsx-runtime").JSX.Element;
10
+ /**
11
+ * Field component for rendering multiple form fields under a single label.
12
+ * It supports various properties for customization, including label, info, required state,
13
+ * and styling options.
14
+ */
15
+ export declare function Field(props: FieldProps): import("react").JSX.Element;
@@ -1,6 +1,11 @@
1
- import { type RefProp } from "@react-fabric/core/dist/types/types";
2
- import { type InputProps } from "../types";
3
- export interface FileInputProps extends InputProps<AnyObject>, RefProp<HTMLInputElement> {
1
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
2
+ import type { InputProps, WrapperProps } from "../types";
3
+ interface FileType {
4
+ name: string;
5
+ type?: string;
6
+ size?: number;
7
+ }
8
+ export interface FileInputProps extends InputProps<FileType | FileType[]>, WrapperProps, RefProp<HTMLInputElement> {
4
9
  /**
5
10
  * allow selecting mutiple files
6
11
  */
@@ -14,4 +19,11 @@ export interface FileInputProps extends InputProps<AnyObject>, RefProp<HTMLInput
14
19
  */
15
20
  accept?: string;
16
21
  }
17
- export declare const FileInput: ({ ref, value, invalid, readOnly, disabled, required, placeholder, autoFocus, error, name, accept, showList, multiple, onChange, onEnterPressed, ...rest }: FileInputProps) => import("react/jsx-runtime").JSX.Element;
22
+ /**
23
+ * File input component that allows users to select files from their system.
24
+ * It supports multiple file selection and displays a list of selected files.
25
+ * The component also provides functionality to remove files from the list.
26
+ * It handles file changes, invalid states, and read-only or disabled states.
27
+ */
28
+ export declare function FileInput(props: FileInputProps): import("react").JSX.Element;
29
+ export {};
@@ -4,13 +4,14 @@ interface Props {
4
4
  */
5
5
  name?: string;
6
6
  /**
7
- * hidden value will fire change for form update
7
+ * hidden input value
8
8
  */
9
9
  hiddenValue?: AnyObject;
10
- /**
11
- * form onChange handler
12
- */
13
- onChange?: (value: AnyObject) => void;
14
10
  }
15
- export declare const HiddenInput: ({ hiddenValue, onChange, invalid, error, value, name, }: Props) => import("react/jsx-runtime").JSX.Element;
11
+ /**
12
+ * Hidden input component to handle hidden values in forms.
13
+ * It will trigger the onChange handler with the hidden value after a short delay.
14
+ * This is useful for cases where you need to update the form state without user interaction.
15
+ */
16
+ export declare function HiddenInput(props: Props): import("react").JSX.Element;
16
17
  export {};
@@ -1,9 +1,16 @@
1
- import { type RefProp } from "@react-fabric/core/dist/types/types";
2
- import { type InputProps } from "../types";
3
- export interface TextInputProps extends InputProps, RefProp<HTMLInputElement> {
1
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
2
+ import type { InputHTMLAttributes } from "react";
3
+ import type { InputProps, WrapperProps } from "../types";
4
+ export interface TextInputProps extends InputProps, WrapperProps, RefProp<HTMLInputElement> {
4
5
  /**
5
6
  * input type
6
7
  */
7
8
  type?: "email" | "file" | "search" | "tel" | "text" | "url";
9
+ autoComplete?: InputHTMLAttributes<HTMLInputElement>["autoComplete"];
8
10
  }
9
- export declare const Input: ({ ref, name, value, invalid, readOnly, disabled, required, placeholder, autoFocus, error, type, onChange, onEnterPressed, ...rest }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
11
+ /**
12
+ * This component is used to render a text input field with various properties such as name, value, invalid state, read-only, disabled, required, placeholder, autoFocus, error message, monospace font option, and event handlers for blur, focus, change, and enter key press.
13
+ * It also includes a clear button that appears when there is a value in the input field, allowing users to clear the input easily.
14
+ * The component uses a wrapper to handle the clear button and styling, and it supports deferred value updates to optimize performance.
15
+ */
16
+ export declare function Input(props: TextInputProps): import("react").JSX.Element;
@@ -1,6 +1,6 @@
1
- import { type RefProp } from "@react-fabric/core/dist/types/types";
2
- import { type InputProps } from "../types";
3
- export interface NumberProps extends InputProps<number>, RefProp<HTMLInputElement> {
1
+ import type { RefProp } from "@react-fabric/core/dist/types/types";
2
+ import type { InputProps, WrapperProps } from "../types";
3
+ export interface NumberProps extends InputProps<number>, WrapperProps, RefProp<HTMLInputElement> {
4
4
  /**
5
5
  * minimum value
6
6
  */
@@ -14,4 +14,9 @@ export interface NumberProps extends InputProps<number>, RefProp<HTMLInputElemen
14
14
  */
15
15
  step?: number;
16
16
  }
17
- export declare const Number: ({ ref, value, invalid, readOnly, disabled, required, placeholder, autoFocus, name, min, max, step, onChange, onEnterPressed, ...rest }: NumberProps) => import("react/jsx-runtime").JSX.Element;
17
+ /**
18
+ * This component allows users to input numeric values with optional minimum, maximum, and step constraints.
19
+ * It provides a clear interface for entering numbers, with support for validation and accessibility features.
20
+ * It also includes a clear button to reset the input value.
21
+ */
22
+ export declare function Number(props: NumberProps): import("react").JSX.Element;