@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.
- package/css/_colorPicker.css +35 -5
- package/css/_file.css +2 -2
- package/dist/cjs/builder/FileField.js +6 -6
- package/dist/cjs/builder/SchemaEditor.js +1 -1
- package/dist/cjs/builder/components/SchemaArrayForm.js +1 -3
- package/dist/cjs/builder/components/SchemaField.js +1 -1
- package/dist/cjs/form/Controller.js +1 -1
- package/dist/cjs/form/Form.js +11 -35
- package/dist/cjs/form/useForm.js +32 -0
- package/dist/cjs/hooks/useFileUploader.js +5 -5
- package/dist/cjs/hooks/useFormBuilder.js +3 -3
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/input/ArrayInput.js +66 -19
- package/dist/cjs/input/AvatarInput.js +7 -7
- package/dist/cjs/input/Checkbox.js +1 -1
- package/dist/cjs/input/ColorInput.js +26 -19
- package/dist/cjs/input/ColorPicker.js +16 -9
- package/dist/cjs/input/DateInput.js +3 -3
- package/dist/cjs/input/Field.js +1 -1
- package/dist/cjs/input/File.js +1 -1
- package/dist/cjs/input/Hidden.js +1 -1
- package/dist/cjs/input/Input.js +1 -1
- package/dist/cjs/input/Number.js +1 -1
- package/dist/cjs/input/Password.js +1 -1
- package/dist/cjs/input/Radio.js +1 -1
- package/dist/cjs/input/RadioGroup.js +5 -3
- package/dist/cjs/input/RangeSlider.js +1 -1
- package/dist/cjs/input/Search.js +1 -1
- package/dist/cjs/input/Slider.js +1 -1
- package/dist/cjs/input/Switch.js +4 -4
- package/dist/cjs/input/Textarea.js +1 -1
- package/dist/cjs/internal/InputWrapper.js +2 -2
- package/dist/cjs/ranger/index.js +5 -5
- package/dist/cjs/select/AutoComplete.js +4 -2
- package/dist/cjs/select/DualList.js +2 -2
- package/dist/cjs/select/List.js +3 -2
- package/dist/cjs/select/Options.js +5 -4
- package/dist/cjs/select/Select.js +4 -2
- package/dist/cjs/select/useSelect.js +15 -13
- package/dist/esm/builder/FileField.js +6 -6
- package/dist/esm/builder/SchemaEditor.js +1 -1
- package/dist/esm/builder/components/SchemaArrayForm.js +1 -3
- package/dist/esm/builder/components/SchemaField.js +1 -1
- package/dist/esm/form/Controller.js +1 -1
- package/dist/esm/form/Form.js +14 -37
- package/dist/esm/form/useForm.js +32 -0
- package/dist/esm/hooks/useFileUploader.js +5 -5
- package/dist/esm/hooks/useFormBuilder.js +3 -3
- package/dist/esm/index.js +2 -1
- package/dist/esm/input/ArrayInput.js +66 -19
- package/dist/esm/input/AvatarInput.js +7 -7
- package/dist/esm/input/Checkbox.js +1 -1
- package/dist/esm/input/ColorInput.js +27 -20
- package/dist/esm/input/ColorPicker.js +17 -10
- package/dist/esm/input/DateInput.js +3 -3
- package/dist/esm/input/Field.js +1 -1
- package/dist/esm/input/File.js +1 -1
- package/dist/esm/input/Hidden.js +1 -1
- package/dist/esm/input/Input.js +1 -1
- package/dist/esm/input/Number.js +1 -1
- package/dist/esm/input/Password.js +1 -1
- package/dist/esm/input/Radio.js +1 -1
- package/dist/esm/input/RadioGroup.js +5 -3
- package/dist/esm/input/RangeSlider.js +1 -1
- package/dist/esm/input/Search.js +1 -1
- package/dist/esm/input/Slider.js +1 -1
- package/dist/esm/input/Switch.js +4 -4
- package/dist/esm/input/Textarea.js +1 -1
- package/dist/esm/internal/InputWrapper.js +2 -2
- package/dist/esm/ranger/index.js +5 -5
- package/dist/esm/select/AutoComplete.js +4 -2
- package/dist/esm/select/DualList.js +2 -2
- package/dist/esm/select/List.js +4 -3
- package/dist/esm/select/Options.js +5 -4
- package/dist/esm/select/Select.js +5 -3
- package/dist/esm/select/useSelect.js +15 -13
- package/dist/types/builder/SchemaEditor.d.ts +1 -1
- package/dist/types/form/Controller.d.ts +1 -1
- package/dist/types/form/Form.d.ts +1 -12
- package/dist/types/form/useForm.d.ts +11 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/input/ArrayInput.d.ts +5 -4
- package/dist/types/input/AvatarInput.d.ts +1 -1
- package/dist/types/input/Checkbox.d.ts +2 -2
- package/dist/types/input/ColorInput.d.ts +1 -1
- package/dist/types/input/ColorPicker.d.ts +5 -1
- package/dist/types/input/DateInput.d.ts +1 -1
- package/dist/types/input/Field.d.ts +1 -1
- package/dist/types/input/File.d.ts +1 -1
- package/dist/types/input/Hidden.d.ts +1 -1
- package/dist/types/input/Input.d.ts +1 -1
- package/dist/types/input/Number.d.ts +1 -1
- package/dist/types/input/Password.d.ts +1 -1
- package/dist/types/input/Radio.d.ts +2 -2
- package/dist/types/input/RadioGroup.d.ts +3 -3
- package/dist/types/input/RangeSlider.d.ts +1 -1
- package/dist/types/input/Search.d.ts +1 -1
- package/dist/types/input/Slider.d.ts +1 -1
- package/dist/types/input/Switch.d.ts +2 -2
- package/dist/types/input/Textarea.d.ts +1 -1
- package/dist/types/select/AutoComplete.d.ts +1 -1
- package/dist/types/select/DualList.d.ts +1 -1
- package/dist/types/select/List.d.ts +1 -1
- package/dist/types/select/Select.d.ts +1 -1
- package/dist/types/types/index.d.ts +3 -3
- package/dist/types/types/schema.d.ts +1 -1
- package/package.json +14 -14
- package/src/builder/SchemaEditor.tsx +2 -2
- package/src/builder/components/SchemaArrayForm.tsx +0 -2
- package/src/builder/components/SchemaField.tsx +1 -1
- package/src/form/Controller.tsx +1 -1
- package/src/form/Form.tsx +1 -30
- package/src/form/useForm.ts +44 -0
- package/src/index.ts +3 -7
- package/src/input/ArrayInput.tsx +20 -10
- package/src/input/AvatarInput.tsx +1 -1
- package/src/input/Checkbox.tsx +2 -2
- package/src/input/ColorInput.tsx +29 -45
- package/src/input/ColorPicker.tsx +42 -49
- package/src/input/DateInput.tsx +3 -3
- package/src/input/Field.tsx +2 -2
- package/src/input/File.tsx +1 -1
- package/src/input/Hidden.tsx +1 -3
- package/src/input/Input.tsx +1 -1
- package/src/input/Number.tsx +1 -1
- package/src/input/Password.tsx +1 -1
- package/src/input/Radio.tsx +2 -2
- package/src/input/RadioGroup.tsx +5 -3
- package/src/input/RangeSlider.tsx +1 -1
- package/src/input/Search.tsx +1 -1
- package/src/input/Slider.tsx +1 -1
- package/src/input/Switch.tsx +6 -6
- package/src/input/Textarea.tsx +1 -1
- package/src/internal/InputWrapper.tsx +1 -2
- package/src/select/AutoComplete.tsx +13 -52
- package/src/select/DualList.tsx +2 -2
- package/src/select/List.tsx +29 -67
- package/src/select/Options.tsx +4 -3
- package/src/select/Select.tsx +18 -40
- package/src/select/useSelect.tsx +24 -69
- package/src/types/index.ts +3 -3
- 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?:
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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?:
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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?:
|
|
42
|
+
appendLabel?: React.ReactElement | string | number | boolean;
|
|
43
43
|
/**
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
|
-
decorateStart?:
|
|
46
|
+
decorateStart?: React.ReactElement | string | number | boolean;
|
|
47
47
|
/**
|
|
48
48
|
*
|
|
49
49
|
*/
|
|
50
|
-
decorateEnd?:
|
|
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<
|
|
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.
|
|
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.
|
|
42
|
+
"@floating-ui/react": "~0.27.19",
|
|
43
43
|
"@hookform/resolvers": "~5.2.2",
|
|
44
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
45
|
-
"@react-fabric/date": "^1.0.0-beta.
|
|
46
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
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.
|
|
50
|
+
"react-hook-form": "~7.71.2"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"i18next": "~25.
|
|
54
|
-
"react": "~19.2.
|
|
55
|
-
"react-dom": "~19.2.
|
|
56
|
-
"react-i18next": "~16.
|
|
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.
|
|
63
|
-
"npm": ">=8.
|
|
62
|
+
"node": ">=22.18.0",
|
|
63
|
+
"npm": ">=10.8.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
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 {
|
|
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-
|
|
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-
|
|
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
|
package/src/form/Controller.tsx
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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,
|
|
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";
|
package/src/input/ArrayInput.tsx
CHANGED
|
@@ -51,7 +51,7 @@ export interface ArrayInputProps<T extends AnyObject = string> {
|
|
|
51
51
|
/**
|
|
52
52
|
* append to label end
|
|
53
53
|
*/
|
|
54
|
-
appendLabel?:
|
|
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: {
|
|
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: (
|
|
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 {
|
|
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 {
|
|
78
|
+
* @returns {React.ReactElement} - The rendered AvatarInput component.
|
|
79
79
|
*/
|
|
80
80
|
export const AvatarInput = ({
|
|
81
81
|
size = "6rem",
|
package/src/input/Checkbox.tsx
CHANGED
|
@@ -38,7 +38,7 @@ interface CheckboxProps extends RefProp<HTMLInputElement> {
|
|
|
38
38
|
/**
|
|
39
39
|
* checkbox label
|
|
40
40
|
*/
|
|
41
|
-
label?:
|
|
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 {
|
|
91
|
+
* @returns {React.ReactElement} The rendered Checkbox component.
|
|
92
92
|
*/
|
|
93
93
|
export const Checkbox = ({
|
|
94
94
|
ref,
|
package/src/input/ColorInput.tsx
CHANGED
|
@@ -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 {
|
|
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
|
-
<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
{...rest}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
</
|
|
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
|
)}
|