@react-fabric/form 1.0.0-beta.62 → 1.0.0-beta.63

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 (142) hide show
  1. package/css/_colorPicker.css +35 -5
  2. package/css/_file.css +2 -2
  3. package/dist/cjs/builder/FileField.js +6 -6
  4. package/dist/cjs/builder/SchemaEditor.js +1 -1
  5. package/dist/cjs/builder/components/SchemaArrayForm.js +1 -3
  6. package/dist/cjs/builder/components/SchemaField.js +1 -1
  7. package/dist/cjs/form/Controller.js +1 -1
  8. package/dist/cjs/form/Form.js +11 -35
  9. package/dist/cjs/form/useForm.js +32 -0
  10. package/dist/cjs/hooks/useFileUploader.js +5 -5
  11. package/dist/cjs/hooks/useFormBuilder.js +3 -3
  12. package/dist/cjs/index.js +2 -1
  13. package/dist/cjs/input/ArrayInput.js +66 -19
  14. package/dist/cjs/input/AvatarInput.js +7 -7
  15. package/dist/cjs/input/Checkbox.js +1 -1
  16. package/dist/cjs/input/ColorInput.js +26 -19
  17. package/dist/cjs/input/ColorPicker.js +16 -9
  18. package/dist/cjs/input/DateInput.js +3 -3
  19. package/dist/cjs/input/Field.js +1 -1
  20. package/dist/cjs/input/File.js +1 -1
  21. package/dist/cjs/input/Hidden.js +1 -1
  22. package/dist/cjs/input/Input.js +1 -1
  23. package/dist/cjs/input/Number.js +1 -1
  24. package/dist/cjs/input/Password.js +1 -1
  25. package/dist/cjs/input/Radio.js +1 -1
  26. package/dist/cjs/input/RadioGroup.js +5 -3
  27. package/dist/cjs/input/RangeSlider.js +1 -1
  28. package/dist/cjs/input/Search.js +1 -1
  29. package/dist/cjs/input/Slider.js +1 -1
  30. package/dist/cjs/input/Switch.js +4 -4
  31. package/dist/cjs/input/Textarea.js +1 -1
  32. package/dist/cjs/internal/InputWrapper.js +2 -2
  33. package/dist/cjs/ranger/index.js +5 -5
  34. package/dist/cjs/select/AutoComplete.js +4 -2
  35. package/dist/cjs/select/DualList.js +2 -2
  36. package/dist/cjs/select/List.js +3 -2
  37. package/dist/cjs/select/Options.js +5 -4
  38. package/dist/cjs/select/Select.js +4 -2
  39. package/dist/cjs/select/useSelect.js +15 -13
  40. package/dist/esm/builder/FileField.js +6 -6
  41. package/dist/esm/builder/SchemaEditor.js +1 -1
  42. package/dist/esm/builder/components/SchemaArrayForm.js +1 -3
  43. package/dist/esm/builder/components/SchemaField.js +1 -1
  44. package/dist/esm/form/Controller.js +1 -1
  45. package/dist/esm/form/Form.js +14 -37
  46. package/dist/esm/form/useForm.js +32 -0
  47. package/dist/esm/hooks/useFileUploader.js +5 -5
  48. package/dist/esm/hooks/useFormBuilder.js +3 -3
  49. package/dist/esm/index.js +2 -1
  50. package/dist/esm/input/ArrayInput.js +66 -19
  51. package/dist/esm/input/AvatarInput.js +7 -7
  52. package/dist/esm/input/Checkbox.js +1 -1
  53. package/dist/esm/input/ColorInput.js +27 -20
  54. package/dist/esm/input/ColorPicker.js +17 -10
  55. package/dist/esm/input/DateInput.js +3 -3
  56. package/dist/esm/input/Field.js +1 -1
  57. package/dist/esm/input/File.js +1 -1
  58. package/dist/esm/input/Hidden.js +1 -1
  59. package/dist/esm/input/Input.js +1 -1
  60. package/dist/esm/input/Number.js +1 -1
  61. package/dist/esm/input/Password.js +1 -1
  62. package/dist/esm/input/Radio.js +1 -1
  63. package/dist/esm/input/RadioGroup.js +5 -3
  64. package/dist/esm/input/RangeSlider.js +1 -1
  65. package/dist/esm/input/Search.js +1 -1
  66. package/dist/esm/input/Slider.js +1 -1
  67. package/dist/esm/input/Switch.js +4 -4
  68. package/dist/esm/input/Textarea.js +1 -1
  69. package/dist/esm/internal/InputWrapper.js +2 -2
  70. package/dist/esm/ranger/index.js +5 -5
  71. package/dist/esm/select/AutoComplete.js +4 -2
  72. package/dist/esm/select/DualList.js +2 -2
  73. package/dist/esm/select/List.js +4 -3
  74. package/dist/esm/select/Options.js +5 -4
  75. package/dist/esm/select/Select.js +5 -3
  76. package/dist/esm/select/useSelect.js +15 -13
  77. package/dist/types/builder/SchemaEditor.d.ts +1 -1
  78. package/dist/types/form/Controller.d.ts +1 -1
  79. package/dist/types/form/Form.d.ts +1 -12
  80. package/dist/types/form/useForm.d.ts +11 -0
  81. package/dist/types/index.d.ts +3 -2
  82. package/dist/types/input/ArrayInput.d.ts +5 -4
  83. package/dist/types/input/AvatarInput.d.ts +1 -1
  84. package/dist/types/input/Checkbox.d.ts +2 -2
  85. package/dist/types/input/ColorInput.d.ts +1 -1
  86. package/dist/types/input/ColorPicker.d.ts +5 -1
  87. package/dist/types/input/DateInput.d.ts +1 -1
  88. package/dist/types/input/Field.d.ts +1 -1
  89. package/dist/types/input/File.d.ts +1 -1
  90. package/dist/types/input/Hidden.d.ts +1 -1
  91. package/dist/types/input/Input.d.ts +1 -1
  92. package/dist/types/input/Number.d.ts +1 -1
  93. package/dist/types/input/Password.d.ts +1 -1
  94. package/dist/types/input/Radio.d.ts +2 -2
  95. package/dist/types/input/RadioGroup.d.ts +3 -3
  96. package/dist/types/input/RangeSlider.d.ts +1 -1
  97. package/dist/types/input/Search.d.ts +1 -1
  98. package/dist/types/input/Slider.d.ts +1 -1
  99. package/dist/types/input/Switch.d.ts +2 -2
  100. package/dist/types/input/Textarea.d.ts +1 -1
  101. package/dist/types/select/AutoComplete.d.ts +1 -1
  102. package/dist/types/select/DualList.d.ts +1 -1
  103. package/dist/types/select/List.d.ts +1 -1
  104. package/dist/types/select/Select.d.ts +1 -1
  105. package/dist/types/types/index.d.ts +3 -3
  106. package/dist/types/types/schema.d.ts +1 -1
  107. package/package.json +14 -14
  108. package/src/builder/SchemaEditor.tsx +2 -2
  109. package/src/builder/components/SchemaArrayForm.tsx +0 -2
  110. package/src/builder/components/SchemaField.tsx +1 -1
  111. package/src/form/Controller.tsx +1 -1
  112. package/src/form/Form.tsx +1 -30
  113. package/src/form/useForm.ts +44 -0
  114. package/src/index.ts +3 -7
  115. package/src/input/ArrayInput.tsx +20 -10
  116. package/src/input/AvatarInput.tsx +1 -1
  117. package/src/input/Checkbox.tsx +2 -2
  118. package/src/input/ColorInput.tsx +29 -45
  119. package/src/input/ColorPicker.tsx +42 -49
  120. package/src/input/DateInput.tsx +3 -3
  121. package/src/input/Field.tsx +2 -2
  122. package/src/input/File.tsx +1 -1
  123. package/src/input/Hidden.tsx +1 -3
  124. package/src/input/Input.tsx +1 -1
  125. package/src/input/Number.tsx +1 -1
  126. package/src/input/Password.tsx +1 -1
  127. package/src/input/Radio.tsx +2 -2
  128. package/src/input/RadioGroup.tsx +5 -3
  129. package/src/input/RangeSlider.tsx +1 -1
  130. package/src/input/Search.tsx +1 -1
  131. package/src/input/Slider.tsx +1 -1
  132. package/src/input/Switch.tsx +6 -6
  133. package/src/input/Textarea.tsx +1 -1
  134. package/src/internal/InputWrapper.tsx +1 -2
  135. package/src/select/AutoComplete.tsx +13 -52
  136. package/src/select/DualList.tsx +2 -2
  137. package/src/select/List.tsx +29 -67
  138. package/src/select/Options.tsx +4 -3
  139. package/src/select/Select.tsx +18 -40
  140. package/src/select/useSelect.tsx +24 -69
  141. package/src/types/index.ts +3 -3
  142. package/src/types/schema.ts +1 -1
@@ -8,7 +8,7 @@ export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
8
8
  /**
9
9
  * append to label end
10
10
  */
11
- appendLabel?: JSX.Element | string | number | boolean;
11
+ appendLabel?: React.ReactElement | string | number | boolean;
12
12
  /**
13
13
  * field info
14
14
  */
@@ -52,6 +52,6 @@ export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
52
52
  * The component supports inline and vertical orientations, and can handle change events.
53
53
  *
54
54
  * @param {RadioGroupProps} props - The properties for the RadioGroup component.
55
- * @returns {JSX.Element} The rendered RadioGroup component.
55
+ * @returns {React.ReactElement} The rendered RadioGroup component.
56
56
  */
57
- export declare const RadioGroup: ({ children, name, className, optionWidth, value, onChange, ...rest }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
57
+ export declare const RadioGroup: ({ children, name, className, optionWidth, vertical, value, onChange, ...rest }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
@@ -62,6 +62,6 @@ export interface RangeProps extends Omit<InputProps<[number, number]>, "placehol
62
62
  * The component is designed to be flexible and customizable, allowing for various configurations.
63
63
  *
64
64
  * @param {RangeProps} props - The properties for the RangeSlider component.
65
- * @returns {JSX.Element} The rendered RangeSlider component.
65
+ * @returns {React.ReactElement} The rendered RangeSlider component.
66
66
  */
67
67
  export declare const RangeSlider: ({ error, name, value, step, min, max, height, color, vertical, showLabels, showValue, minLabel, maxLabel, ranges, format, autoFocus, disabled, readOnly, onBlur, onChange, onEnterPressed, onFocus, onSlide, invalid, ...rest }: RangeProps) => import("react/jsx-runtime").JSX.Element;
@@ -25,6 +25,6 @@ export interface SearchProps extends InputProps, RefProp<HTMLInputElement> {
25
25
  * and handling search actions with a debounce mechanism.
26
26
  *
27
27
  * @param {SearchProps} props - The properties for the Search component.
28
- * @returns {JSX.Element} The rendered Search input component.
28
+ * @returns {React.ReactElement} The rendered Search input component.
29
29
  */
30
30
  export declare const Search: ({ ref, value, name, invalid, readOnly, disabled, required, searching, placeholder, defaultValue, autoFocus, hideHandle, allowClear, searchOnChange, onBlur, onFocus, onSearch, onChange, onEnterPressed, ...rest }: SearchProps) => import("react/jsx-runtime").JSX.Element;
@@ -64,6 +64,6 @@ export interface SliderProps extends Omit<InputProps<number>, "placeholder" | "a
64
64
  * It also supports deferred value updates for smoother interactions.
65
65
  *
66
66
  * @param {SliderProps} props - The properties for the Slider component.
67
- * @returns {JSX.Element} The rendered Slider component.
67
+ * @returns {React.ReactElement} The rendered Slider component.
68
68
  */
69
69
  export declare const Slider: ({ error, name, value, step, min, max, height, color, vertical, showLabels, showValue, minLabel, maxLabel, ranges, useInfinity, format, invalid, autoFocus, disabled, readOnly, onBlur, onChange, onEnterPressed, onFocus, onSlide, ...rest }: SliderProps) => import("react/jsx-runtime").JSX.Element;
@@ -3,7 +3,7 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
3
3
  /**
4
4
  * Switch label
5
5
  */
6
- label?: JSX.Element | string;
6
+ label?: React.ReactElement | string;
7
7
  /**
8
8
  * checked
9
9
  */
@@ -49,6 +49,6 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
49
49
  * It supports disabled and invalid states, and handles change events.
50
50
  *
51
51
  * @param {SwitchProps} props - The properties for the Switch component.
52
- * @returns {JSX.Element} The rendered Switch input component.
52
+ * @returns {React.ReactElement} The rendered Switch input component.
53
53
  */
54
54
  export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, onLabel, offLabel, onLabelColor, offLabelColor, defaultColor, required, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
@@ -26,6 +26,6 @@ export interface TextareaProps extends InputProps, RefProp<HTMLTextAreaElement>
26
26
  * providing a clear interface for text input with optional validation and accessibility features.
27
27
  *
28
28
  * @param {TextareaProps} props - The properties for the Textarea component.
29
- * @returns {JSX.Element} The rendered Textarea component.
29
+ * @returns {React.ReactElement} The rendered Textarea component.
30
30
  */
31
31
  export declare const Textarea: ({ ref, value, name, invalid, readOnly, disabled, required, placeholder, defaultValue, autoFocus, rows, maxRows, variableRows, expandable, onBlur, onFocus, onChange, onEnterPressed, ...rest }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
@@ -18,7 +18,7 @@ type AutoCompleteProps = Omit<SelectProps<string>, "options" | "allowCreate" | "
18
18
  * It supports multiple selections, history suggestions, and custom styling.
19
19
  *
20
20
  * @param {AutoCompleteProps} props - The properties for the AutoComplete component.
21
- * @returns {JSX.Element} The rendered AutoComplete component.
21
+ * @returns {React.ReactElement} The rendered AutoComplete component.
22
22
  */
23
23
  export declare const AutoComplete: ({ ref, name, value, invalid, readOnly, disabled, required, placeholder, autoFocus, expandOnEdit, error, history, multiple, onChange, onSelect, onInput, onFocus, onBlur, onQuery, onEnterPressed, ...rest }: AutoCompleteProps) => import("react/jsx-runtime").JSX.Element;
24
24
  export {};
@@ -47,6 +47,6 @@ export interface DualListProps<T> extends Omit<FieldProps, "children">, RefProp<
47
47
  * This component is useful for scenarios where users need to manage selections from a larger set of options, such as in forms or settings.
48
48
  *
49
49
  * @param {DualListProps<T>} props - The properties for the DualList component.
50
- * @returns {JSX.Element} The rendered DualList component.
50
+ * @returns {React.ReactElement} The rendered DualList component.
51
51
  */
52
52
  export declare const DualList: <T extends AnyObject = string>({ ref, value, options, emptyDisplay, groupProperty, height, labelProperty, valueProperty, renderer, onChange, name, invalid, readOnly, disabled, placeholder, autoFocus, error, ...rest }: DualListProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -5,7 +5,7 @@ import { type SelectProps } from "../types";
5
5
  * and custom rendering of options.
6
6
  *
7
7
  * @param {SelectProps<T>} props - The properties for the List component.
8
- * @returns {JSX.Element} The rendered List component.
8
+ * @returns {React.ReactElement} The rendered List component.
9
9
  */
10
10
  export declare const List: <T extends AnyObject = string>({ ref, name, value, readOnly, disabled, required, placeholder, autoFocus, options, height, groupProperty, labelProperty, valueProperty, infoProperty, sortProperty, multiple, allowCreate, searchable, createOption, matcher, renderer, onQuery, onChange, onSelect, onEnterPressed, emptyDisplay, invalid, error, allowClear, decorateStart, decorateEnd, "data-inner": isInner, "data-hide-selected": hideSelected, ...rest }: Omit<SelectProps<T>, "defaultOpen" | "hideHandle"> & {
11
11
  height?: string | number;
@@ -5,6 +5,6 @@ import { type SelectProps } from "../types";
5
5
  * and custom rendering of options.
6
6
  *
7
7
  * @param {SelectProps<T>} props - The properties for the Select component.
8
- * @returns {JSX.Element} The rendered Select component.
8
+ * @returns {React.ReactElement} The rendered Select component.
9
9
  */
10
10
  export declare const Select: <T extends AnyObject = string>({ ref, name, value, invalid, readOnly, disabled, required, placeholder, autoFocus, error, options, defaultOpen, hideHandle, groupProperty, labelProperty, valueProperty, sortProperty, infoProperty, multiple, searchable, allowCreate, emptyDisplay, createOption, matcher, renderer, onQuery, onChange, onSelect, onEnterPressed, ...rest }: SelectProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -39,15 +39,15 @@ export interface InputProps<V = string> extends TestProps {
39
39
  /**
40
40
  * append to label end
41
41
  */
42
- appendLabel?: JSX.Element | string | number | boolean;
42
+ appendLabel?: React.ReactElement | string | number | boolean;
43
43
  /**
44
44
  *
45
45
  */
46
- decorateStart?: JSX.Element | string | number | boolean;
46
+ decorateStart?: React.ReactElement | string | number | boolean;
47
47
  /**
48
48
  *
49
49
  */
50
- decorateEnd?: JSX.Element | string | number | boolean;
50
+ decorateEnd?: React.ReactElement | string | number | boolean;
51
51
  decorateEndShowWhenEmpty?: boolean;
52
52
  decorateEndHideWhenEmpty?: boolean;
53
53
  /**
@@ -97,7 +97,7 @@ export interface SchemaEditorProps {
97
97
  /**
98
98
  * footer actions
99
99
  */
100
- children?: Elements<JSX.Element> | Array<Elements<JSX.Element>>;
100
+ children?: Elements<React.ReactElement> | Array<Elements<React.ReactElement>>;
101
101
  onChange?: (schema: FormSchema) => void;
102
102
  onSubmit?: (schema: FormSchema) => void;
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/form",
3
- "version": "1.0.0-beta.62",
3
+ "version": "1.0.0-beta.63",
4
4
  "description": "RUF: Form package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -39,28 +39,28 @@
39
39
  "@dnd-kit/modifiers": "~9.0.0",
40
40
  "@dnd-kit/sortable": "~10.0.0",
41
41
  "@dnd-kit/utilities": "~3.2.2",
42
- "@floating-ui/react": "~0.27.16",
42
+ "@floating-ui/react": "~0.27.19",
43
43
  "@hookform/resolvers": "~5.2.2",
44
- "@react-fabric/core": "^1.0.0-beta.62",
45
- "@react-fabric/date": "^1.0.0-beta.62",
46
- "@react-fabric/utilities": "^1.0.0-beta.62",
44
+ "@react-fabric/core": "^1.0.0-beta.63",
45
+ "@react-fabric/date": "^1.0.0-beta.63",
46
+ "@react-fabric/utilities": "^1.0.0-beta.63",
47
+ "chroma-js": "~3.2.0",
47
48
  "classnames": "~2.5.1",
48
- "color": "~5.0.2",
49
49
  "react-color": "~2.19.3",
50
- "react-hook-form": "~7.65.0"
50
+ "react-hook-form": "~7.71.2"
51
51
  },
52
52
  "peerDependencies": {
53
- "i18next": "~25.6.0",
54
- "react": "~19.2.0",
55
- "react-dom": "~19.2.0",
56
- "react-i18next": "~16.2.1"
53
+ "i18next": "~25.8.18",
54
+ "react": "~19.2.4",
55
+ "react-dom": "~19.2.4",
56
+ "react-i18next": "~16.5.8"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/react-color": "~3.0.13"
60
60
  },
61
61
  "engines": {
62
- "node": ">=18.12.0",
63
- "npm": ">=8.19.0"
62
+ "node": ">=22.18.0",
63
+ "npm": ">=10.8.0"
64
64
  },
65
- "gitHead": "9dce2fd9bb753d67e3f8adbf50be257b4bc64242"
65
+ "gitHead": "6e0652b15c6384fbc316842862572e21299a5466"
66
66
  }
@@ -37,7 +37,7 @@ import { SchemaArrayForm } from "./components/SchemaArrayForm";
37
37
  * It provides a form interface to modify schema properties dynamically.
38
38
  *
39
39
  * @param {SchemaEditorProps} props - The properties for the SchemaEditor component.
40
- * @returns {JSX.Element} The rendered SchemaEditor component.
40
+ * @returns {React.ReactElement} The rendered SchemaEditor component.
41
41
  */
42
42
  export const SchemaEditor = ({
43
43
  schemaDef,
@@ -70,7 +70,7 @@ export const SchemaEditor = ({
70
70
  acceptableTypes={acceptableTypes ?? Object.values(DATA_TYPES)}
71
71
  />
72
72
  {children && (
73
- <Footer flex className="border-t bg-base px-6 py-2">
73
+ <Footer flex className="border-t bg-default px-6 py-2">
74
74
  {children}
75
75
  </Footer>
76
76
  )}
@@ -33,7 +33,6 @@ import { AddSchemaFields } from "./AddSchemaFields";
33
33
  import { SchemaField } from "./SchemaField";
34
34
 
35
35
  // Need to disable prop-types lint due to uknown lint error
36
- /* eslint-disable react/prop-types */
37
36
  export const SchemaArrayForm = ({
38
37
  dynamic,
39
38
  acceptableTypes,
@@ -75,7 +74,6 @@ export const SchemaArrayForm = ({
75
74
  }, []);
76
75
 
77
76
  const Wrapper = useCallback(
78
- // eslint-disable-next-line @typescript-eslint/promise-function-async
79
77
  ({ children }: { children: React.ReactNode }) => {
80
78
  if (dynamic) {
81
79
  // pass id list to dnd context
@@ -147,7 +147,7 @@ export const SchemaField = ({
147
147
  <Footer
148
148
  flex
149
149
  justify="end"
150
- className="sticky bottom-0 border-t bg-base px-6 py-2"
150
+ className="sticky bottom-0 border-t bg-default px-6 py-2"
151
151
  >
152
152
  <Button variant="link" onClick={props.onClose}>
153
153
  Close
@@ -76,7 +76,7 @@ export interface ControllerProps {
76
76
  * to the child component, allowing for proper focus management and DOM access.
77
77
  *
78
78
  * @param {ControllerProps} props - The properties for the Controller component.
79
- * @returns {JSX.Element} The rendered Controller component.
79
+ * @returns {React.ReactElement} The rendered Controller component.
80
80
  *
81
81
  * @example
82
82
  * ```jsx
package/src/form/Form.tsx CHANGED
@@ -92,7 +92,7 @@ const DEFAULT_SUBMIT = () => undefined;
92
92
  * It supports nested form structures and allows for custom validation schemas using Yup.
93
93
  *
94
94
  * @param {FormProps<K>} props - The properties for the Form component.
95
- * @returns {JSX.Element} The rendered Form component.
95
+ * @returns {React.ReactElement} The rendered Form component.
96
96
  *
97
97
  * @example
98
98
  * ```jsx
@@ -211,32 +211,3 @@ export const Form = <K extends KeyValue>({
211
211
  </FormProvider>
212
212
  );
213
213
  };
214
-
215
- export const useForm = <K extends KeyValue = KeyValue>() => {
216
- const {
217
- formState,
218
- getValues,
219
- setValue,
220
- watch,
221
- reset,
222
- resetField,
223
- setError,
224
- setFocus,
225
- } = useFormContext<K>();
226
- const values = useWatch<K>();
227
-
228
- return {
229
- values: {
230
- ...values,
231
- ...getValues(),
232
- },
233
- formState,
234
- getValues,
235
- setValue,
236
- watch,
237
- reset,
238
- resetField,
239
- setError,
240
- setFocus,
241
- };
242
- };
@@ -0,0 +1,44 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2026 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 { useFormContext, useWatch } from "react-hook-form";
25
+
26
+ export const useForm = <K extends KeyValue = KeyValue>() => {
27
+ const { formState, getValues, setValue, watch, reset, resetField, setError, setFocus } = useFormContext<K>();
28
+ const values = useWatch<K>();
29
+
30
+ return {
31
+ values: {
32
+ ...values,
33
+ ...getValues(),
34
+ },
35
+ formState,
36
+ getValues,
37
+ setValue,
38
+ watch,
39
+ reset,
40
+ resetField,
41
+ setError,
42
+ setFocus,
43
+ };
44
+ };
package/src/index.ts CHANGED
@@ -24,19 +24,15 @@
24
24
  import "./i18n";
25
25
 
26
26
  export { Controller } from "./form/Controller";
27
- export { Form, useForm, type FormRef } from "./form/Form";
27
+ export { Form, type FormRef } from "./form/Form";
28
+ export { useForm } from "./form/useForm";
28
29
 
29
30
  export { SchemaEditor } from "./builder/SchemaEditor";
30
31
 
31
32
  export { useFileUploader } from "./hooks/useFileUploader";
32
33
  export { useFormBuilder } from "./hooks/useFormBuilder";
33
34
 
34
- export {
35
- DATA_TYPES,
36
- SCHEMA_CUSTOM_LIST,
37
- type FormSchema,
38
- type SchemaDef,
39
- } from "./types/schema";
35
+ export { DATA_TYPES, SCHEMA_CUSTOM_LIST, type FormSchema, type SchemaDef } from "./types/schema";
40
36
 
41
37
  export { ArrayInput } from "./input/ArrayInput";
42
38
  export { AvatarInput } from "./input/AvatarInput";
@@ -51,7 +51,7 @@ export interface ArrayInputProps<T extends AnyObject = string> {
51
51
  /**
52
52
  * append to label end
53
53
  */
54
- appendLabel?: JSX.Element | string | number | boolean;
54
+ appendLabel?: React.ReactElement | string | number | boolean;
55
55
  /**
56
56
  * info label at bottom
57
57
  */
@@ -91,20 +91,27 @@ export interface ArrayInputProps<T extends AnyObject = string> {
91
91
  enableSorting?: boolean;
92
92
  children:
93
93
  | React.ReactNode
94
- | ((props: { index: number; name: string; item: T }) => React.ReactNode);
94
+ | ((props: {
95
+ index: number;
96
+ name: string;
97
+ item: T;
98
+ onChange: (val: false | undefined | T) => void;
99
+ }) => React.ReactNode);
95
100
  /**
96
101
  * add item button label
97
102
  */
98
103
  addLabel?: string;
99
104
  buttonPosition?: "top" | "bottom" | "both";
100
105
  arrayRef?: Ref<{
101
- addItem: (item: T) => void;
106
+ addItem: (
107
+ item: false | undefined | T | Promise<false | undefined | T>,
108
+ ) => void;
102
109
  removeItem: (idx: number) => void;
103
110
  }>;
104
111
  /**
105
112
  * add new item
106
113
  */
107
- onAdd?: () => T;
114
+ onAdd?: () => false | undefined | T | Promise<false | undefined | T>;
108
115
  /**
109
116
  * on item remove
110
117
  */
@@ -147,7 +154,7 @@ export interface ArrayInputProps<T extends AnyObject = string> {
147
154
  * It also supports drag-and-drop sorting using `@dnd-kit/core` and `@dnd-kit/sortable` for a better user experience when reordering items.
148
155
  *
149
156
  * @param {ArrayInputProps<T>} props - The properties for the ArrayInput component.
150
- * @returns {JSX.Element} The rendered ArrayInput component.
157
+ * @returns {React.ReactElement} The rendered ArrayInput component.
151
158
  *
152
159
  * @example
153
160
  * ```jsx
@@ -235,9 +242,9 @@ export const ArrayInput = <T extends AnyObject = string>({
235
242
  );
236
243
 
237
244
  const handleAdd = useCallback(
238
- (item?: T) => {
245
+ async (item?: Promise<false | undefined | T>) => {
239
246
  if (!item) return;
240
- append(item);
247
+ append((await item) as T);
241
248
  setTimeout(() => {
242
249
  form.setFocus(
243
250
  `${name}.${fields.length}${focusName ? "." + focusName : ""}`,
@@ -261,12 +268,11 @@ export const ArrayInput = <T extends AnyObject = string>({
261
268
  );
262
269
 
263
270
  useImperativeHandle(arrayRef, () => ({
264
- addItem: handleAdd,
271
+ addItem: (t) => handleAdd(Promise.resolve(t)),
265
272
  removeItem: remove,
266
273
  }));
267
274
 
268
275
  const Wrapper = useCallback(
269
- // eslint-disable-next-line @typescript-eslint/promise-function-async
270
276
  ({ children }: { children: React.ReactNode }) => {
271
277
  if (enableSorting) {
272
278
  // pass id list to dnd context
@@ -364,7 +370,7 @@ export const ArrayInput = <T extends AnyObject = string>({
364
370
  size="sm"
365
371
  aria-label="Add item"
366
372
  icon="icon-[mdi--plus-circle-outline]"
367
- onClick={() => handleAdd(onAdd?.())}
373
+ onClick={() => handleAdd(Promise.resolve(onAdd?.()))}
368
374
  data-invalid={!!error}
369
375
  disabled={!!disabled || readOnly || fields.length > maxItems}
370
376
  className={classNames(
@@ -411,6 +417,10 @@ export const ArrayInput = <T extends AnyObject = string>({
411
417
  index,
412
418
  item: item as any,
413
419
  name: `${name}.${index}`,
420
+ onChange: async (val) => {
421
+ const result = await Promise.resolve(val);
422
+ result && form.setValue(`${name}.${index}`, result);
423
+ },
414
424
  })
415
425
  : cloneChildren(children, (child: AnyObject) =>
416
426
  cloneElement(
@@ -75,7 +75,7 @@ export interface Props extends RefProp {
75
75
  * It also provides a way to remove the uploaded file and shows upload progress.
76
76
  *
77
77
  * @param {Props} props - The properties for the AvatarInput component.
78
- * @returns {JSX.Element} - The rendered AvatarInput component.
78
+ * @returns {React.ReactElement} - The rendered AvatarInput component.
79
79
  */
80
80
  export const AvatarInput = ({
81
81
  size = "6rem",
@@ -38,7 +38,7 @@ interface CheckboxProps extends RefProp<HTMLInputElement> {
38
38
  /**
39
39
  * checkbox label
40
40
  */
41
- label?: JSX.Element | string;
41
+ label?: React.ReactElement | string;
42
42
  /**
43
43
  * checked
44
44
  */
@@ -88,7 +88,7 @@ interface CheckboxProps extends RefProp<HTMLInputElement> {
88
88
  * It also provides an error icon to indicate validation errors.
89
89
  *
90
90
  * @param {CheckboxProps} props - The properties for the Checkbox component.
91
- * @returns {JSX.Element} The rendered Checkbox component.
91
+ * @returns {React.ReactElement} The rendered Checkbox component.
92
92
  */
93
93
  export const Checkbox = ({
94
94
  ref,
@@ -26,6 +26,7 @@ import {
26
26
  autoUpdate,
27
27
  flip,
28
28
  FloatingArrow,
29
+ FloatingFocusManager,
29
30
  offset,
30
31
  shift,
31
32
  useClick,
@@ -35,22 +36,12 @@ import {
35
36
  } from "@floating-ui/react";
36
37
  import { Icon } from "@react-fabric/core";
37
38
  import { type RefProp } from "@react-fabric/core/dist/types/types";
38
- import {
39
- startTransition,
40
- useCallback,
41
- useDeferredValue,
42
- useEffect,
43
- useRef,
44
- useState,
45
- } from "react";
39
+ import { startTransition, useCallback, useDeferredValue, useEffect, useRef, useState } from "react";
46
40
  import { InputWrapper } from "../internal/InputWrapper";
47
41
  import { type InputProps } from "../types";
48
42
  import { ColorPicker, type ColorProps } from "./ColorPicker";
49
43
 
50
- export interface ColorInputProps
51
- extends InputProps,
52
- Omit<ColorProps, "onChange">,
53
- RefProp {
44
+ export interface ColorInputProps extends InputProps, Omit<ColorProps, "onChange">, RefProp {
54
45
  /**
55
46
  * show eydrop picker
56
47
  */
@@ -68,7 +59,7 @@ export interface ColorInputProps
68
59
  * and handling the color selection state.
69
60
  *
70
61
  * @param {ColorInputProps} props - The properties for the ColorInput component.
71
- * @returns {JSX.Element} - The rendered ColorInput component.
62
+ * @returns {React.ReactElement} - The rendered ColorInput component.
72
63
  */
73
64
  export const ColorInput = ({
74
65
  ref,
@@ -130,10 +121,7 @@ export const ColorInput = ({
130
121
  referencePress: true,
131
122
  });
132
123
 
133
- const { getReferenceProps, getFloatingProps } = useInteractions([
134
- dismiss,
135
- click,
136
- ]);
124
+ const { getReferenceProps, getFloatingProps } = useInteractions([dismiss, click]);
137
125
 
138
126
  return (
139
127
  <InputWrapper
@@ -167,34 +155,32 @@ export const ColorInput = ({
167
155
  pointerEvents: disabled ? "none" : undefined,
168
156
  }}
169
157
  >
170
- {!actualValue && (
171
- <Icon size="md" className="text-muted" icon="icon-[mdi--palette]" />
172
- )}
158
+ {!actualValue && <Icon size="md" className="text-muted" icon="icon-[mdi--palette]" />}
173
159
  </div>
174
160
  </button>
175
161
  {isOpen && (
176
- <div
177
- ref={refs.setFloating}
178
- style={{
179
- zIndex: "var(--z-popover)",
180
- ...floatingStyles,
181
- }}
182
- data-ref="dropdownBody"
183
- {...getFloatingProps()}
184
- >
185
- <ColorPicker
186
- {...rest}
187
- onChange={handleChange}
188
- defaultColor={defaultColor}
189
- value={actualValue}
190
- />
191
- <FloatingArrow
192
- ref={arrowRef}
193
- context={context}
194
- strokeWidth={0.5}
195
- className="fill-base stroke-muted"
196
- />
197
- </div>
162
+ <FloatingFocusManager context={context} closeOnFocusOut>
163
+ <div
164
+ ref={refs.setFloating}
165
+ style={{
166
+ zIndex: "var(--z-popover)",
167
+ ...floatingStyles,
168
+ }}
169
+ data-ref="dropdownBody"
170
+ {...getFloatingProps()}
171
+ >
172
+ <ColorPicker {...rest} onChange={handleChange} defaultColor={defaultColor} value={actualValue} />
173
+ <FloatingArrow
174
+ ref={arrowRef}
175
+ context={context}
176
+ strokeWidth={0.5}
177
+ className="stroke-muted"
178
+ style={{
179
+ fill: actualValue || "var(--bg-color-base)",
180
+ }}
181
+ />
182
+ </div>
183
+ </FloatingFocusManager>
198
184
  )}
199
185
  {!disabled && showPicker && (
200
186
  <Icon
@@ -202,9 +188,7 @@ export const ColorInput = ({
202
188
  icon="icon-[mdi--eyedropper]"
203
189
  onClick={() =>
204
190
  (window as AnyObject).EyeDropper &&
205
- new (window as AnyObject).EyeDropper()
206
- .open()
207
- .then((resp: AnyObject) => handleChange(resp.sRGBHex))
191
+ new (window as AnyObject).EyeDropper().open().then((resp: AnyObject) => handleChange(resp.sRGBHex))
208
192
  }
209
193
  />
210
194
  )}