react-compose-form 0.0.6-beta.3 → 0.0.6-beta.5
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/Form.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ElementType } from "react";
|
|
2
2
|
import { UseFormProps, FieldValues, SubmitHandler, SubmitErrorHandler } from "react-hook-form";
|
|
3
|
-
import { PolymorphicComponentProps } from "../types
|
|
4
|
-
export type FormProps<T extends FieldValues = FieldValues, C extends ElementType = "form"> = PolymorphicComponentProps<
|
|
3
|
+
import { PolymorphicComponentProps } from "../types";
|
|
4
|
+
export type FormProps<T extends FieldValues = FieldValues, C = any, E extends ElementType = "form"> = PolymorphicComponentProps<E, UseFormProps<T, C> & {
|
|
5
5
|
onSubmit?: SubmitHandler<T>;
|
|
6
6
|
onInvalid?: SubmitErrorHandler<T>;
|
|
7
7
|
}>;
|
|
8
|
-
export declare const Form: <T extends FieldValues = FieldValues, C extends ElementType = "form">(props: FormProps<T, C>) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const Form: <T extends FieldValues = FieldValues, C = any, E extends ElementType = "form">(props: FormProps<T, C, E>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentType } from "react";
|
|
2
|
-
import { Control, ControllerRenderProps, Message, ValidationRule, ControllerFieldState } from "react-hook-form";
|
|
2
|
+
import { Control, ControllerRenderProps, Message, ValidationRule, ControllerFieldState, Validate } 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>>;
|
|
@@ -7,6 +7,7 @@ export type FormControlProps<P = unknown> = Omit<P, "as" | "name" | "disabled" |
|
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
withState?: boolean;
|
|
9
9
|
required?: Message | ValidationRule<boolean>;
|
|
10
|
+
validate?: Validate<any, any> | Record<string, Validate<any, any>>;
|
|
10
11
|
control?: Control;
|
|
11
12
|
};
|
|
12
13
|
export declare const FormControl: <P = unknown>(props: FormControlProps<P>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -15,13 +15,14 @@ import { FormControlContext } from "../contexts";
|
|
|
15
15
|
import { useFormGroupName } from "../hooks";
|
|
16
16
|
import { ControllerWithContext } from "./ControllerWithContext";
|
|
17
17
|
export const FormControl = (props) => {
|
|
18
|
-
const { as: Component = "input", name, disabled = false, withState, required, control } = props, rest = __rest(props, ["as", "name", "disabled", "withState", "required", "control"]);
|
|
18
|
+
const { as: Component = "input", name, disabled = false, withState, required, validate, control } = props, rest = __rest(props, ["as", "name", "disabled", "withState", "required", "validate", "control"]);
|
|
19
19
|
const fullName = useFormGroupName(name);
|
|
20
20
|
const ControllerComponent = control
|
|
21
21
|
? Controller
|
|
22
22
|
: ControllerWithContext;
|
|
23
23
|
return (_jsx(ControllerComponent, { control: control, disabled: disabled, name: fullName, rules: {
|
|
24
|
-
required
|
|
24
|
+
required,
|
|
25
|
+
validate
|
|
25
26
|
}, render: ({ field, fieldState }) => {
|
|
26
27
|
return (_jsx(FormControlContext, { value: fieldState, children: _jsx(Component, Object.assign({}, rest, withState ? fieldState : {}, field)) }));
|
|
27
28
|
} }));
|
package/package.json
CHANGED