aha-components 1.5.8 → 1.6.1
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/dist/Form.esm.js +1 -1
- package/dist/Form.esm.js.map +1 -1
- package/dist/Form.js +1 -1
- package/dist/Form.js.map +1 -1
- package/dist/components/Form/FormContext.d.ts +7 -0
- package/dist/components/Form/index.d.ts +29 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -30,6 +30,22 @@ export interface FormProps {
|
|
|
30
30
|
/** 子元素 */
|
|
31
31
|
children?: React.ReactNode;
|
|
32
32
|
}
|
|
33
|
+
/** scrollToField 的选项,与 Element.scrollIntoView 一致 */
|
|
34
|
+
export type ScrollToFieldOptions = ScrollIntoViewOptions;
|
|
35
|
+
/** 校验失败时抛出的错误,携带 values 和 errorFields,便于 catch 后使用 */
|
|
36
|
+
export declare class FormValidationError extends Error {
|
|
37
|
+
/** 当前表单值 */
|
|
38
|
+
values: Record<string, any>;
|
|
39
|
+
/** 校验失败的字段列表 */
|
|
40
|
+
errorFields: Array<{
|
|
41
|
+
name: string;
|
|
42
|
+
errors: string[];
|
|
43
|
+
}>;
|
|
44
|
+
constructor(message: string, values: Record<string, any>, errorFields: Array<{
|
|
45
|
+
name: string;
|
|
46
|
+
errors: string[];
|
|
47
|
+
}>);
|
|
48
|
+
}
|
|
33
49
|
export interface FormInstance {
|
|
34
50
|
/** 获取字段值 */
|
|
35
51
|
getFieldValue: (name: string) => any;
|
|
@@ -39,6 +55,12 @@ export interface FormInstance {
|
|
|
39
55
|
setFieldValue: (name: string, value: any) => void;
|
|
40
56
|
/** 设置所有字段值 */
|
|
41
57
|
setFieldsValue: (values: Record<string, any>) => void;
|
|
58
|
+
/** 批量设置字段(值 + 错误),类似 antd 的 setFields */
|
|
59
|
+
setFields: (fields: Array<{
|
|
60
|
+
name: string;
|
|
61
|
+
value?: any;
|
|
62
|
+
errors?: string[];
|
|
63
|
+
}>) => void;
|
|
42
64
|
/** 获取字段错误 */
|
|
43
65
|
getFieldError: (name: string) => string | undefined;
|
|
44
66
|
/** 校验字段 */
|
|
@@ -47,11 +69,17 @@ export interface FormInstance {
|
|
|
47
69
|
validateFields: (nameList?: string[]) => Promise<any>;
|
|
48
70
|
/** 重置字段 */
|
|
49
71
|
resetFields: (nameList?: string[]) => void;
|
|
50
|
-
/**
|
|
72
|
+
/** 提交表单:校验通过时 resolve 表单值,校验失败时 reject 为 FormValidationError(需 await 或 .catch() 才能捕获) */
|
|
51
73
|
submit: () => Promise<any>;
|
|
74
|
+
/** 滚动到指定字段(如第一个报错项) */
|
|
75
|
+
scrollToField: (name: string, options?: ScrollToFieldOptions) => void;
|
|
52
76
|
}
|
|
53
77
|
declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<FormInstance>>;
|
|
78
|
+
/** 获取表单实例的 hook,用法与 antd Form.useForm() 一致,返回的 ref 传给 <Form ref={formRef} /> 后即可使用 formRef.current?.setFieldValue 等方法 */
|
|
79
|
+
declare function useForm(): [React.RefObject<FormInstance | null>];
|
|
54
80
|
declare const FormWithItem: typeof Form & {
|
|
55
81
|
Item: typeof FormItem;
|
|
82
|
+
useForm: typeof useForm;
|
|
56
83
|
};
|
|
57
84
|
export default FormWithItem;
|
|
85
|
+
export { useForm };
|
package/dist/index.d.ts
CHANGED
|
@@ -725,6 +725,8 @@ interface FormProps {
|
|
|
725
725
|
/** 子元素 */
|
|
726
726
|
children?: React.ReactNode;
|
|
727
727
|
}
|
|
728
|
+
/** scrollToField 的选项,与 Element.scrollIntoView 一致 */
|
|
729
|
+
type ScrollToFieldOptions = ScrollIntoViewOptions;
|
|
728
730
|
interface FormInstance {
|
|
729
731
|
/** 获取字段值 */
|
|
730
732
|
getFieldValue: (name: string) => any;
|
|
@@ -734,6 +736,12 @@ interface FormInstance {
|
|
|
734
736
|
setFieldValue: (name: string, value: any) => void;
|
|
735
737
|
/** 设置所有字段值 */
|
|
736
738
|
setFieldsValue: (values: Record<string, any>) => void;
|
|
739
|
+
/** 批量设置字段(值 + 错误),类似 antd 的 setFields */
|
|
740
|
+
setFields: (fields: Array<{
|
|
741
|
+
name: string;
|
|
742
|
+
value?: any;
|
|
743
|
+
errors?: string[];
|
|
744
|
+
}>) => void;
|
|
737
745
|
/** 获取字段错误 */
|
|
738
746
|
getFieldError: (name: string) => string | undefined;
|
|
739
747
|
/** 校验字段 */
|
|
@@ -742,12 +750,17 @@ interface FormInstance {
|
|
|
742
750
|
validateFields: (nameList?: string[]) => Promise<any>;
|
|
743
751
|
/** 重置字段 */
|
|
744
752
|
resetFields: (nameList?: string[]) => void;
|
|
745
|
-
/**
|
|
753
|
+
/** 提交表单:校验通过时 resolve 表单值,校验失败时 reject 为 FormValidationError(需 await 或 .catch() 才能捕获) */
|
|
746
754
|
submit: () => Promise<any>;
|
|
755
|
+
/** 滚动到指定字段(如第一个报错项) */
|
|
756
|
+
scrollToField: (name: string, options?: ScrollToFieldOptions) => void;
|
|
747
757
|
}
|
|
748
758
|
declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<FormInstance>>;
|
|
759
|
+
/** 获取表单实例的 hook,用法与 antd Form.useForm() 一致,返回的 ref 传给 <Form ref={formRef} /> 后即可使用 formRef.current?.setFieldValue 等方法 */
|
|
760
|
+
declare function useForm(): [React.RefObject<FormInstance | null>];
|
|
749
761
|
declare const FormWithItem: typeof Form & {
|
|
750
762
|
Item: typeof FormItem;
|
|
763
|
+
useForm: typeof useForm;
|
|
751
764
|
};
|
|
752
765
|
|
|
753
766
|
interface MenuItemType {
|