1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4 | import classNames from 'classnames';
|
5 | import KeyCode from "rc-util/es/KeyCode";
|
6 | import * as React from 'react';
|
7 | var Notify = React.forwardRef(function (props, ref) {
|
8 | var prefixCls = props.prefixCls,
|
9 | style = props.style,
|
10 | className = props.className,
|
11 | _props$duration = props.duration,
|
12 | duration = _props$duration === void 0 ? 4.5 : _props$duration,
|
13 | eventKey = props.eventKey,
|
14 | content = props.content,
|
15 | closable = props.closable,
|
16 | _props$closeIcon = props.closeIcon,
|
17 | closeIcon = _props$closeIcon === void 0 ? 'x' : _props$closeIcon,
|
18 | divProps = props.props,
|
19 | onClick = props.onClick,
|
20 | onNoticeClose = props.onNoticeClose,
|
21 | times = props.times;
|
22 | var _React$useState = React.useState(false),
|
23 | _React$useState2 = _slicedToArray(_React$useState, 2),
|
24 | hovering = _React$useState2[0],
|
25 | setHovering = _React$useState2[1];
|
26 |
|
27 | var onInternalClose = function onInternalClose() {
|
28 | onNoticeClose(eventKey);
|
29 | };
|
30 | var onCloseKeyDown = function onCloseKeyDown(e) {
|
31 | if (e.key === 'Enter' || e.code === 'Enter' || e.keyCode === KeyCode.ENTER) {
|
32 | onInternalClose();
|
33 | }
|
34 | };
|
35 |
|
36 | React.useEffect(function () {
|
37 | if (!hovering && duration > 0) {
|
38 | var timeout = setTimeout(function () {
|
39 | onInternalClose();
|
40 | }, duration * 1000);
|
41 | return function () {
|
42 | clearTimeout(timeout);
|
43 | };
|
44 | }
|
45 |
|
46 | }, [duration, hovering, times]);
|
47 |
|
48 | var noticePrefixCls = "".concat(prefixCls, "-notice");
|
49 | return React.createElement("div", _extends({}, divProps, {
|
50 | ref: ref,
|
51 | className: classNames(noticePrefixCls, className, _defineProperty({}, "".concat(noticePrefixCls, "-closable"), closable)),
|
52 | style: style,
|
53 | onMouseEnter: function onMouseEnter() {
|
54 | setHovering(true);
|
55 | },
|
56 | onMouseLeave: function onMouseLeave() {
|
57 | setHovering(false);
|
58 | },
|
59 | onClick: onClick
|
60 | }), React.createElement("div", {
|
61 | className: "".concat(noticePrefixCls, "-content")
|
62 | }, content), closable && React.createElement("a", {
|
63 | tabIndex: 0,
|
64 | className: "".concat(noticePrefixCls, "-close"),
|
65 | onKeyDown: onCloseKeyDown,
|
66 | onClick: function onClick(e) {
|
67 | e.preventDefault();
|
68 | e.stopPropagation();
|
69 | onInternalClose();
|
70 | }
|
71 | }, closeIcon));
|
72 | });
|
73 | export default Notify; |
\ | No newline at end of file |