@autobest-ui/components 2.3.0 → 2.4.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.
Files changed (140) hide show
  1. package/esm/accordion/Item.js +6 -23
  2. package/esm/accordion/index.js +8 -36
  3. package/esm/affix/PortalAffix.js +7 -11
  4. package/esm/affix/index.js +30 -70
  5. package/esm/carousel/index.js +45 -141
  6. package/esm/checkbox/index.js +12 -37
  7. package/esm/collapse/index.js +11 -49
  8. package/esm/confirm/index.d.ts +8 -0
  9. package/esm/confirm/index.js +23 -31
  10. package/esm/date-picker/DateEnum.js +0 -3
  11. package/esm/date-picker/calendar/Day.js +62 -78
  12. package/esm/date-picker/calendar/MonthYear.js +20 -53
  13. package/esm/date-picker/calendar/grid/index.js +7 -12
  14. package/esm/date-picker/calendar/index.js +4 -31
  15. package/esm/date-picker/index.js +11 -51
  16. package/esm/date-picker/utils.js +6 -11
  17. package/esm/drawer/Child.js +10 -20
  18. package/esm/drawer/index.js +22 -71
  19. package/esm/ellipsis/index.js +9 -17
  20. package/esm/guide/index.js +25 -63
  21. package/esm/index.d.ts +1 -1
  22. package/esm/input-number/ControlArrow.js +0 -2
  23. package/esm/input-number/constants.js +2 -2
  24. package/esm/input-number/index.js +26 -106
  25. package/esm/lazy-image/index.js +10 -55
  26. package/esm/link-list/index.js +11 -35
  27. package/esm/loading/index.js +15 -42
  28. package/esm/loading-container/index.js +3 -6
  29. package/esm/loading-icon/index.js +0 -2
  30. package/esm/mask/index.js +6 -9
  31. package/esm/message/index.d.ts +17 -6
  32. package/esm/message/index.js +68 -96
  33. package/esm/message/renderMessage.d.ts +17 -0
  34. package/esm/message/renderMessage.js +137 -0
  35. package/esm/message/style/index.css +1 -1
  36. package/esm/modal/Title.js +5 -12
  37. package/esm/modal/getPopupLocation.js +5 -7
  38. package/esm/modal/index.js +44 -125
  39. package/esm/move/index.js +32 -132
  40. package/esm/move/range.js +6 -12
  41. package/esm/move/utils.js +3 -10
  42. package/esm/popover/index.js +9 -28
  43. package/esm/portal/index.js +1 -22
  44. package/esm/script/index.js +19 -59
  45. package/esm/select/index.js +28 -106
  46. package/esm/show-more/index.js +40 -103
  47. package/esm/skeleton/Item.js +1 -3
  48. package/esm/skeleton/index.js +5 -11
  49. package/esm/style.css +1 -1
  50. package/esm/table/body/BodyRow.js +11 -28
  51. package/esm/table/body/CheckIcon.js +10 -18
  52. package/esm/table/body/index.js +8 -12
  53. package/esm/table/header/CheckIcon.js +3 -11
  54. package/esm/table/header/HeaderCell.js +12 -33
  55. package/esm/table/header/HeaderRow.js +6 -17
  56. package/esm/table/index.js +30 -100
  57. package/esm/tabs/index.js +35 -118
  58. package/esm/tooltip/index.js +0 -4
  59. package/esm/trigger/align.js +6 -6
  60. package/esm/trigger/bottomAlign.js +33 -45
  61. package/esm/trigger/constants.js +0 -1
  62. package/esm/trigger/getPopupLocation.js +48 -68
  63. package/esm/trigger/index.js +52 -187
  64. package/esm/trigger/leftAlign.js +33 -47
  65. package/esm/trigger/ref.js +2 -7
  66. package/esm/trigger/rightAlign.js +33 -45
  67. package/esm/trigger/topAlign.js +33 -45
  68. package/esm/trigger/utils.js +28 -45
  69. package/lib/accordion/Item.js +6 -27
  70. package/lib/accordion/index.js +8 -41
  71. package/lib/affix/PortalAffix.js +7 -17
  72. package/lib/affix/index.js +30 -75
  73. package/lib/carousel/index.js +45 -146
  74. package/lib/checkbox/index.js +12 -41
  75. package/lib/collapse/index.js +11 -53
  76. package/lib/confirm/index.d.ts +8 -0
  77. package/lib/confirm/index.js +23 -38
  78. package/lib/date-picker/DateEnum.js +0 -3
  79. package/lib/date-picker/calendar/Day.js +62 -87
  80. package/lib/date-picker/calendar/MonthYear.js +20 -62
  81. package/lib/date-picker/calendar/grid/index.js +7 -16
  82. package/lib/date-picker/calendar/index.js +4 -37
  83. package/lib/date-picker/index.js +9 -58
  84. package/lib/date-picker/utils.js +6 -26
  85. package/lib/drawer/Child.js +10 -25
  86. package/lib/drawer/index.js +22 -78
  87. package/lib/ellipsis/index.js +9 -23
  88. package/lib/guide/index.js +25 -71
  89. package/lib/index.d.ts +1 -1
  90. package/lib/index.js +0 -29
  91. package/lib/input-number/ControlArrow.js +0 -4
  92. package/lib/input-number/constants.js +2 -2
  93. package/lib/input-number/index.js +26 -114
  94. package/lib/lazy-image/index.js +10 -58
  95. package/lib/link-list/index.js +11 -40
  96. package/lib/loading/index.js +13 -48
  97. package/lib/loading-bar/index.js +0 -5
  98. package/lib/loading-container/index.js +3 -11
  99. package/lib/loading-icon/index.js +0 -7
  100. package/lib/mask/index.js +6 -17
  101. package/lib/message/index.d.ts +17 -6
  102. package/lib/message/index.js +67 -104
  103. package/lib/message/renderMessage.d.ts +17 -0
  104. package/lib/message/renderMessage.js +144 -0
  105. package/lib/message/style/index.css +1 -1
  106. package/lib/modal/Affix.js +0 -4
  107. package/lib/modal/Title.js +5 -15
  108. package/lib/modal/getPopupLocation.js +5 -9
  109. package/lib/modal/index.js +44 -135
  110. package/lib/move/index.js +32 -144
  111. package/lib/move/range.js +6 -14
  112. package/lib/move/utils.js +3 -12
  113. package/lib/popover/index.js +9 -33
  114. package/lib/portal/index.js +1 -25
  115. package/lib/script/index.js +19 -61
  116. package/lib/select/index.js +28 -113
  117. package/lib/show-more/index.js +40 -110
  118. package/lib/skeleton/Item.js +1 -8
  119. package/lib/skeleton/index.js +5 -16
  120. package/lib/style.css +1 -1
  121. package/lib/table/body/BodyRow.js +11 -33
  122. package/lib/table/body/CheckIcon.js +10 -22
  123. package/lib/table/body/index.js +8 -17
  124. package/lib/table/header/CheckIcon.js +3 -15
  125. package/lib/table/header/HeaderCell.js +12 -37
  126. package/lib/table/header/HeaderRow.js +6 -22
  127. package/lib/table/index.js +30 -107
  128. package/lib/tabs/index.js +35 -122
  129. package/lib/tooltip/index.js +0 -9
  130. package/lib/trigger/align.js +0 -4
  131. package/lib/trigger/bottomAlign.js +33 -48
  132. package/lib/trigger/constants.js +0 -2
  133. package/lib/trigger/getPopupLocation.js +48 -74
  134. package/lib/trigger/index.js +52 -198
  135. package/lib/trigger/leftAlign.js +33 -50
  136. package/lib/trigger/ref.js +2 -12
  137. package/lib/trigger/rightAlign.js +33 -48
  138. package/lib/trigger/topAlign.js +33 -48
  139. package/lib/trigger/utils.js +28 -53
  140. package/package.json +7 -3
@@ -9,53 +9,38 @@ var __extends = this && this.__extends || function () {
9
9
  if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
10
10
  }
11
11
  };
12
-
13
12
  return _extendStatics(d, b);
14
13
  };
15
-
16
14
  return function (d, b) {
17
15
  if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
18
-
19
16
  _extendStatics(d, b);
20
-
21
17
  function __() {
22
18
  this.constructor = d;
23
19
  }
24
-
25
20
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
26
21
  };
27
22
  }();
28
-
29
23
  import React from 'react';
30
24
  import classNames from 'classnames';
31
25
  import { isEmptyObject } from '@autobest-ui/utils';
32
26
  import Popover from '../popover';
33
-
34
- var LinkList =
35
- /** @class */
36
- function (_super) {
27
+ var LinkList = /** @class */function (_super) {
37
28
  __extends(LinkList, _super);
38
-
39
29
  function LinkList(props) {
40
30
  var _this = _super.call(this, props) || this;
41
-
42
31
  _this.prefixCls = 'ab-link-list';
43
-
44
32
  _this.onVisibleChange = function () {
45
33
  _this.setState({
46
34
  visible: !_this.state.visible
47
35
  });
48
36
  };
49
-
50
37
  _this.state = {
51
38
  visible: props.defaultVisible
52
39
  };
53
40
  return _this;
54
41
  }
55
-
56
42
  LinkList.prototype.renderItemContent = function (item) {
57
43
  var _a;
58
-
59
44
  var hrefTarget = this.props.hrefTarget;
60
45
  var cls = this.prefixCls;
61
46
  return item.url ? /*#__PURE__*/React.createElement("a", {
@@ -68,13 +53,11 @@ function (_super) {
68
53
  className: classNames((_a = {}, _a["".concat(cls, "-hidden")] = item.isHidden, _a))
69
54
  }, "".concat(item.name, " "));
70
55
  };
71
-
72
56
  LinkList.prototype.renderItem = function (item) {
73
57
  // 判断hiddenPopover和是否有具体的popover参数
74
58
  if (this.props.hiddenPopover || isEmptyObject(item.subInfo)) {
75
59
  return this.renderItemContent(item);
76
60
  }
77
-
78
61
  var subInfo = item.subInfo;
79
62
  var cls = this.prefixCls;
80
63
  return /*#__PURE__*/React.createElement(Popover, {
@@ -95,37 +78,32 @@ function (_super) {
95
78
  mouseEnterDelay: 0.1
96
79
  }, this.renderItemContent(item));
97
80
  };
98
-
99
81
  LinkList.prototype.renderContent = function () {
100
82
  var _this = this;
101
-
102
83
  var _a = this.props,
103
- hiddenPopover = _a.hiddenPopover,
104
- options = _a.options; // 隐藏popover和忽略分列
105
-
84
+ hiddenPopover = _a.hiddenPopover,
85
+ options = _a.options;
86
+ // 隐藏popover和忽略分列
106
87
  if (hiddenPopover) {
107
88
  return options.map(function (item) {
108
89
  return _this.renderItemContent(item);
109
90
  });
110
- } // 忽略分列
111
-
112
-
91
+ }
92
+ // 忽略分列
113
93
  return options.map(function (item) {
114
94
  return _this.renderItem(item);
115
95
  });
116
96
  };
117
-
118
97
  LinkList.prototype.render = function () {
119
98
  var _a, _b;
120
-
121
99
  var cls = this.prefixCls;
122
100
  var visible = this.state.visible;
123
101
  var _c = this.props,
124
- className = _c.className,
125
- title = _c.title,
126
- extraTopElement = _c.extraTopElement,
127
- extraBottomElement = _c.extraBottomElement,
128
- columnCount = _c.columnCount;
102
+ className = _c.className,
103
+ title = _c.title,
104
+ extraTopElement = _c.extraTopElement,
105
+ extraBottomElement = _c.extraBottomElement,
106
+ columnCount = _c.columnCount;
129
107
  return /*#__PURE__*/React.createElement("div", {
130
108
  className: classNames(cls, className)
131
109
  }, title ? /*#__PURE__*/React.createElement("div", {
@@ -139,7 +117,6 @@ function (_super) {
139
117
  className: classNames("".concat(cls, "-content"), "".concat(cls, "-col").concat(columnCount))
140
118
  }, this.renderContent()), extraBottomElement));
141
119
  };
142
-
143
120
  LinkList.defaultProps = {
144
121
  className: '',
145
122
  hrefTarget: '_self',
@@ -150,5 +127,4 @@ function (_super) {
150
127
  };
151
128
  return LinkList;
152
129
  }(React.Component);
153
-
154
130
  export default LinkList;
@@ -2,63 +2,51 @@ var __assign = this && this.__assign || function () {
2
2
  __assign = Object.assign || function (t) {
3
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4
4
  s = arguments[i];
5
-
6
5
  for (var p in s) {
7
6
  if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
7
  }
9
8
  }
10
-
11
9
  return t;
12
10
  };
13
-
14
11
  return __assign.apply(this, arguments);
15
12
  };
16
-
17
13
  import React from 'react';
18
14
  import classNames from 'classnames';
19
15
  import ReactDOM from 'react-dom';
20
16
  import { canUseDOM } from '@autobest-ui/utils';
21
- import LoadingIcon from '../loading-icon'; // 缓存创建的loading元素
22
-
17
+ import LoadingIcon from '../loading-icon';
18
+ // 缓存创建的loading元素
23
19
  var loadingElement = null;
24
20
  var loadingTimer = null;
25
21
  var closeTimer = null;
26
22
  var prevCustomIcon = null;
27
23
  var cls = 'ab-loading';
28
-
29
24
  function getLoadingContainer(customIcon, className) {
30
25
  return /*#__PURE__*/React.createElement("div", {
31
26
  className: classNames("".concat(cls, "-wrap"), className)
32
27
  }, customIcon || /*#__PURE__*/React.createElement(LoadingIcon, {
33
28
  className: "".concat(cls, "-content")
34
29
  }));
35
- } // openIds 容器
36
-
37
-
38
- var openIds = []; // closeIds 容器
39
-
30
+ }
31
+ // openIds 容器
32
+ var openIds = [];
33
+ // closeIds 容器
40
34
  var closeIds = [];
41
-
42
35
  function createLoading(customIcon, className) {
43
36
  loadingElement = document.createElement('div');
44
37
  document.body.appendChild(loadingElement);
45
38
  ReactDOM.render(getLoadingContainer(customIcon, className), loadingElement);
46
39
  }
47
-
48
- var Loading =
49
- /** @class */
50
- function () {
40
+ var Loading = /** @class */function () {
51
41
  function Loading() {}
52
-
53
42
  Loading.open = function (config) {
54
43
  if (!canUseDOM) {
55
44
  return null;
56
45
  }
57
-
58
46
  config = __assign({
59
47
  expire: 0
60
- }, config); // 防止重复创建或自定义loading icon,重新创建
61
-
48
+ }, config);
49
+ // 防止重复创建或自定义loading icon,重新创建
62
50
  if (!loadingElement) {
63
51
  createLoading(config.customIcon, config.className);
64
52
  } else if (config.customIcon || config.customIcon !== prevCustomIcon) {
@@ -68,75 +56,60 @@ function () {
68
56
  loadingElement = null;
69
57
  } catch (e) {}
70
58
  }
71
-
72
59
  createLoading(config.customIcon, config.className);
73
60
  } else {
74
61
  loadingElement.style.display = 'block';
75
62
  }
76
-
77
- prevCustomIcon = config.customIcon; // 如果配置中有expire且大于0
63
+ prevCustomIcon = config.customIcon;
64
+ // 如果配置中有expire且大于0
78
65
  // 将会在到达时间后自动关闭,不用手动再关闭(不需要再close())
79
-
80
66
  if (config.expire > 0) {
81
67
  loadingTimer = setTimeout(function () {
82
68
  Loading.close();
83
69
  }, config.expire);
84
70
  }
85
-
86
71
  var id = new Date().getTime();
87
72
  openIds.push(id);
88
73
  return id;
89
74
  };
90
-
91
75
  Loading.close = function (closeId) {
92
76
  if (!canUseDOM) {
93
77
  return;
94
- } // 防止重复关闭
95
-
96
-
78
+ }
79
+ // 防止重复关闭
97
80
  if (loadingTimer) {
98
81
  clearTimeout(loadingTimer);
99
82
  }
100
-
101
83
  if (closeTimer) {
102
84
  clearTimeout(closeTimer);
103
85
  }
104
-
105
86
  if (!closeId) {
106
87
  openIds = [];
107
88
  closeIds = [];
108
-
109
89
  if (loadingElement) {
110
90
  loadingElement.style.display = 'none';
111
91
  }
112
-
113
92
  return;
114
93
  }
115
-
116
- closeIds.push(closeId); // 代码执行时,由于一些接口loading很短暂,而另一个接口还没有开始调用,
94
+ closeIds.push(closeId);
95
+ // 代码执行时,由于一些接口loading很短暂,而另一个接口还没有开始调用,
117
96
  // 只有closeId是不能真正解决一些特殊loading抖动情况,
118
97
  // 根据js的任务队列,我们加入setTimeout,只有主线程结束后才执行销毁
119
-
120
98
  closeTimer = setTimeout(function () {
121
99
  closeIds.forEach(function (id) {
122
100
  var index = openIds.indexOf(id);
123
-
124
101
  if (index >= 0) {
125
102
  openIds.splice(index, 1);
126
103
  }
127
104
  });
128
-
129
105
  if (!openIds.length) {
130
106
  closeIds = [];
131
-
132
107
  if (loadingElement) {
133
108
  loadingElement.style.display = 'none';
134
109
  }
135
110
  }
136
111
  });
137
112
  };
138
-
139
113
  return Loading;
140
114
  }();
141
-
142
115
  export default Loading;
@@ -2,14 +2,12 @@ import React from 'react';
2
2
  import classNames from 'classnames';
3
3
  import LoadingIcon from '../loading-icon';
4
4
  var cls = 'ab-loading-container';
5
-
6
5
  function LoadingContainer(props) {
7
6
  var _a;
8
-
9
7
  var _b = props.loading,
10
- loading = _b === void 0 ? false : _b,
11
- className = props.className,
12
- children = props.children;
8
+ loading = _b === void 0 ? false : _b,
9
+ className = props.className,
10
+ children = props.children;
13
11
  return /*#__PURE__*/React.createElement("div", {
14
12
  className: classNames(className, cls, (_a = {}, _a["".concat(cls, "-active")] = loading, _a))
15
13
  }, children, loading && /*#__PURE__*/React.createElement("div", {
@@ -18,5 +16,4 @@ function LoadingContainer(props) {
18
16
  className: "".concat(cls, "-icon")
19
17
  })));
20
18
  }
21
-
22
19
  export default LoadingContainer;
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import classNames from 'classnames';
3
3
  var cls = 'ab-svg-loading';
4
-
5
4
  var LoadingIcon = function LoadingIcon(props) {
6
5
  var className = props.className;
7
6
  return /*#__PURE__*/React.createElement("span", {
@@ -54,5 +53,4 @@ var LoadingIcon = function LoadingIcon(props) {
54
53
  fill: "#fff"
55
54
  })));
56
55
  };
57
-
58
56
  export default /*#__PURE__*/React.memo(LoadingIcon);
package/esm/mask/index.js CHANGED
@@ -3,18 +3,16 @@ import classNames from 'classnames';
3
3
  import { CSSTransition } from 'react-transition-group';
4
4
  import { isTouchScreen } from '@autobest-ui/utils';
5
5
  var prefixCls = 'ab-mask';
6
-
7
6
  function Mask(_a, ref) {
8
7
  var className = _a.className,
9
- _b = _a.timeout,
10
- timeout = _b === void 0 ? 300 : _b,
11
- _c = _a.onClose,
12
- onClose = _c === void 0 ? function () {} : _c,
13
- visible = _a.visible; // mousedown和touchstart会一起触发,这里判断后,只执行一次
14
-
8
+ _b = _a.timeout,
9
+ timeout = _b === void 0 ? 300 : _b,
10
+ _c = _a.onClose,
11
+ onClose = _c === void 0 ? function () {} : _c,
12
+ visible = _a.visible;
13
+ // mousedown和touchstart会一起触发,这里判断后,只执行一次
15
14
  var onChangeVisible = React.useCallback(function (event) {
16
15
  var touch = isTouchScreen();
17
-
18
16
  if (event.type === 'touchstart' && touch || event.type === 'mousedown' && !touch) {
19
17
  onClose(event);
20
18
  }
@@ -31,5 +29,4 @@ function Mask(_a, ref) {
31
29
  ref: ref
32
30
  }));
33
31
  }
34
-
35
32
  export default /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(Mask));
@@ -5,20 +5,31 @@ export interface MessageProps {
5
5
  */
6
6
  content: React.ReactNode;
7
7
  /**
8
- * class样式名
8
+ * 支持多种样式
9
9
  */
10
- className?: string;
11
10
  contentClassName?: string;
12
11
  /**
13
12
  * 提示文字显示的时间,达到时间后自动关闭
14
13
  */
15
14
  expires?: number;
15
+ /**
16
+ * 销毁后的回调
17
+ */
18
+ onDestroy?: () => void;
19
+ }
20
+ export interface MessageConfig {
21
+ className?: string;
22
+ expires?: number;
16
23
  /**
17
24
  * 最多同时显示的提示文字条数
18
25
  */
19
26
  maxCount?: number;
20
- width?: string;
21
- height?: string;
22
- onDestroy?: (id: number) => void;
23
27
  }
24
- export default function Message(config: MessageProps): () => void;
28
+ declare function Message(props: MessageProps): {
29
+ onCloseAll: () => void;
30
+ onClose: () => void;
31
+ };
32
+ declare namespace Message {
33
+ var setConfig: (config: MessageConfig) => void;
34
+ }
35
+ export default Message;
@@ -2,125 +2,97 @@ var __assign = this && this.__assign || function () {
2
2
  __assign = Object.assign || function (t) {
3
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4
4
  s = arguments[i];
5
-
6
5
  for (var p in s) {
7
6
  if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
7
  }
9
8
  }
10
-
11
9
  return t;
12
10
  };
13
-
14
11
  return __assign.apply(this, arguments);
15
12
  };
16
-
17
- import React from 'react';
18
- import { CSSTransition, TransitionGroup } from 'react-transition-group';
19
- import classNames from 'classnames';
20
- import ReactDOM from 'react-dom';
21
- import { canUseDOM } from '@autobest-ui/utils';
22
- var defaultConfig = {
23
- expires: 3000,
24
- maxCount: 3,
25
- width: '6rem',
26
- height: 'auto',
27
- onDestroy: function onDestroy() {}
28
- };
13
+ import { canUseDOM, isEmptyArray } from '@autobest-ui/utils';
14
+ import renderMessage from './renderMessage';
29
15
  var prefixCls = 'ab-message';
30
- var container = null;
31
- var items = [];
16
+ var options = [];
32
17
  var id = 0;
33
- export default function Message(config) {
18
+ // 全局配置的默认值
19
+ var currentConfig = {
20
+ expires: 3000,
21
+ maxCount: 3
22
+ };
23
+ export default function Message(props) {
34
24
  if (!canUseDOM) {
35
25
  throw new Error('Message use client!');
36
26
  }
37
-
38
27
  var cachedId = id++;
39
-
40
- var currentConfig = __assign(__assign({}, defaultConfig), config);
41
-
42
- if (!container) {
43
- container = document.createElement('div');
44
- container.setAttribute('class', classNames(currentConfig.className, "".concat(prefixCls, "-container")));
45
- document.body.appendChild(container);
46
- }
47
-
48
- if (items.length >= currentConfig.maxCount) {
49
- close(items[0].id);
28
+ function render() {
29
+ renderMessage({
30
+ prefixCls: prefixCls,
31
+ className: currentConfig.className,
32
+ options: options
33
+ });
50
34
  }
51
-
52
- function close(currentId) {
53
- var index = items.findIndex(function (item) {
35
+ /**
36
+ * 关闭指定的一条message
37
+ * @param currentId
38
+ */
39
+ function _onClose(currentId) {
40
+ if (isEmptyArray(options)) {
41
+ return;
42
+ }
43
+ var index = options.findIndex(function (item) {
54
44
  return item.id === currentId;
55
45
  });
56
-
57
46
  if (index >= 0) {
58
- clearTimeout(items[index].timer);
59
- items.splice(index, 1);
60
- } // 关闭需要再渲染一次
61
-
62
-
47
+ clearTimeout(options[index].timer);
48
+ options.splice(index, 1);
49
+ // 关闭需要再渲染一次
50
+ render();
51
+ }
52
+ }
53
+ /**
54
+ * 关闭所有message
55
+ */
56
+ function onCloseAll() {
57
+ if (isEmptyArray(options)) {
58
+ return;
59
+ }
60
+ options.forEach(function (child) {
61
+ clearTimeout(child.timer);
62
+ });
63
+ options = [];
63
64
  render();
64
65
  }
65
-
66
- function _onExited(currentId) {
67
- currentConfig.onDestroy(currentId);
68
- } // 渲染组件
69
-
70
-
71
- function render() {
72
- var cls = prefixCls;
73
- ReactDOM.render( /*#__PURE__*/React.createElement(TransitionGroup, {
74
- component: null
75
- }, items.map(function (item) {
76
- var _a = item.currentConfig,
77
- content = _a.content,
78
- width = _a.width,
79
- height = _a.height,
80
- contentClassName = _a.contentClassName;
81
- var style = {
82
- width: width,
83
- height: height
84
- };
85
- return /*#__PURE__*/React.createElement(CSSTransition, {
86
- key: item.id,
87
- timeout: 300,
88
- classNames: "".concat(cls, "-fade"),
89
- onExited: function onExited() {
90
- _onExited(item.id);
91
- },
92
- appear: true
93
- }, /*#__PURE__*/React.createElement("div", {
94
- className: classNames("".concat(cls, "-content"), contentClassName),
95
- style: style
96
- }, content, /*#__PURE__*/React.createElement("div", {
97
- className: "".concat(cls, "-close"),
98
- onClick: function onClick() {
99
- close(item.id);
100
- }
101
- }, "\xD7")));
102
- })), container);
66
+ /**
67
+ * 超出条数,将删除最旧的那条message
68
+ */
69
+ if (options.length >= currentConfig.maxCount) {
70
+ _onClose(options[0].id);
103
71
  }
104
-
72
+ // 每条message对象
105
73
  var item = {
106
- currentConfig: currentConfig,
74
+ content: props.content,
75
+ contentClassName: props.contentClassName,
107
76
  id: cachedId,
77
+ onDestroy: props.onDestroy,
78
+ onClose: _onClose,
108
79
  timer: null
109
80
  };
110
- items.push(item);
111
- render(); // render后设置自动关闭功能,把定时器绑定到列表
112
-
81
+ // push
82
+ options.push(item);
83
+ // 开始渲染
84
+ render();
85
+ // render后设置自动关闭功能,把定时器绑定到列表
113
86
  item.timer = setTimeout(function () {
114
- close(cachedId);
115
- }, currentConfig.expires);
116
-
117
- function destroy() {
118
- items.forEach(function (child) {
119
- clearTimeout(child.timer);
120
- });
121
- items = [];
122
- render();
123
- }
124
-
125
- return destroy;
126
- }
87
+ _onClose(cachedId);
88
+ }, props.expires || currentConfig.expires);
89
+ return {
90
+ onCloseAll: onCloseAll,
91
+ onClose: function onClose() {
92
+ return _onClose(cachedId);
93
+ }
94
+ };
95
+ }
96
+ Message.setConfig = function (config) {
97
+ currentConfig = __assign(__assign({}, currentConfig), config);
98
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ export interface MessageItem {
3
+ content: React.ReactNode;
4
+ contentClassName?: string;
5
+ id: number;
6
+ onClose?: (id: number) => void;
7
+ onDestroy?: () => void;
8
+ }
9
+ interface TransitionContentProps {
10
+ prefixCls: string;
11
+ options: MessageItem[];
12
+ }
13
+ export interface RenderMessageProps extends TransitionContentProps {
14
+ className?: string;
15
+ }
16
+ export default function renderMessage(props: RenderMessageProps): void;
17
+ export {};