@autobest-ui/components 2.3.0 → 2.5.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 (141) 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 +2 -2
  22. package/esm/index.js +1 -1
  23. package/esm/input-number/ControlArrow.js +0 -2
  24. package/esm/input-number/constants.js +2 -2
  25. package/esm/input-number/index.js +26 -106
  26. package/esm/lazy-image/index.js +10 -55
  27. package/esm/link-list/index.js +11 -35
  28. package/esm/loading/index.js +15 -42
  29. package/esm/loading-container/index.js +3 -6
  30. package/esm/loading-icon/index.js +0 -2
  31. package/esm/mask/index.js +6 -9
  32. package/esm/message/index.d.ts +44 -7
  33. package/esm/message/index.js +96 -111
  34. package/esm/message/renderMessage.d.ts +17 -0
  35. package/esm/message/renderMessage.js +137 -0
  36. package/esm/message/style/index.css +1 -1
  37. package/esm/modal/Title.js +5 -12
  38. package/esm/modal/getPopupLocation.js +5 -7
  39. package/esm/modal/index.js +44 -125
  40. package/esm/move/index.js +32 -132
  41. package/esm/move/range.js +6 -12
  42. package/esm/move/utils.js +3 -10
  43. package/esm/popover/index.js +9 -28
  44. package/esm/portal/index.js +1 -22
  45. package/esm/script/index.js +19 -59
  46. package/esm/select/index.js +28 -106
  47. package/esm/show-more/index.js +40 -103
  48. package/esm/skeleton/Item.js +1 -3
  49. package/esm/skeleton/index.js +5 -11
  50. package/esm/style.css +1 -1
  51. package/esm/table/body/BodyRow.js +11 -28
  52. package/esm/table/body/CheckIcon.js +10 -18
  53. package/esm/table/body/index.js +8 -12
  54. package/esm/table/header/CheckIcon.js +3 -11
  55. package/esm/table/header/HeaderCell.js +12 -33
  56. package/esm/table/header/HeaderRow.js +6 -17
  57. package/esm/table/index.js +30 -100
  58. package/esm/tabs/index.js +35 -118
  59. package/esm/tooltip/index.js +0 -4
  60. package/esm/trigger/align.js +6 -6
  61. package/esm/trigger/bottomAlign.js +33 -45
  62. package/esm/trigger/constants.js +0 -1
  63. package/esm/trigger/getPopupLocation.js +48 -68
  64. package/esm/trigger/index.js +52 -187
  65. package/esm/trigger/leftAlign.js +33 -47
  66. package/esm/trigger/ref.js +2 -7
  67. package/esm/trigger/rightAlign.js +33 -45
  68. package/esm/trigger/topAlign.js +33 -45
  69. package/esm/trigger/utils.js +28 -45
  70. package/lib/accordion/Item.js +6 -27
  71. package/lib/accordion/index.js +8 -41
  72. package/lib/affix/PortalAffix.js +7 -17
  73. package/lib/affix/index.js +30 -75
  74. package/lib/carousel/index.js +45 -146
  75. package/lib/checkbox/index.js +12 -41
  76. package/lib/collapse/index.js +11 -53
  77. package/lib/confirm/index.d.ts +8 -0
  78. package/lib/confirm/index.js +23 -38
  79. package/lib/date-picker/DateEnum.js +0 -3
  80. package/lib/date-picker/calendar/Day.js +62 -87
  81. package/lib/date-picker/calendar/MonthYear.js +20 -62
  82. package/lib/date-picker/calendar/grid/index.js +7 -16
  83. package/lib/date-picker/calendar/index.js +4 -37
  84. package/lib/date-picker/index.js +9 -58
  85. package/lib/date-picker/utils.js +6 -26
  86. package/lib/drawer/Child.js +10 -25
  87. package/lib/drawer/index.js +22 -78
  88. package/lib/ellipsis/index.js +9 -23
  89. package/lib/guide/index.js +25 -71
  90. package/lib/index.d.ts +2 -2
  91. package/lib/index.js +12 -32
  92. package/lib/input-number/ControlArrow.js +0 -4
  93. package/lib/input-number/constants.js +2 -2
  94. package/lib/input-number/index.js +26 -114
  95. package/lib/lazy-image/index.js +10 -58
  96. package/lib/link-list/index.js +11 -40
  97. package/lib/loading/index.js +13 -48
  98. package/lib/loading-bar/index.js +0 -5
  99. package/lib/loading-container/index.js +3 -11
  100. package/lib/loading-icon/index.js +0 -7
  101. package/lib/mask/index.js +6 -17
  102. package/lib/message/index.d.ts +44 -7
  103. package/lib/message/index.js +97 -120
  104. package/lib/message/renderMessage.d.ts +17 -0
  105. package/lib/message/renderMessage.js +144 -0
  106. package/lib/message/style/index.css +1 -1
  107. package/lib/modal/Affix.js +0 -4
  108. package/lib/modal/Title.js +5 -15
  109. package/lib/modal/getPopupLocation.js +5 -9
  110. package/lib/modal/index.js +44 -135
  111. package/lib/move/index.js +32 -144
  112. package/lib/move/range.js +6 -14
  113. package/lib/move/utils.js +3 -12
  114. package/lib/popover/index.js +9 -33
  115. package/lib/portal/index.js +1 -25
  116. package/lib/script/index.js +19 -61
  117. package/lib/select/index.js +28 -113
  118. package/lib/show-more/index.js +40 -110
  119. package/lib/skeleton/Item.js +1 -8
  120. package/lib/skeleton/index.js +5 -16
  121. package/lib/style.css +1 -1
  122. package/lib/table/body/BodyRow.js +11 -33
  123. package/lib/table/body/CheckIcon.js +10 -22
  124. package/lib/table/body/index.js +8 -17
  125. package/lib/table/header/CheckIcon.js +3 -15
  126. package/lib/table/header/HeaderCell.js +12 -37
  127. package/lib/table/header/HeaderRow.js +6 -22
  128. package/lib/table/index.js +30 -107
  129. package/lib/tabs/index.js +35 -122
  130. package/lib/tooltip/index.js +0 -9
  131. package/lib/trigger/align.js +0 -4
  132. package/lib/trigger/bottomAlign.js +33 -48
  133. package/lib/trigger/constants.js +0 -2
  134. package/lib/trigger/getPopupLocation.js +48 -74
  135. package/lib/trigger/index.js +52 -198
  136. package/lib/trigger/leftAlign.js +33 -50
  137. package/lib/trigger/ref.js +2 -12
  138. package/lib/trigger/rightAlign.js +33 -48
  139. package/lib/trigger/topAlign.js +33 -48
  140. package/lib/trigger/utils.js +28 -53
  141. 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));
@@ -1,24 +1,61 @@
1
1
  import React from 'react';
2
+ import { MessageItem } from './renderMessage';
2
3
  export interface MessageProps {
3
4
  /**
4
5
  * 提示文字
5
6
  */
6
- content: React.ReactNode;
7
+ content: React.ReactChild;
7
8
  /**
8
- * class样式名
9
+ * 支持多种样式
9
10
  */
10
- className?: string;
11
11
  contentClassName?: string;
12
12
  /**
13
13
  * 提示文字显示的时间,达到时间后自动关闭
14
14
  */
15
15
  expires?: number;
16
+ /**
17
+ * 销毁后的回调
18
+ */
19
+ onDestroy?: () => void;
20
+ }
21
+ export interface MessageConfig {
22
+ className?: string;
23
+ expires?: number;
16
24
  /**
17
25
  * 最多同时显示的提示文字条数
18
26
  */
19
27
  maxCount?: number;
20
- width?: string;
21
- height?: string;
22
- onDestroy?: (id: number) => void;
23
28
  }
24
- export default function Message(config: MessageProps): () => void;
29
+ export interface MessageResult {
30
+ onClose: () => void;
31
+ onCloseAll: () => void;
32
+ }
33
+ declare type MessageItemWithTimer = MessageItem & {
34
+ timer?: ReturnType<typeof setTimeout>;
35
+ };
36
+ export declare class Message {
37
+ id: number;
38
+ prefixCls: string;
39
+ options: MessageItemWithTimer[];
40
+ config: MessageConfig;
41
+ constructor(config?: MessageConfig & {
42
+ prefixCls?: string;
43
+ });
44
+ private _render;
45
+ /**
46
+ * 关闭指定的一条message
47
+ * @param currentId
48
+ */
49
+ private _onClose;
50
+ /**
51
+ * 关闭所有message
52
+ */
53
+ private _onCloseAll;
54
+ setConfig: (config: MessageConfig) => void;
55
+ open: (props: MessageProps) => {
56
+ onCloseAll: () => void;
57
+ onClose: () => void;
58
+ };
59
+ }
60
+ declare const message: Message;
61
+ export default message;
@@ -2,125 +2,110 @@ 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
- };
29
- var prefixCls = 'ab-message';
30
- var container = null;
31
- var items = [];
32
- var id = 0;
33
- export default function Message(config) {
34
- if (!canUseDOM) {
35
- throw new Error('Message use client!');
36
- }
37
-
38
- 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);
50
- }
51
-
52
- function close(currentId) {
53
- var index = items.findIndex(function (item) {
54
- return item.id === currentId;
55
- });
56
-
57
- if (index >= 0) {
58
- clearTimeout(items[index].timer);
59
- items.splice(index, 1);
60
- } // 关闭需要再渲染一次
61
-
62
-
63
- render();
64
- }
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
13
+ import { canUseDOM, isEmptyArray } from '@autobest-ui/utils';
14
+ import renderMessage from './renderMessage';
15
+ var Message = /** @class */function () {
16
+ function Message(config) {
17
+ if (config === void 0) {
18
+ config = {};
19
+ }
20
+ var _this = this;
21
+ this.id = 0;
22
+ this.options = [];
23
+ this._render = function () {
24
+ renderMessage({
25
+ prefixCls: _this.prefixCls,
26
+ className: _this.config.className,
27
+ options: _this.options
28
+ });
29
+ };
30
+ /**
31
+ * 关闭指定的一条message
32
+ * @param currentId
33
+ */
34
+ this._onClose = function (currentId) {
35
+ if (isEmptyArray(_this.options)) {
36
+ return;
37
+ }
38
+ var index = _this.options.findIndex(function (item) {
39
+ return item.id === currentId;
40
+ });
41
+ if (index >= 0) {
42
+ clearTimeout(_this.options[index].timer);
43
+ _this.options.splice(index, 1);
44
+ // 关闭需要再渲染一次
45
+ _this._render();
46
+ }
47
+ };
48
+ /**
49
+ * 关闭所有message
50
+ */
51
+ this._onCloseAll = function () {
52
+ if (isEmptyArray(_this.options)) {
53
+ return;
54
+ }
55
+ _this.options.forEach(function (child) {
56
+ clearTimeout(child.timer);
57
+ });
58
+ _this.options = [];
59
+ _this._render();
60
+ };
61
+ this.setConfig = function (config) {
62
+ _this.config = __assign({
63
+ expires: 3000,
64
+ maxCount: 3
65
+ }, config);
66
+ };
67
+ this.open = function (props) {
68
+ if (!canUseDOM) {
69
+ throw new Error('Message use client!');
70
+ }
71
+ _this.id++;
72
+ var currentId = _this.id;
73
+ /**
74
+ * 超出条数,将删除最旧的那条message
75
+ */
76
+ if (_this.options.length >= _this.config.maxCount) {
77
+ _this._onClose(_this.options[0].id);
78
+ }
79
+ // 每条message对象
80
+ var item = {
81
+ content: props.content,
82
+ contentClassName: props.contentClassName,
83
+ id: currentId,
84
+ onDestroy: props.onDestroy,
85
+ onClose: _this._onClose,
86
+ timer: null
84
87
  };
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);
88
+ // push
89
+ _this.options.push(item);
90
+ // 开始渲染
91
+ _this._render();
92
+ // render后设置自动关闭功能,把定时器绑定到列表
93
+ item.timer = setTimeout(function () {
94
+ _this._onClose(currentId);
95
+ }, props.expires || _this.config.expires);
96
+ return {
97
+ onCloseAll: _this._onCloseAll,
98
+ onClose: function onClose() {
99
+ return _this._onClose(currentId);
100
100
  }
101
- }, "\xD7")));
102
- })), container);
103
- }
104
-
105
- var item = {
106
- currentConfig: currentConfig,
107
- id: cachedId,
108
- timer: null
109
- };
110
- items.push(item);
111
- render(); // render后设置自动关闭功能,把定时器绑定到列表
112
-
113
- 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();
101
+ };
102
+ };
103
+ this.prefixCls = config.prefixCls || 'ab-message';
104
+ delete config.prefixCls;
105
+ this.setConfig(__assign({}, config));
123
106
  }
124
-
125
- return destroy;
126
- }
107
+ return Message;
108
+ }();
109
+ export { Message };
110
+ var message = new Message();
111
+ export default message;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ export interface MessageItem {
3
+ content: React.ReactChild;
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 {};