react-compose-form 0.0.6-beta.0 → 0.0.6-beta.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.
- package/lib/blocks/ControllerWithContext.d.ts +3 -0
- package/lib/blocks/ControllerWithContext.js +6 -0
- package/lib/blocks/FormControl.d.ts +2 -1
- package/lib/blocks/FormControl.js +8 -9
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/types/FormFieldProps.d.ts +2 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/package.json +1 -1
- package/lib/contexts/FormRegistryContext.d.ts +0 -1
- package/lib/contexts/FormRegistryContext.js +0 -6
- package/lib/types/FormControl.d.ts +0 -4
- /package/lib/types/{FormControl.js → FormFieldProps.js} +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
3
|
+
export const ControllerWithContext = (props) => {
|
|
4
|
+
const { control } = useFormContext();
|
|
5
|
+
return (_jsx(Controller, Object.assign({}, props, { control: control })));
|
|
6
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ComponentType } from "react";
|
|
2
2
|
import { Control, ControllerRenderProps, Message, ValidationRule, ControllerFieldState } from "react-hook-form";
|
|
3
|
-
|
|
3
|
+
import { FormFieldProps } from "../types";
|
|
4
4
|
export type FormControlProps<P = unknown> = Omit<P, "as" | "name" | "disabled" | "required" | keyof ControllerFieldState | keyof ControllerRenderProps> & {
|
|
5
5
|
as?: ComponentType<FormFieldProps<P>>;
|
|
6
6
|
name: string;
|
|
7
7
|
disabled?: boolean;
|
|
8
|
+
withState?: boolean;
|
|
8
9
|
required?: Message | ValidationRule<boolean>;
|
|
9
10
|
control?: Control;
|
|
10
11
|
};
|
|
@@ -10,20 +10,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
13
|
+
import { Controller } from "react-hook-form";
|
|
14
14
|
import { FormControlContext } from "../contexts";
|
|
15
15
|
import { useFormGroupName } from "../hooks";
|
|
16
|
-
|
|
17
|
-
const { control } = useFormContext();
|
|
18
|
-
return (_jsx(Controller, Object.assign({}, props, { control: control })));
|
|
19
|
-
};
|
|
16
|
+
import { ControllerWithContext } from "./ControllerWithContext";
|
|
20
17
|
export const FormControl = (props) => {
|
|
21
|
-
const { as: Component = "input", name, disabled = false, required, control } = props, rest = __rest(props, ["as", "name", "disabled", "required", "control"]);
|
|
18
|
+
const { as: Component = "input", name, disabled = false, withState, required, control } = props, rest = __rest(props, ["as", "name", "disabled", "withState", "required", "control"]);
|
|
22
19
|
const fullName = useFormGroupName(name);
|
|
23
|
-
const
|
|
24
|
-
|
|
20
|
+
const ControllerComponent = control
|
|
21
|
+
? Controller
|
|
22
|
+
: ControllerWithContext;
|
|
23
|
+
return (_jsx(ControllerComponent, { control: control, disabled: disabled, name: fullName, rules: {
|
|
25
24
|
required
|
|
26
25
|
}, render: ({ field, fieldState }) => {
|
|
27
|
-
return (_jsx(FormControlContext, { value: fieldState, children: _jsx(Component, Object.assign({}, rest, field)) }));
|
|
26
|
+
return (_jsx(FormControlContext, { value: fieldState, children: _jsx(Component, Object.assign({}, rest, withState ? fieldState : {}, field)) }));
|
|
28
27
|
} }));
|
|
29
28
|
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useFormRegistry: () => void;
|
|
File without changes
|