1 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
3 | import * as React from 'react';
|
4 | import classNames from 'classnames';
|
5 | import CSSMotion from 'rc-motion';
|
6 | import useMemo from "rc-util/es/hooks/useMemo";
|
7 | import useCacheErrors from './hooks/useCacheErrors';
|
8 | import useForceUpdate from '../_util/hooks/useForceUpdate';
|
9 | import { FormItemPrefixContext } from './context';
|
10 | import { ConfigContext } from '../config-provider';
|
11 | var EMPTY_LIST = [];
|
12 | export default function ErrorList(_ref) {
|
13 | var _ref$errors = _ref.errors,
|
14 | errors = _ref$errors === void 0 ? EMPTY_LIST : _ref$errors,
|
15 | help = _ref.help,
|
16 | onDomErrorVisibleChange = _ref.onDomErrorVisibleChange;
|
17 | var forceUpdate = useForceUpdate();
|
18 |
|
19 | var _React$useContext = React.useContext(FormItemPrefixContext),
|
20 | prefixCls = _React$useContext.prefixCls,
|
21 | status = _React$useContext.status;
|
22 |
|
23 | var _React$useContext2 = React.useContext(ConfigContext),
|
24 | getPrefixCls = _React$useContext2.getPrefixCls;
|
25 |
|
26 | var _useCacheErrors = useCacheErrors(errors, function (changedVisible) {
|
27 | if (changedVisible) {
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | Promise.resolve().then(function () {
|
35 | onDomErrorVisibleChange === null || onDomErrorVisibleChange === void 0 ? void 0 : onDomErrorVisibleChange(true);
|
36 | });
|
37 | }
|
38 |
|
39 | forceUpdate();
|
40 | }, !!help),
|
41 | _useCacheErrors2 = _slicedToArray(_useCacheErrors, 2),
|
42 | visible = _useCacheErrors2[0],
|
43 | cacheErrors = _useCacheErrors2[1];
|
44 |
|
45 | var memoErrors = useMemo(function () {
|
46 | return cacheErrors;
|
47 | }, visible, function (_, nextVisible) {
|
48 | return nextVisible;
|
49 | });
|
50 |
|
51 | var _React$useState = React.useState(status),
|
52 | _React$useState2 = _slicedToArray(_React$useState, 2),
|
53 | innerStatus = _React$useState2[0],
|
54 | setInnerStatus = _React$useState2[1];
|
55 |
|
56 | React.useEffect(function () {
|
57 | if (visible && status) {
|
58 | setInnerStatus(status);
|
59 | }
|
60 | }, [visible, status]);
|
61 | var baseClassName = "".concat(prefixCls, "-item-explain");
|
62 | var rootPrefixCls = getPrefixCls();
|
63 | return React.createElement(CSSMotion, {
|
64 | motionDeadline: 500,
|
65 | visible: visible,
|
66 | motionName: "".concat(rootPrefixCls, "-show-help"),
|
67 | onLeaveEnd: function onLeaveEnd() {
|
68 | onDomErrorVisibleChange === null || onDomErrorVisibleChange === void 0 ? void 0 : onDomErrorVisibleChange(false);
|
69 | }
|
70 | }, function (_ref2) {
|
71 | var motionClassName = _ref2.className;
|
72 | return React.createElement("div", {
|
73 | className: classNames(baseClassName, _defineProperty({}, "".concat(baseClassName, "-").concat(innerStatus), innerStatus), motionClassName),
|
74 | key: "help"
|
75 | }, memoErrors.map(function (error, index) {
|
76 | return (
|
77 |
|
78 |
|
79 | React.createElement("div", {
|
80 | key: index,
|
81 | role: "alert"
|
82 | }, error)
|
83 | );
|
84 | }));
|
85 | });
|
86 | } |
\ | No newline at end of file |