musae 1.3.1-beta.19 → 1.3.1-beta.20

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.
@@ -14,7 +14,7 @@ var className = require('@aiszlab/relax/class-name');
14
14
  var context = require('../context.cjs');
15
15
  var index = require('../hooks/index.cjs');
16
16
 
17
- var _excluded = ["required", "children", "className", "style", "supporting", "error", "name", "rules"];
17
+ var _excluded = ["required", "children", "className", "style", "supporting", "name", "rules"];
18
18
  /**
19
19
  * @description
20
20
  * form item may not has name prop
@@ -26,7 +26,6 @@ var Field = function Field(_ref) {
26
26
  className$1 = _ref.className,
27
27
  style = _ref.style,
28
28
  supporting$1 = _ref.supporting,
29
- renderError = _ref.error,
30
29
  name = _ref.name,
31
30
  rules = _ref.rules,
32
31
  props = _objectWithoutProperties(_ref, _excluded);
@@ -57,13 +56,14 @@ var Field = function Field(_ref) {
57
56
  })), true];
58
57
  }, [[], false]).at(0);
59
58
  }, [_children, name, value, isInvalid, change]);
59
+ var isSupportingHidden = supporting$1 === false || supporting$1 === null;
60
60
  return /*#__PURE__*/React.createElement(layout.default, {
61
61
  label: props.label,
62
62
  required: required,
63
63
  className: classNames.item,
64
- supporting: /*#__PURE__*/React.createElement(React.Fragment, null, !!supporting$1 && /*#__PURE__*/React.createElement(supporting.default, null, supporting$1), /*#__PURE__*/React.createElement(react.AnimatePresence, {
64
+ supporting: !isSupportingHidden && (/*#__PURE__*/React.createElement(React.Fragment, null, !!supporting$1 && /*#__PURE__*/React.createElement(supporting.default, null, supporting$1), /*#__PURE__*/React.createElement(react.AnimatePresence, {
65
65
  mode: "wait"
66
- }, isInvalid && (renderError === false ? null : relax.isFunction(renderError) ? renderError(error$1) : (/*#__PURE__*/React.createElement(error.default, null, error$1)))))
66
+ }, isInvalid && /*#__PURE__*/React.createElement(error.default, null, error$1))))
67
67
  }, /*#__PURE__*/React.createElement("div", {
68
68
  className: className.stringify(classNames.field, className$1),
69
69
  style: style
@@ -6,5 +6,5 @@ import type { RequiredIn } from "@aiszlab/relax/types";
6
6
  * form item may not has name prop
7
7
  * if there is name prop, it will render
8
8
  */
9
- declare const Field: <T extends FieldsValue, FieldKey extends keyof T>({ required, children: _children, className, style, supporting, error: renderError, name, rules, ...props }: RequiredIn<FormItemProps<T, FieldKey>, "name" | "required">) => React.JSX.Element;
9
+ declare const Field: <T extends FieldsValue, FieldKey extends keyof T>({ required, children: _children, className, style, supporting, name, rules, ...props }: RequiredIn<FormItemProps<T, FieldKey>, "name" | "required">) => React.JSX.Element;
10
10
  export default Field;
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
2
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
3
3
  import React, { useContext, useMemo, Children, isValidElement, cloneElement } from 'react';
4
- import { chain, isFunction } from '@aiszlab/relax';
4
+ import { chain } from '@aiszlab/relax';
5
5
  import Layout from './layout.mjs';
6
6
  import Error from './error.mjs';
7
7
  import { AnimatePresence } from 'motion/react';
@@ -10,7 +10,7 @@ import { stringify } from '@aiszlab/relax/class-name';
10
10
  import Context from '../context.mjs';
11
11
  import { useFormItem } from '../hooks/index.mjs';
12
12
 
13
- var _excluded = ["required", "children", "className", "style", "supporting", "error", "name", "rules"];
13
+ var _excluded = ["required", "children", "className", "style", "supporting", "name", "rules"];
14
14
  /**
15
15
  * @description
16
16
  * form item may not has name prop
@@ -22,7 +22,6 @@ var Field = function Field(_ref) {
22
22
  className = _ref.className,
23
23
  style = _ref.style,
24
24
  supporting = _ref.supporting,
25
- renderError = _ref.error,
26
25
  name = _ref.name,
27
26
  rules = _ref.rules,
28
27
  props = _objectWithoutProperties(_ref, _excluded);
@@ -53,13 +52,14 @@ var Field = function Field(_ref) {
53
52
  })), true];
54
53
  }, [[], false]).at(0);
55
54
  }, [_children, name, value, isInvalid, change]);
55
+ var isSupportingHidden = supporting === false || supporting === null;
56
56
  return /*#__PURE__*/React.createElement(Layout, {
57
57
  label: props.label,
58
58
  required: required,
59
59
  className: classNames.item,
60
- supporting: /*#__PURE__*/React.createElement(React.Fragment, null, !!supporting && /*#__PURE__*/React.createElement(Supporting, null, supporting), /*#__PURE__*/React.createElement(AnimatePresence, {
60
+ supporting: !isSupportingHidden && (/*#__PURE__*/React.createElement(React.Fragment, null, !!supporting && /*#__PURE__*/React.createElement(Supporting, null, supporting), /*#__PURE__*/React.createElement(AnimatePresence, {
61
61
  mode: "wait"
62
- }, isInvalid && (renderError === false ? null : isFunction(renderError) ? renderError(error) : (/*#__PURE__*/React.createElement(Error, null, error)))))
62
+ }, isInvalid && /*#__PURE__*/React.createElement(Error, null, error))))
63
63
  }, /*#__PURE__*/React.createElement("div", {
64
64
  className: stringify(classNames.field, className),
65
65
  style: style
@@ -3,66 +3,80 @@ import type { FieldsValue, Form, Rule, FORM_TOKEN, ChangeHandler } from "../util
3
3
  import type { Nullable, Partialable } from "@aiszlab/relax/types";
4
4
  import type { ComponentProps } from "./element";
5
5
  /**
6
- * form hook return
6
+ * @zh 表单实例 hook 的返回值。
7
+ * @en Return value of the form instance hook.
7
8
  */
8
9
  interface UsedForm<T extends FieldsValue> {
9
10
  /**
10
- * set field value
11
+ * @zh 设置指定字段的值,并清除该字段的校验错误。
12
+ * @en Set a field value and clear that field's validation error.
11
13
  */
12
14
  setFieldValue(name: keyof T, value: T[keyof T]): void;
13
15
  /**
14
- * set fields value
15
- * @description set multiple fields value
16
+ * @zh 批量设置字段值,并清除这些字段的校验错误。
17
+ * @en Set multiple field values and clear their validation errors.
16
18
  */
17
19
  setFieldsValue(value: Partial<T>): void;
18
20
  /**
19
- * reset fields value and clear errors
21
+ * @zh 将字段值重置为 `defaultValue`,并清除所有校验错误。
22
+ * @en Reset field values to `defaultValue` and clear all validation errors.
20
23
  */
21
24
  reset(): void;
22
25
  /**
23
- * clear fields value and clear errors
26
+ * @zh 清空字段值并清除所有校验错误。
27
+ * @en Clear field values and all validation errors.
24
28
  */
25
29
  clear(): void;
26
30
  /**
27
- * validate
31
+ * @zh 校验所有已注册字段;全部通过时返回 `true`。
32
+ * @en Validate all registered fields; resolve to `true` when all pass.
28
33
  */
29
34
  validate: () => Promise<boolean>;
30
35
  /**
31
- * get field value
36
+ * @zh 获取指定字段当前值。
37
+ * @en Get the current value of a field.
32
38
  */
33
39
  getFieldValue: <FieldValue = T[keyof T]>(name: keyof T) => Partialable<FieldValue>;
34
40
  /**
35
- * get fields value
41
+ * @zh 获取已注册字段的当前值。
42
+ * @en Get the current values of registered fields.
36
43
  */
37
44
  getFieldsValue: () => Partial<T>;
38
45
  /**
39
- * form instance
46
+ * @zh 底层表单实例,供组件内部共享使用。
47
+ * @en Underlying form instance shared by the form components.
40
48
  */
41
49
  [FORM_TOKEN]: Form<T>;
42
50
  }
43
51
  /**
44
- * form hook props
52
+ * @zh 表单实例 hook 的配置参数。
53
+ * @en Configuration options for the form instance hook.
45
54
  */
46
55
  interface UsingForm<T extends FieldsValue> {
47
56
  /**
48
- * form default value
57
+ * @zh 非受控表单的初始值,也作为调用 `reset()` 时恢复的值。
58
+ * @en Initial value for an uncontrolled form and the value restored by `reset()`.
49
59
  */
50
60
  defaultValue?: Partial<T>;
51
61
  /**
52
- * registered form
62
+ * @zh 复用已有的表单实例;不传时会创建新实例。
63
+ * @en Reuse an existing form instance; a new instance is created when omitted.
53
64
  */
54
65
  form?: UsedForm<T>;
55
66
  /**
56
- * change handler
67
+ * @zh 字段通过表单交互发生变化时调用,参数依次为已登记字段值和本次变更的字段名。
68
+ * @en Called when a field changes through form interaction, with registered field values and the names changed.
57
69
  */
58
70
  onChange?: ChangeHandler<T>;
59
71
  /**
60
- * controlled form value
72
+ * @zh 受控表单的当前值;传入后由调用方负责更新该值。
73
+ * @en Current value of a controlled form; the caller is responsible for updating it.
61
74
  */
62
75
  value?: Partial<T>;
63
76
  }
64
77
  /**
65
- * form props
78
+ * @zh Form 组件的参数。
79
+ * @en Props for the Form component.
66
80
  */
67
81
  interface FormProps<T extends FieldsValue> extends ComponentProps {
68
82
  /**
@@ -72,26 +86,28 @@ interface FormProps<T extends FieldsValue> extends ComponentProps {
72
86
  */
73
87
  layout?: FormLayout;
74
88
  /**
75
- * used form instance
76
- * use `form` can control `Form` value
89
+ * @zh 传入 `Form.useForm()` 创建的实例以复用或外部操作表单。
90
+ * @en Pass an instance from `Form.useForm()` to reuse or control the form externally.
77
91
  */
78
92
  form?: UsedForm<T>;
79
93
  /**
80
- * children components
94
+ * @zh 表单内容,通常包含 `Form.Item` 等表单项。
95
+ * @en Form contents, usually including fields such as `Form.Item`.
81
96
  */
82
97
  children: ReactNode;
83
98
  /**
84
- * form value change handler
99
+ * @zh 字段通过表单交互发生变化时调用,参数依次为已登记字段值和本次变更的字段名。
100
+ * @en Called when a field changes through form interaction, with registered field values and the names changed.
85
101
  */
86
102
  onChange?: ChangeHandler<T>;
87
103
  /**
88
- * default value
104
+ * @zh 非受控表单的初始值,也作为调用 `form.reset()` 时恢复的值。
105
+ * @en Initial value for an uncontrolled form and the value restored by `form.reset()`.
89
106
  */
90
107
  defaultValue?: Partial<T>;
91
108
  /**
92
- * controlled value
93
- * @description
94
- * if `value` is provided, `Form` will be controlled
109
+ * @zh 受控表单的当前值;传入后由调用方负责更新该值。
110
+ * @en Current value of a controlled form; the caller is responsible for updating it.
95
111
  */
96
112
  value?: Partial<T>;
97
113
  }
@@ -141,52 +157,58 @@ interface TypedForm {
141
157
  useFormContext: UseFormContext;
142
158
  }
143
159
  /**
144
- * form item props
160
+ * @zh Form.Item 组件的参数。
161
+ * @en Props for the Form.Item component.
145
162
  */
146
163
  interface FormItemProps<T extends FieldsValue, FieldKey extends keyof T> {
147
164
  /**
148
- * name
165
+ * @zh 对应表单数据中的字段名;省略时该项不与表单值绑定。
166
+ * @en Field name in the form data; when omitted, this item is not bound to a form value.
149
167
  */
150
168
  name?: FieldKey;
151
169
  /**
152
- * required field
170
+ * @zh 标记该字段为必填,并用于显示必填状态。
171
+ * @en Mark the field as required and display its required state.
153
172
  */
154
173
  required?: boolean;
155
174
  /**
156
- * class name
175
+ * @zh 应用于表单项根元素的额外类名。
176
+ * @en Additional class name applied to the form item root.
157
177
  */
158
178
  className?: string;
159
179
  /**
160
- * style
180
+ * @zh 应用于表单项根元素的内联样式。
181
+ * @en Inline styles applied to the form item root.
161
182
  */
162
183
  style?: CSSProperties;
163
184
  /**
164
- * supporting
185
+ * @zh 显示在字段下方的补充说明。
186
+ * @en Supporting text displayed below the field.
165
187
  */
166
188
  supporting?: ReactNode;
167
189
  /**
168
- * @zh 自定义错误消息的渲染方式
169
- * @en Customize how the error message is rendered
170
- */
171
- error?: false | ((error: ReactNode) => ReactNode);
172
- /**
173
- * label
190
+ * @zh 字段标签内容。
191
+ * @en Field label content.
174
192
  */
175
193
  label?: ReactNode;
176
194
  /**
177
- * labelCol
195
+ * @zh 标签区域占用的栅格列数。
196
+ * @en Number of grid columns occupied by the label.
178
197
  */
179
198
  labelCol?: number;
180
199
  /**
181
- * wrapperCol
200
+ * @zh 字段控件区域占用的栅格列数。
201
+ * @en Number of grid columns occupied by the field control.
182
202
  */
183
203
  wrapperCol?: number;
184
204
  /**
185
- * children
205
+ * @zh 字段控件或其他表单项内容。
206
+ * @en Field control or other form item content.
186
207
  */
187
208
  children?: ReactNode;
188
209
  /**
189
- * rules
210
+ * @zh 按顺序执行的字段校验规则。
211
+ * @en Validation rules run for this field.
190
212
  */
191
213
  rules?: Rule<T, FieldKey>[];
192
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musae",
3
- "version": "1.3.1-beta.19",
3
+ "version": "1.3.1-beta.20",
4
4
  "description": "musae-ui",
5
5
  "author": "tutu@fantufantu.com",
6
6
  "license": "MIT",