@hi-ui/form 4.0.0-alpha.9 → 4.0.0-beta.10

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 (47) hide show
  1. package/README.md +23 -24
  2. package/lib/cjs/Form.js +8 -4
  3. package/lib/cjs/Form.js.map +1 -1
  4. package/lib/cjs/FormField.js +6 -0
  5. package/lib/cjs/FormField.js.map +1 -1
  6. package/lib/cjs/FormItem.js +10 -8
  7. package/lib/cjs/FormItem.js.map +1 -1
  8. package/lib/cjs/FormLabel.js +10 -8
  9. package/lib/cjs/FormLabel.js.map +1 -1
  10. package/lib/cjs/FormList.js +7 -7
  11. package/lib/cjs/FormList.js.map +1 -1
  12. package/lib/cjs/context.js.map +1 -1
  13. package/lib/cjs/index.js +10 -4
  14. package/lib/cjs/index.js.map +1 -1
  15. package/lib/cjs/styles/index.scss.js +1 -1
  16. package/lib/cjs/use-form-field.js +4 -3
  17. package/lib/cjs/use-form-field.js.map +1 -1
  18. package/lib/cjs/use-form.js +28 -30
  19. package/lib/cjs/use-form.js.map +1 -1
  20. package/lib/esm/Form.js +8 -4
  21. package/lib/esm/Form.js.map +1 -1
  22. package/lib/esm/FormField.js +5 -0
  23. package/lib/esm/FormField.js.map +1 -1
  24. package/lib/esm/FormItem.js +10 -8
  25. package/lib/esm/FormItem.js.map +1 -1
  26. package/lib/esm/FormLabel.js +9 -8
  27. package/lib/esm/FormLabel.js.map +1 -1
  28. package/lib/esm/FormList.js +1 -1
  29. package/lib/esm/context.js.map +1 -1
  30. package/lib/esm/index.js +13 -1
  31. package/lib/esm/index.js.map +1 -1
  32. package/lib/esm/styles/index.scss.js +1 -1
  33. package/lib/esm/use-form-field.js +4 -3
  34. package/lib/esm/use-form-field.js.map +1 -1
  35. package/lib/esm/use-form.js +17 -20
  36. package/lib/esm/use-form.js.map +1 -1
  37. package/lib/types/Form.d.ts +3 -3
  38. package/lib/types/FormField.d.ts +4 -0
  39. package/lib/types/FormItem.d.ts +4 -0
  40. package/lib/types/FormLabel.d.ts +5 -1
  41. package/lib/types/FormSubmit.d.ts +2 -2
  42. package/lib/types/context.d.ts +10 -69
  43. package/lib/types/index.d.ts +8 -1
  44. package/lib/types/types.d.ts +7 -7
  45. package/lib/types/use-form-field.d.ts +8 -13
  46. package/lib/types/use-form.d.ts +5 -14
  47. package/package.json +15 -14
@@ -16,7 +16,7 @@ export interface FormLabelProps extends HiBaseHTMLProps<'div'> {
16
16
  /**
17
17
  * 是否显示冒号
18
18
  */
19
- colon?: boolean;
19
+ showColon?: boolean;
20
20
  /**
21
21
  * label 宽度,可使用任意 CSS 长度单位。优先级高于 Form 设置的 labelWidth
22
22
  */
@@ -25,4 +25,8 @@ export interface FormLabelProps extends HiBaseHTMLProps<'div'> {
25
25
  * label 文案
26
26
  */
27
27
  label?: React.ReactNode;
28
+ /**
29
+ * 在 vertical 放置时,label 相对表单控件垂直对齐的方式,优先级低于 Form
30
+ */
31
+ contentPosition?: 'top' | 'center' | 'bottom';
28
32
  }
@@ -3,7 +3,7 @@ import { ButtonProps } from '@hi-ui/button';
3
3
  /**
4
4
  * TODO: What is FormSubmit
5
5
  */
6
- export declare const FormSubmit: React.ForwardRefExoticComponent<FormLabelProps & React.RefAttributes<HTMLAnchorElement | HTMLButtonElement | null>>;
7
- export interface FormLabelProps extends Omit<ButtonProps, 'onClick'> {
6
+ export declare const FormSubmit: React.ForwardRefExoticComponent<FormSubmitProps & React.RefAttributes<HTMLAnchorElement | HTMLButtonElement | null>>;
7
+ export interface FormSubmitProps extends Omit<ButtonProps, 'onClick'> {
8
8
  onClick?: (value: any, error: any) => void;
9
9
  }
@@ -1,69 +1,10 @@
1
- /// <reference types="react" />
2
- export declare const FormProvider: import("react").Provider<Omit<{
3
- setFormState: (stateOrFunc: import("./types").FormSetState<unknown>) => void;
4
- setFieldValue: (field: import("./types").FormFieldPath, value: unknown, shouldValidate?: boolean | undefined) => void;
5
- setFieldError: (field: import("./types").FormFieldPath, errorMessage: string | undefined) => void;
6
- setFieldTouched: (field: import("./types").FormFieldPath, touched?: any) => void;
7
- getFieldValue: (fieldName: import("./types").FormFieldPath) => any;
8
- getFieldError: (fieldName: import("./types").FormFieldPath) => any;
9
- getFieldRules: (fieldName: import("./types").FormFieldPath) => any;
10
- getRootProps: () => {
11
- onSubmit: (evt?: import("react").FormEvent<HTMLFormElement> | undefined) => Promise<unknown>;
12
- onReset: (evt?: import("react").FormEvent<HTMLFormElement> | undefined) => void;
13
- };
14
- getFieldProps: (props?: any, ref?: any) => {
15
- [x: number]: any;
16
- ref: any;
17
- onBlur: (...args: any) => void;
18
- invalid: any;
19
- };
20
- registerField: (keyOrKeys: import("./types").FormFieldPath, value: import("./types").FormFieldCollection<unknown>) => void;
21
- unregisterField: (keyOrKeys: import("./types").FormFieldPath) => void;
22
- submitForm: () => Promise<unknown>;
23
- resetForm: (nextState?: Partial<import("./types").FormState<any>> | undefined) => Promise<void>;
24
- resetErrors: () => void;
25
- validateFieldState: (field: import("./types").FormFieldPath) => Promise<{} | undefined>;
26
- validateValue: (field: import("./types").FormFieldPath, value: unknown) => Promise<{} | undefined>;
27
- getFieldsValue: () => any;
28
- setFieldsValue: (fields: Record<string, any>, shouldValidate?: boolean | undefined) => void;
29
- getFieldsError: () => any;
30
- values: unknown;
31
- errors: import("./types").FormErrors<unknown>;
32
- touched: import("./types").FormTouched<unknown>;
33
- validating: boolean;
34
- submitting?: boolean | undefined;
35
- }, "rootProps"> | null>;
36
- export declare const useFormContext: () => Omit<{
37
- setFormState: (stateOrFunc: import("./types").FormSetState<unknown>) => void;
38
- setFieldValue: (field: import("./types").FormFieldPath, value: unknown, shouldValidate?: boolean | undefined) => void;
39
- setFieldError: (field: import("./types").FormFieldPath, errorMessage: string | undefined) => void;
40
- setFieldTouched: (field: import("./types").FormFieldPath, touched?: any) => void;
41
- getFieldValue: (fieldName: import("./types").FormFieldPath) => any;
42
- getFieldError: (fieldName: import("./types").FormFieldPath) => any;
43
- getFieldRules: (fieldName: import("./types").FormFieldPath) => any;
44
- getRootProps: () => {
45
- onSubmit: (evt?: import("react").FormEvent<HTMLFormElement> | undefined) => Promise<unknown>;
46
- onReset: (evt?: import("react").FormEvent<HTMLFormElement> | undefined) => void;
47
- };
48
- getFieldProps: (props?: any, ref?: any) => {
49
- [x: number]: any;
50
- ref: any;
51
- onBlur: (...args: any) => void;
52
- invalid: any;
53
- };
54
- registerField: (keyOrKeys: import("./types").FormFieldPath, value: import("./types").FormFieldCollection<unknown>) => void;
55
- unregisterField: (keyOrKeys: import("./types").FormFieldPath) => void;
56
- submitForm: () => Promise<unknown>;
57
- resetForm: (nextState?: Partial<import("./types").FormState<any>> | undefined) => Promise<void>;
58
- resetErrors: () => void;
59
- validateFieldState: (field: import("./types").FormFieldPath) => Promise<{} | undefined>;
60
- validateValue: (field: import("./types").FormFieldPath, value: unknown) => Promise<{} | undefined>;
61
- getFieldsValue: () => any;
62
- setFieldsValue: (fields: Record<string, any>, shouldValidate?: boolean | undefined) => void;
63
- getFieldsError: () => any;
64
- values: unknown;
65
- errors: import("./types").FormErrors<unknown>;
66
- touched: import("./types").FormTouched<unknown>;
67
- validating: boolean;
68
- submitting?: boolean | undefined;
69
- }, "rootProps">;
1
+ import React from 'react';
2
+ import { UseFormReturn } from './use-form';
3
+ export interface FormContextProps extends UseFormReturn {
4
+ labelWidth: React.ReactText;
5
+ labelPlacement: 'left' | 'right' | 'top';
6
+ contentPosition: 'top' | 'center' | 'bottom';
7
+ showColon: boolean;
8
+ }
9
+ export declare const FormProvider: React.Provider<Omit<FormContextProps, "rootProps"> | null>;
10
+ export declare const useFormContext: () => Omit<FormContextProps, "rootProps">;
@@ -1,6 +1,13 @@
1
+ /// <reference types="react" />
1
2
  import './styles/index.scss';
3
+ declare const Form: import("react").ForwardRefExoticComponent<import("./Form").FormProps<Record<string, any>> & import("react").RefAttributes<HTMLFormElement | null>> & {
4
+ Item: import("react").FC<import("./FormItem").FormItemProps>;
5
+ List: import("react").FC<import("./FormList").FormListProps>;
6
+ Submit: import("react").ForwardRefExoticComponent<import("./FormSubmit").FormSubmitProps & import("react").RefAttributes<HTMLAnchorElement | HTMLButtonElement | null>>;
7
+ Reset: import("react").ForwardRefExoticComponent<import("./FormReset").FormResetProps & import("react").RefAttributes<HTMLButtonElement | null>>;
8
+ };
9
+ export default Form;
2
10
  export * from './Form';
3
- export { Form as default } from './Form';
4
11
  export * from './FormItem';
5
12
  export * from './FormList';
6
13
  export * from './FormSubmit';
@@ -88,19 +88,19 @@ export interface FormHelpers<T = any> {
88
88
  /**
89
89
  * 重置整个表单的验证,对应 Form.Reset中的 API
90
90
  */
91
- reset: (fields?: [], toDefault?: boolean) => Promise<T>;
91
+ reset: (fields?: FormFieldPath, toDefault?: boolean) => Promise<T>;
92
92
  /**
93
93
  * 对指定表单字段进行校验
94
94
  */
95
- validateField: (fields?: string[] | string) => Promise<T>;
95
+ validateField: (fields?: FormFieldPath) => Promise<T>;
96
96
  /**
97
97
  * 对指定表单字段进行校验
98
98
  */
99
- validateFields: (fields?: string[] | string) => Promise<T>;
99
+ validateFields: (fields?: FormFieldPath) => Promise<T>;
100
100
  /**
101
101
  * 设置表单的值,在异步获取的数据回显的时候,使用该方法
102
102
  */
103
- setFieldValue: (field: string, value: any) => void;
103
+ setFieldValue: (field: FormFieldPath, value: any) => void;
104
104
  /**
105
105
  * 设置多个表单的值,在异步获取的数据回显的时候,使用该方法
106
106
  */
@@ -108,7 +108,7 @@ export interface FormHelpers<T = any> {
108
108
  /**
109
109
  * 获取一个字段名对应的 Values 返回为数组形式, 不传入 fields;默认返回全部信息, 不会触发表单校验
110
110
  */
111
- getFieldValue: (field: string) => any;
111
+ getFieldValue: (field: FormFieldPath) => any;
112
112
  /**
113
113
  * 获取所有字段名对应的 Values 返回为数组形式, 不传入 fields;默认返回全部信息, 不会触发表单校验
114
114
  */
@@ -116,7 +116,7 @@ export interface FormHelpers<T = any> {
116
116
  /**
117
117
  * 获取一组字段名对应的错误信息,返回为数组形式, 不传入 fields;默认返回全部信息
118
118
  */
119
- getFieldError: (field: string) => any;
119
+ getFieldError: (field: FormFieldPath) => any;
120
120
  /**
121
121
  * 获取所有字段名对应的错误信息,返回为数组形式, 不传入 fields;默认返回全部信息
122
122
  */
@@ -128,7 +128,7 @@ export interface FormHelpers<T = any> {
128
128
  /**
129
129
  * 移除表单项的校验结果,传入待移除的表单项的 field 属性组成的数组
130
130
  */
131
- clearFieldsValidates: (fields: string[]) => void;
131
+ clearFieldsValidates: (fields: FormFieldPath) => void;
132
132
  }
133
133
  export declare type FormFieldPath = (string | number)[] | string | number;
134
134
  export declare type FormErrorMessage = string;
@@ -1,19 +1,14 @@
1
- import { FormFieldPath, FormRuleModel } from './types';
2
- export declare const useFormField: <Values = any>(props: UseFormFieldProps<Values>) => {
3
- [x: number]: any;
4
- ref: any;
5
- onBlur: (...args: any) => void;
6
- invalid: any;
7
- };
1
+ import { FormFieldPath, FormRuleModel, FormRuleType } from './types';
2
+ export declare const useFormField: <Values = any>(props: UseFormFieldProps<Values>) => any;
8
3
  export interface UseFormFieldProps<T = Record<string, any>> {
9
4
  /**
10
5
  * 字段名,支持数组
11
6
  */
12
- field: FormFieldPath | null;
7
+ field?: FormFieldPath;
13
8
  /**
14
9
  * 指定控件值数据结构类型
15
10
  */
16
- valueType: 'string' | 'boolean' | 'number' | 'array' | 'object' | 'date' | null;
11
+ valueType?: FormRuleType;
17
12
  /**
18
13
  * 设置字段的验证规则,会覆盖 Form 设置的 rules
19
14
  */
@@ -25,17 +20,17 @@ export interface UseFormFieldProps<T = Record<string, any>> {
25
20
  /**
26
21
  * form 从控件个体采集数据的转换器,最终会把返回值转发给 Form
27
22
  */
28
- valueCollectPipe?: (value: any) => T;
23
+ valueDispatchTransform?: (...args: any[]) => T;
29
24
  /**
30
25
  * 控件个体接收 form 下发数据的转换器,最终会把返回值转发给 FormField
31
26
  */
32
- valueSyncPipe?: (value: any) => T;
27
+ valueConnectTransform?: (value: any) => T;
33
28
  /**
34
29
  * 自定义设置 Form 从表单控件采集数据回调的属性
35
30
  */
36
- valueCollectPropName?: string;
31
+ valueChangeFuncPropName?: string;
37
32
  /**
38
- * 设置触发该字段校验的时机,会覆盖 Form 设置的 validateTrigger
33
+ * 设置触发该字段校验的时机(值必须是回调函数),会覆盖 Form 设置的 validateTrigger
39
34
  */
40
35
  validateTrigger?: string | string[];
41
36
  }
@@ -12,12 +12,7 @@ export declare const useForm: <Values = Record<string, any>>({ initialValues, in
12
12
  onSubmit: (evt?: React.FormEvent<HTMLFormElement> | undefined) => Promise<unknown>;
13
13
  onReset: (evt?: React.FormEvent<HTMLFormElement> | undefined) => void;
14
14
  };
15
- getFieldProps: (props?: any, ref?: any) => {
16
- [x: number]: any;
17
- ref: any;
18
- onBlur: (...args: any) => void;
19
- invalid: any;
20
- };
15
+ getFieldProps: (props?: any) => any;
21
16
  registerField: (keyOrKeys: FormFieldPath, value: FormFieldCollection<Values>) => void;
22
17
  unregisterField: (keyOrKeys: FormFieldPath) => void;
23
18
  submitForm: () => Promise<unknown>;
@@ -44,25 +39,21 @@ export interface UseFormProps<T = Record<string, any>> {
44
39
  */
45
40
  initialErrors?: Record<keyof T, string>;
46
41
  /**
47
- * 初始化是否已被触碰
42
+ * 初始化是否已被触碰。暂不对外暴露
43
+ * @private
48
44
  */
49
45
  initialTouched?: Record<string, boolean>;
50
46
  /**
51
47
  * 校验规则,设置字段的校验逻辑
52
48
  */
53
49
  rules?: Record<string, FormRuleModel[]>;
54
- /**
55
- * 开启在 onBlur 时触发校验
56
- */
57
- /**
58
- * 开启在 onChange 时触发校验
59
- */
60
50
  /**
61
51
  * 设置统一的表单校验时机
62
52
  */
63
53
  validateTrigger?: string | string[];
64
54
  /**
65
- * 在触摸控件之后才开启校验
55
+ * 在触摸控件之后才开启校验。暂不对外暴露
56
+ * @private
66
57
  */
67
58
  validateAfterTouched?: boolean;
68
59
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/form",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.10",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HIUI <mi-hiui@xiaomi.com>",
@@ -43,26 +43,27 @@
43
43
  "url": "https://github.com/XiaoMi/hiui/issues"
44
44
  },
45
45
  "dependencies": {
46
- "@flcwly/validater": "^0.1.4",
47
- "@hi-ui/button": "^4.0.0-alpha.21",
48
- "@hi-ui/classname": "^4.0.0-alpha.3",
49
- "@hi-ui/core-css": "^4.0.0-alpha.13",
50
- "@hi-ui/dom-utils": "^4.0.0-alpha.7",
51
- "@hi-ui/env": "^4.0.0-alpha.5",
52
- "@hi-ui/func-utils": "^4.0.0-alpha.5",
53
- "@hi-ui/type-assertion": "^4.0.0-alpha.13",
54
- "@hi-ui/use-latest": "^4.0.0-alpha.5",
55
- "async-validator": "^4.0.7",
56
- "yup": "^0.32.11"
46
+ "@hi-ui/array-utils": "^4.0.0-beta.4",
47
+ "@hi-ui/button": "^4.0.0-beta.5",
48
+ "@hi-ui/classname": "^4.0.0-beta.0",
49
+ "@hi-ui/core-css": "^4.0.0-beta.3",
50
+ "@hi-ui/dom-utils": "^4.0.0-beta.1",
51
+ "@hi-ui/env": "^4.0.0-beta.0",
52
+ "@hi-ui/func-utils": "^4.0.0-beta.4",
53
+ "@hi-ui/locale-context": "^4.0.0-beta.7",
54
+ "@hi-ui/object-utils": "^4.0.0-beta.3",
55
+ "@hi-ui/type-assertion": "^4.0.0-beta.1",
56
+ "@hi-ui/use-latest": "^4.0.0-beta.1",
57
+ "async-validator": "^4.0.7"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "react": ">=16.8.6",
60
61
  "react-dom": ">=16.8.6"
61
62
  },
62
63
  "devDependencies": {
63
- "@hi-ui/hi-build": "^4.0.0-alpha.4",
64
+ "@hi-ui/hi-build": "^4.0.0-beta.1",
64
65
  "react": "^17.0.1",
65
66
  "react-dom": "^17.0.1"
66
67
  },
67
- "gitHead": "5a8f028a385e4a547748df37875653cfb416beb9"
68
+ "gitHead": "6b493b7d53d775bd0b94f45f208986774620af43"
68
69
  }