@rainbow-oh/yee-c 0.8.20 → 0.9.0

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.
@@ -98,7 +98,7 @@ var Field = (props) => {
98
98
  } = props;
99
99
  const {
100
100
  getCallbacks,
101
- getFieldValidate,
101
+ getFieldStatus,
102
102
  getFieldValue,
103
103
  getFieldsValue,
104
104
  setFieldsValue,
@@ -129,7 +129,7 @@ var Field = (props) => {
129
129
  const isRequired = () => {
130
130
  return Array.isArray(rules) && rules.find((rule) => rule.required) || required;
131
131
  };
132
- const validate = getFieldValidate == null ? void 0 : getFieldValidate(normalizedName);
132
+ const fieldStatus = getFieldStatus == null ? void 0 : getFieldStatus(normalizedName);
133
133
  const tooltipConfig = (0, import_react2.useMemo)(() => {
134
134
  if (tooltip === void 0 || tooltip === null || tooltip === false)
135
135
  return null;
@@ -183,7 +183,7 @@ var Field = (props) => {
183
183
  `${prefixCls}-item`,
184
184
  `${prefixCls}-item-${layout}`,
185
185
  {
186
- [`${prefixCls}-item-${validate == null ? void 0 : validate.status}`]: validate && validate.status
186
+ [`${prefixCls}-item-${fieldStatus == null ? void 0 : fieldStatus.status}`]: fieldStatus == null ? void 0 : fieldStatus.status
187
187
  },
188
188
  className
189
189
  ),
@@ -216,7 +216,7 @@ var Field = (props) => {
216
216
  getControlled(children)
217
217
  ) : /* @__PURE__ */ import_react2.default.createElement("span", null, children)
218
218
  )),
219
- /* @__PURE__ */ import_react2.default.createElement(import_react.AnimatePresence, null, validate && /* @__PURE__ */ import_react2.default.createElement(
219
+ /* @__PURE__ */ import_react2.default.createElement(import_react.AnimatePresence, null, (fieldStatus == null ? void 0 : fieldStatus.message) && /* @__PURE__ */ import_react2.default.createElement(
220
220
  import_react.motion.small,
221
221
  {
222
222
  initial: { opacity: 0, y: -10 },
@@ -224,10 +224,10 @@ var Field = (props) => {
224
224
  exit: { opacity: 0, y: -10 },
225
225
  transition: { duration: 0.16 },
226
226
  className: (0, import_clsx.default)(`${prefixCls}-item-additional`, {
227
- [`${prefixCls}-item-additional-${validate.status}`]: validate.status
227
+ [`${prefixCls}-item-additional-${fieldStatus.status}`]: fieldStatus.status
228
228
  })
229
229
  },
230
- validate.message
230
+ fieldStatus.message
231
231
  ))
232
232
  );
233
233
  };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const _default: () => React.JSX.Element;
3
+ export default _default;
@@ -0,0 +1,116 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/Form/demo/field-status.tsx
30
+ var field_status_exports = {};
31
+ __export(field_status_exports, {
32
+ default: () => field_status_default
33
+ });
34
+ module.exports = __toCommonJS(field_status_exports);
35
+ var import_yee_c = require("../..");
36
+ var import_react = __toESM(require("react"));
37
+ var field_status_default = () => {
38
+ const [form] = import_yee_c.Form.useForm();
39
+ const [currentStatus, setCurrentStatus] = (0, import_react.useState)(
40
+ null
41
+ );
42
+ const [submitResult, setSubmitResult] = (0, import_react.useState)("");
43
+ const applyStatus = (status) => {
44
+ form.setFieldStatus("username", status);
45
+ setCurrentStatus(form.getFieldStatus("username"));
46
+ setSubmitResult("");
47
+ };
48
+ return /* @__PURE__ */ import_react.default.createElement(
49
+ import_yee_c.Form,
50
+ {
51
+ form,
52
+ initialValues: { username: "demo-user" },
53
+ onFinish: () => setSubmitResult("Submit succeeded"),
54
+ onFinishFailed: () => setSubmitResult("Submit blocked by the blocking error")
55
+ },
56
+ /* @__PURE__ */ import_react.default.createElement(
57
+ import_yee_c.Form.Field,
58
+ {
59
+ name: "username",
60
+ label: "Username",
61
+ rules: [{ required: true, message: "Please input your username!" }]
62
+ },
63
+ /* @__PURE__ */ import_react.default.createElement(import_yee_c.Input, { placeholder: "Please input your username" })
64
+ ),
65
+ /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, { style: { marginTop: 28, flexWrap: "wrap" } }, /* @__PURE__ */ import_react.default.createElement(
66
+ import_yee_c.Button,
67
+ {
68
+ onClick: () => applyStatus({
69
+ status: "error",
70
+ message: "This username is unavailable"
71
+ })
72
+ },
73
+ "Error"
74
+ ), /* @__PURE__ */ import_react.default.createElement(
75
+ import_yee_c.Button,
76
+ {
77
+ onClick: () => applyStatus({
78
+ status: "error",
79
+ message: "This error prevents submission",
80
+ blocking: true
81
+ })
82
+ },
83
+ "Blocking error"
84
+ ), /* @__PURE__ */ import_react.default.createElement(
85
+ import_yee_c.Button,
86
+ {
87
+ onClick: () => applyStatus({
88
+ status: "warning",
89
+ message: "This username is commonly used"
90
+ })
91
+ },
92
+ "Warning"
93
+ ), /* @__PURE__ */ import_react.default.createElement(
94
+ import_yee_c.Button,
95
+ {
96
+ onClick: () => applyStatus({
97
+ status: "success",
98
+ message: "This username is available"
99
+ })
100
+ },
101
+ "Success"
102
+ ), /* @__PURE__ */ import_react.default.createElement(
103
+ import_yee_c.Button,
104
+ {
105
+ onClick: () => applyStatus({
106
+ status: "info",
107
+ message: "The username can be changed later"
108
+ })
109
+ },
110
+ "Info"
111
+ ), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Button, { onClick: () => applyStatus(null) }, "Clear"), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Button, { type: "primary", htmlType: "submit" }, "Submit")),
112
+ /* @__PURE__ */ import_react.default.createElement("pre", { style: { marginTop: 16 } }, "Current status: ", JSON.stringify(currentStatus, null, 2)),
113
+ submitResult ? /* @__PURE__ */ import_react.default.createElement("div", null, submitResult) : null,
114
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { marginTop: 8, color: "#999" } }, "Tip: set Success, then clear the input — the rule error takes display precedence over the manually set status.")
115
+ );
116
+ };
@@ -1,10 +1,11 @@
1
- import type { Callbacks, FieldEntity, FormInstance, FormListField, FormListOperation, GroupEntity, Name, NamePath, Store, TRIGGER, ValidateMessage } from './interface';
1
+ import type { Callbacks, FieldEntity, FieldStatusData, FormInstance, FormListField, FormListOperation, GroupEntity, Name, NamePath, Store, TRIGGER, ValidateMessage } from './interface';
2
2
  export declare class FormStore {
3
3
  private store;
4
4
  private callbacks;
5
5
  private fieldEntities;
6
6
  private fieldMap;
7
7
  private validateMessages;
8
+ private fieldStatuses;
8
9
  private initialized;
9
10
  private initialValues;
10
11
  private listKeyManagers;
@@ -23,6 +24,10 @@ export declare class FormStore {
23
24
  private getValueByPath;
24
25
  getFieldValue: (name: Name) => any;
25
26
  getFieldValidate: (name: Name) => ValidateMessage | null;
27
+ getFieldStatus: (name: NamePath) => FieldStatusData | null;
28
+ setFieldStatus: (name: NamePath, status: FieldStatusData | null) => void;
29
+ private deleteRelatedEntries;
30
+ private clearFieldStatuses;
26
31
  setFieldsValue: (newStore: Store, trigger?: TRIGGER) => void;
27
32
  resetFields: (name?: Name[]) => void;
28
33
  clearFields: (name?: Name[]) => void;
@@ -88,6 +88,7 @@ var FormStore = class {
88
88
  this.fieldEntities = [];
89
89
  this.fieldMap = /* @__PURE__ */ new Map();
90
90
  this.validateMessages = /* @__PURE__ */ new Map();
91
+ this.fieldStatuses = /* @__PURE__ */ new Map();
91
92
  this.initialized = false;
92
93
  this.initialValues = {};
93
94
  // List key manager
@@ -143,6 +144,60 @@ var FormStore = class {
143
144
  }
144
145
  return null;
145
146
  };
147
+ this.getFieldStatus = (name) => {
148
+ var _a;
149
+ const normalizedName = (0, import_path.stringifyPath)((0, import_path.getNamePath)(name));
150
+ const manualStatus = this.fieldStatuses.get(normalizedName);
151
+ const validateMessage = (_a = this.validateMessages.get(normalizedName)) == null ? void 0 : _a[0];
152
+ if ((validateMessage == null ? void 0 : validateMessage.status) === "error") {
153
+ return {
154
+ status: "error",
155
+ message: validateMessage.message
156
+ };
157
+ }
158
+ if (manualStatus) {
159
+ return __spreadValues({}, manualStatus);
160
+ }
161
+ if (validateMessage) {
162
+ return {
163
+ status: validateMessage.status,
164
+ message: validateMessage.message
165
+ };
166
+ }
167
+ return null;
168
+ };
169
+ this.setFieldStatus = (name, status) => {
170
+ var _a;
171
+ const normalizedName = (0, import_path.stringifyPath)((0, import_path.getNamePath)(name));
172
+ if (!normalizedName)
173
+ return;
174
+ if (status) {
175
+ this.fieldStatuses.set(normalizedName, __spreadValues({}, status));
176
+ } else {
177
+ this.fieldStatuses.delete(normalizedName);
178
+ }
179
+ (_a = this.fieldMap.get(normalizedName)) == null ? void 0 : _a.onStoreChange();
180
+ };
181
+ // Delete entries whose key equals or nests under one of `names`
182
+ // (no names = delete all). Keeps rule messages and manual statuses in
183
+ // sync with the fields that reset/clear actually touched.
184
+ this.deleteRelatedEntries = (entries, names) => {
185
+ if (!names) {
186
+ entries.clear();
187
+ return;
188
+ }
189
+ const normalizedNames = names.map(
190
+ (name) => (0, import_path.stringifyPath)((0, import_path.getNamePath)(name))
191
+ );
192
+ Array.from(entries.keys()).forEach((fieldName) => {
193
+ if (normalizedNames.some((name) => isRelatedNamePath(fieldName, name))) {
194
+ entries.delete(fieldName);
195
+ }
196
+ });
197
+ };
198
+ this.clearFieldStatuses = (names) => {
199
+ this.deleteRelatedEntries(this.fieldStatuses, names);
200
+ };
146
201
  this.setFieldsValue = (newStore, trigger = "onChange") => {
147
202
  var _a, _b, _c, _d;
148
203
  if (trigger === "reset" || trigger === "clear") {
@@ -208,7 +263,8 @@ var FormStore = class {
208
263
  });
209
264
  }
210
265
  (_b = (_a = this.callbacks) == null ? void 0 : _a.onReset) == null ? void 0 : _b.call(_a);
211
- this.validateMessages.clear();
266
+ this.deleteRelatedEntries(this.validateMessages, name);
267
+ this.clearFieldStatuses(name);
212
268
  this.groupEntities.forEach((entity) => entity.reset());
213
269
  this.refreshField();
214
270
  };
@@ -218,6 +274,7 @@ var FormStore = class {
218
274
  acc[name2] = void 0;
219
275
  return acc;
220
276
  }, {});
277
+ this.clearFieldStatuses(name);
221
278
  this.setFieldsValue(clearStore, "clear");
222
279
  };
223
280
  this.validateField = (name, trigger) => __async(this, null, function* () {
@@ -483,7 +540,20 @@ var FormStore = class {
483
540
  const { onFinish, onFinishFailed } = this.callbacks;
484
541
  const fieldErrors = yield this.validateFields();
485
542
  const groupErrors = yield this.validateGroups(true);
486
- const allErrors = [...fieldErrors, ...groupErrors];
543
+ const statusErrors = Array.from(this.fieldStatuses.entries()).filter(
544
+ ([, status]) => status.status === "error" && status.blocking === true
545
+ ).map(
546
+ ([name, status]) => {
547
+ var _a;
548
+ return {
549
+ name,
550
+ message: (_a = status.message) != null ? _a : "",
551
+ value: this.getFieldValue(name),
552
+ status: "error"
553
+ };
554
+ }
555
+ );
556
+ const allErrors = [...fieldErrors, ...groupErrors, ...statusErrors];
487
557
  if (allErrors.length === 0) {
488
558
  onFinish == null ? void 0 : onFinish(this.getFieldsValue());
489
559
  } else {
@@ -520,6 +590,8 @@ var FormStore = class {
520
590
  getForm() {
521
591
  return {
522
592
  getFieldValidate: this.getFieldValidate,
593
+ getFieldStatus: this.getFieldStatus,
594
+ setFieldStatus: this.setFieldStatus,
523
595
  getFieldsValue: this.getFieldsValue,
524
596
  getFieldValue: this.getFieldValue,
525
597
  setFieldsValue: this.setFieldsValue,
@@ -16,5 +16,5 @@ type FormInterface = typeof InternalForm & {
16
16
  List: typeof List;
17
17
  };
18
18
  declare const Form: FormInterface;
19
- export type { FieldGroupProps, FormInstance, FormListProps, FormProps, } from './interface';
19
+ export type { FieldGroupProps, FieldStatus, FieldStatusData, FormInstance, FormListProps, FormProps, } from './interface';
20
20
  export default Form;
@@ -96,6 +96,15 @@ export interface FormInstance<Values = any> {
96
96
  * Get field validation info
97
97
  */
98
98
  getFieldValidate: (name: Name) => ValidateMessage | null;
99
+ /**
100
+ * Get the displayed field status. Rule validation errors take display
101
+ * precedence; otherwise a manually set status overrides validation.
102
+ */
103
+ getFieldStatus: (name: NamePath) => FieldStatusData | null;
104
+ /**
105
+ * Set or clear a field's displayed status. Pass null to clear it.
106
+ */
107
+ setFieldStatus: (name: NamePath, status: FieldStatusData | null) => void;
99
108
  /**
100
109
  * Get field value
101
110
  */
@@ -225,11 +234,18 @@ export type Rule = {
225
234
  */
226
235
  validateTrigger?: 'onBlur' | 'onChange' | 'onSubmit' | 'reset' | Array<'onBlur' | 'onChange' | 'onSubmit'>;
227
236
  };
237
+ export type FieldStatus = 'error' | 'success' | 'warning' | 'info';
238
+ export type FieldStatusData = {
239
+ status: FieldStatus;
240
+ message?: string;
241
+ /** Whether an error status should prevent form submission. */
242
+ blocking?: boolean;
243
+ };
228
244
  export type ValidateMessage = {
229
245
  name: NamePath | NamePath[] | undefined;
230
246
  message: string;
231
247
  value: unknown;
232
- status: 'error' | 'success' | 'warning' | 'info';
248
+ status: FieldStatus;
233
249
  };
234
250
  export type FieldConfigurableTooltip = Omit<TooltipProps, 'children'> & {
235
251
  /**
@@ -79,6 +79,18 @@
79
79
  &-error {
80
80
  color: var(--yee-error-color);
81
81
  }
82
+
83
+ &-warning {
84
+ color: var(--yee-warning-color);
85
+ }
86
+
87
+ &-success {
88
+ color: var(--yee-success-color);
89
+ }
90
+
91
+ &-info {
92
+ color: var(--yee-info-color);
93
+ }
82
94
  }
83
95
 
84
96
  // 表单校验态:在此重定义控件读取的 border / box-shadow 变量,
@@ -97,5 +109,19 @@
97
109
  --yee-input-focus-bs-color: var(--yee-warning-color-border);
98
110
  --yee-checkbox-border-color: var(--yee-warning-color);
99
111
  }
112
+
113
+ &&-success {
114
+ --yee-input-border-color: var(--yee-success-color);
115
+ --yee-input-hover-border-color: var(--yee-success-color-hover);
116
+ --yee-input-focus-bs-color: var(--yee-success-color-border);
117
+ --yee-checkbox-border-color: var(--yee-success-color);
118
+ }
119
+
120
+ &&-info {
121
+ --yee-input-border-color: var(--yee-info-color);
122
+ --yee-input-hover-border-color: var(--yee-info-color-hover);
123
+ --yee-input-focus-bs-color: var(--yee-info-color-border);
124
+ --yee-checkbox-border-color: var(--yee-info-color);
125
+ }
100
126
  }
101
127
  }
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-08-13T08:02:29.627Z
4
+ * Generated on 2026-08-17T03:37:29.587Z
5
5
  */
6
6
 
7
7
  /* ========== color.blue.css ========== */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-08-13T08:02:29.627Z
4
+ * Generated on 2026-08-17T03:37:29.587Z
5
5
  */
6
6
 
7
7
  /* ========== color.css ========== */
@@ -3,4 +3,4 @@ declare global {
3
3
  __yee_c_version__: string;
4
4
  }
5
5
  }
6
- export declare const version = "0.8.20";
6
+ export declare const version = "0.9.0";
@@ -22,7 +22,7 @@ __export(version_exports, {
22
22
  version: () => version
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- var version = "0.8.20";
25
+ var version = "0.9.0";
26
26
  if (typeof window !== "undefined") {
27
27
  window.__yee_c_version__ = version;
28
28
  }
@@ -55,7 +55,7 @@ var Field = function Field(props) {
55
55
  formatter = props.formatter;
56
56
  var _useContext = useContext(FieldContext),
57
57
  getCallbacks = _useContext.getCallbacks,
58
- getFieldValidate = _useContext.getFieldValidate,
58
+ getFieldStatus = _useContext.getFieldStatus,
59
59
  getFieldValue = _useContext.getFieldValue,
60
60
  getFieldsValue = _useContext.getFieldsValue,
61
61
  setFieldsValue = _useContext.setFieldsValue,
@@ -98,7 +98,7 @@ var Field = function Field(props) {
98
98
  return rule.required;
99
99
  }) || required;
100
100
  };
101
- var validate = getFieldValidate === null || getFieldValidate === void 0 ? void 0 : getFieldValidate(normalizedName);
101
+ var fieldStatus = getFieldStatus === null || getFieldStatus === void 0 ? void 0 : getFieldStatus(normalizedName);
102
102
 
103
103
  // Normalize tooltip into { icon, ...tooltipProps }, or null when not provided.
104
104
  // Everything except `icon` is forwarded to <Tooltip>, so any Tooltip prop
@@ -163,7 +163,7 @@ var Field = function Field(props) {
163
163
  });
164
164
  };
165
165
  return /*#__PURE__*/React.createElement("div", {
166
- className: clsx("".concat(prefixCls, "-item"), "".concat(prefixCls, "-item-").concat(layout), _defineProperty({}, "".concat(prefixCls, "-item-").concat(validate === null || validate === void 0 ? void 0 : validate.status), validate && validate.status), className),
166
+ className: clsx("".concat(prefixCls, "-item"), "".concat(prefixCls, "-item-").concat(layout), _defineProperty({}, "".concat(prefixCls, "-item-").concat(fieldStatus === null || fieldStatus === void 0 ? void 0 : fieldStatus.status), fieldStatus === null || fieldStatus === void 0 ? void 0 : fieldStatus.status), className),
167
167
  style: style
168
168
  }, /*#__PURE__*/React.createElement("div", {
169
169
  className: clsx("".concat(prefixCls, "-item-row"))
@@ -178,7 +178,7 @@ var Field = function Field(props) {
178
178
  }, tooltipConfig.icon)) : null) : null, /*#__PURE__*/React.createElement("div", {
179
179
  className: clsx("".concat(prefixCls, "-item-control"), classNames === null || classNames === void 0 ? void 0 : classNames.control),
180
180
  style: styles === null || styles === void 0 ? void 0 : styles.control
181
- }, /*#__PURE__*/React.isValidElement(children) ? ( /*#__PURE__*/React.cloneElement(children, getControlled(children))) : /*#__PURE__*/React.createElement("span", null, children))), /*#__PURE__*/React.createElement(AnimatePresence, null, validate && /*#__PURE__*/React.createElement(motion.small, {
181
+ }, /*#__PURE__*/React.isValidElement(children) ? ( /*#__PURE__*/React.cloneElement(children, getControlled(children))) : /*#__PURE__*/React.createElement("span", null, children))), /*#__PURE__*/React.createElement(AnimatePresence, null, (fieldStatus === null || fieldStatus === void 0 ? void 0 : fieldStatus.message) && /*#__PURE__*/React.createElement(motion.small, {
182
182
  initial: {
183
183
  opacity: 0,
184
184
  y: -10
@@ -194,7 +194,7 @@ var Field = function Field(props) {
194
194
  transition: {
195
195
  duration: 0.16
196
196
  },
197
- className: clsx("".concat(prefixCls, "-item-additional"), _defineProperty({}, "".concat(prefixCls, "-item-additional-").concat(validate.status), validate.status))
198
- }, validate.message)));
197
+ className: clsx("".concat(prefixCls, "-item-additional"), _defineProperty({}, "".concat(prefixCls, "-item-additional-").concat(fieldStatus.status), fieldStatus.status))
198
+ }, fieldStatus.message)));
199
199
  };
200
200
  export default Field;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const _default: () => React.JSX.Element;
3
+ export default _default;
@@ -0,0 +1,104 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { Button, Form, Input, Space } from "../..";
8
+ import React, { useState } from 'react';
9
+ export default (function () {
10
+ var _Form$useForm = Form.useForm(),
11
+ _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
12
+ form = _Form$useForm2[0];
13
+ var _useState = useState(null),
14
+ _useState2 = _slicedToArray(_useState, 2),
15
+ currentStatus = _useState2[0],
16
+ setCurrentStatus = _useState2[1];
17
+ var _useState3 = useState(''),
18
+ _useState4 = _slicedToArray(_useState3, 2),
19
+ submitResult = _useState4[0],
20
+ setSubmitResult = _useState4[1];
21
+ var applyStatus = function applyStatus(status) {
22
+ form.setFieldStatus('username', status);
23
+ setCurrentStatus(form.getFieldStatus('username'));
24
+ setSubmitResult('');
25
+ };
26
+ return /*#__PURE__*/React.createElement(Form, {
27
+ form: form,
28
+ initialValues: {
29
+ username: 'demo-user'
30
+ },
31
+ onFinish: function onFinish() {
32
+ return setSubmitResult('Submit succeeded');
33
+ },
34
+ onFinishFailed: function onFinishFailed() {
35
+ return setSubmitResult('Submit blocked by the blocking error');
36
+ }
37
+ }, /*#__PURE__*/React.createElement(Form.Field, {
38
+ name: "username",
39
+ label: "Username",
40
+ rules: [{
41
+ required: true,
42
+ message: 'Please input your username!'
43
+ }]
44
+ }, /*#__PURE__*/React.createElement(Input, {
45
+ placeholder: "Please input your username"
46
+ })), /*#__PURE__*/React.createElement(Space, {
47
+ style: {
48
+ marginTop: 28,
49
+ flexWrap: 'wrap'
50
+ }
51
+ }, /*#__PURE__*/React.createElement(Button, {
52
+ onClick: function onClick() {
53
+ return applyStatus({
54
+ status: 'error',
55
+ message: 'This username is unavailable'
56
+ });
57
+ }
58
+ }, "Error"), /*#__PURE__*/React.createElement(Button, {
59
+ onClick: function onClick() {
60
+ return applyStatus({
61
+ status: 'error',
62
+ message: 'This error prevents submission',
63
+ blocking: true
64
+ });
65
+ }
66
+ }, "Blocking error"), /*#__PURE__*/React.createElement(Button, {
67
+ onClick: function onClick() {
68
+ return applyStatus({
69
+ status: 'warning',
70
+ message: 'This username is commonly used'
71
+ });
72
+ }
73
+ }, "Warning"), /*#__PURE__*/React.createElement(Button, {
74
+ onClick: function onClick() {
75
+ return applyStatus({
76
+ status: 'success',
77
+ message: 'This username is available'
78
+ });
79
+ }
80
+ }, "Success"), /*#__PURE__*/React.createElement(Button, {
81
+ onClick: function onClick() {
82
+ return applyStatus({
83
+ status: 'info',
84
+ message: 'The username can be changed later'
85
+ });
86
+ }
87
+ }, "Info"), /*#__PURE__*/React.createElement(Button, {
88
+ onClick: function onClick() {
89
+ return applyStatus(null);
90
+ }
91
+ }, "Clear"), /*#__PURE__*/React.createElement(Button, {
92
+ type: "primary",
93
+ htmlType: "submit"
94
+ }, "Submit")), /*#__PURE__*/React.createElement("pre", {
95
+ style: {
96
+ marginTop: 16
97
+ }
98
+ }, "Current status: ", JSON.stringify(currentStatus, null, 2)), submitResult ? /*#__PURE__*/React.createElement("div", null, submitResult) : null, /*#__PURE__*/React.createElement("div", {
99
+ style: {
100
+ marginTop: 8,
101
+ color: '#999'
102
+ }
103
+ }, "Tip: set Success, then clear the input \u2014 the rule error takes display precedence over the manually set status."));
104
+ });
@@ -1,10 +1,11 @@
1
- import type { Callbacks, FieldEntity, FormInstance, FormListField, FormListOperation, GroupEntity, Name, NamePath, Store, TRIGGER, ValidateMessage } from './interface';
1
+ import type { Callbacks, FieldEntity, FieldStatusData, FormInstance, FormListField, FormListOperation, GroupEntity, Name, NamePath, Store, TRIGGER, ValidateMessage } from './interface';
2
2
  export declare class FormStore {
3
3
  private store;
4
4
  private callbacks;
5
5
  private fieldEntities;
6
6
  private fieldMap;
7
7
  private validateMessages;
8
+ private fieldStatuses;
8
9
  private initialized;
9
10
  private initialValues;
10
11
  private listKeyManagers;
@@ -23,6 +24,10 @@ export declare class FormStore {
23
24
  private getValueByPath;
24
25
  getFieldValue: (name: Name) => any;
25
26
  getFieldValidate: (name: Name) => ValidateMessage | null;
27
+ getFieldStatus: (name: NamePath) => FieldStatusData | null;
28
+ setFieldStatus: (name: NamePath, status: FieldStatusData | null) => void;
29
+ private deleteRelatedEntries;
30
+ private clearFieldStatuses;
26
31
  setFieldsValue: (newStore: Store, trigger?: TRIGGER) => void;
27
32
  resetFields: (name?: Name[]) => void;
28
33
  clearFields: (name?: Name[]) => void;