@semcore/notice-bubble 3.1.0 → 3.2.2
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.
- package/CHANGELOG.md +17 -1
- package/lib/cjs/NoticeBubble.js +12 -14
- package/lib/cjs/NoticeBubble.js.map +1 -1
- package/lib/cjs/NoticeBubbleManager.js +11 -26
- package/lib/cjs/NoticeBubbleManager.js.map +1 -1
- package/lib/es6/NoticeBubble.js +12 -14
- package/lib/es6/NoticeBubble.js.map +1 -1
- package/lib/es6/NoticeBubbleManager.js +10 -26
- package/lib/es6/NoticeBubbleManager.js.map +1 -1
- package/lib/types/index.d.ts +1 -7
- package/package.json +2 -4
- package/src/NoticeBubble.js +4 -5
- package/src/NoticeBubbleManager.js +9 -18
- package/src/index.d.ts +1 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
-
## [3.
|
|
5
|
+
## [3.2.2] - 2021-8-26
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Remove `console.log`.
|
|
10
|
+
|
|
11
|
+
## [3.2.1] - 2021-8-26
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Add 'sideEffect=false' for more optimal build via webpack
|
|
16
|
+
|
|
17
|
+
## [3.2.0] - 2021-07-29
|
|
6
18
|
|
|
7
19
|
### Changed
|
|
8
20
|
|
|
9
21
|
- Number of simultaneous notifications can be more than one
|
|
10
22
|
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `visible` property can run in uncontrolled mode
|
|
26
|
+
|
|
11
27
|
## [3.0.0] - 2021-07-05
|
|
12
28
|
|
|
13
29
|
### BREAK
|
package/lib/cjs/NoticeBubble.js
CHANGED
|
@@ -60,18 +60,18 @@ var style = (
|
|
|
60
60
|
/*__reshadow_css_start__*/
|
|
61
61
|
_core.sstyled.insert(
|
|
62
62
|
/*__inner_css_start__*/
|
|
63
|
-
".
|
|
63
|
+
".___SInfo_1t051_gg_,.___SView_1t051_gg_,.___SWarning_1t051_gg_{position:relative;margin-bottom:12px;padding:12px 24px 12px 12px;width:100%;min-height:42px;border-radius:3px;overflow:hidden;box-sizing:border-box}.___SInfo_1t051_gg_{background:#333}.___SWarning_1t051_gg_{background:#ff7f00}.___SMessage_1t051_gg_{font-size:12px;color:#fff;line-height:1.5}.___SDismiss_1t051_gg_{cursor:pointer;position:absolute;right:0;top:0;padding:8px;color:#757575}.___SDismiss_1t051_gg_:hover{color:#ccc}.___SAction_1t051_gg_{margin-top:8px}.___SNoticeBubble_1t051_gg_{width:300px;position:fixed;z-index:1010;right:10px;top:10px}@media (max-width:767px){.___SNoticeBubble_1t051_gg_{width:calc(100% - 20px)}}"
|
|
64
64
|
/*__inner_css_end__*/
|
|
65
65
|
, "1nxod8h_gg_")
|
|
66
66
|
/*__reshadow_css_end__*/
|
|
67
67
|
, {
|
|
68
|
-
"__SInfo": "
|
|
69
|
-
"__SView": "
|
|
70
|
-
"__SWarning": "
|
|
71
|
-
"__SMessage": "
|
|
72
|
-
"__SDismiss": "
|
|
73
|
-
"__SAction": "
|
|
74
|
-
"__SNoticeBubble": "
|
|
68
|
+
"__SInfo": "___SInfo_1t051_gg_",
|
|
69
|
+
"__SView": "___SView_1t051_gg_",
|
|
70
|
+
"__SWarning": "___SWarning_1t051_gg_",
|
|
71
|
+
"__SMessage": "___SMessage_1t051_gg_",
|
|
72
|
+
"__SDismiss": "___SDismiss_1t051_gg_",
|
|
73
|
+
"__SAction": "___SAction_1t051_gg_",
|
|
74
|
+
"__SNoticeBubble": "___SNoticeBubble_1t051_gg_"
|
|
75
75
|
});
|
|
76
76
|
var animationNotice = (
|
|
77
77
|
/*__reshadow_css_start__*/
|
|
@@ -91,14 +91,13 @@ var Notices = function Notices(props) {
|
|
|
91
91
|
_props$data = props.data,
|
|
92
92
|
data = _props$data === void 0 ? [] : _props$data,
|
|
93
93
|
_props$tag = props.tag,
|
|
94
|
-
SView = _props$tag === void 0 ? ViewInfo : _props$tag
|
|
95
|
-
visible = props.visible;
|
|
94
|
+
SView = _props$tag === void 0 ? ViewInfo : _props$tag;
|
|
96
95
|
return data.map(function (notice) {
|
|
97
96
|
var _ref2;
|
|
98
97
|
|
|
99
98
|
return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(_animation.Animation, _ref2.cn("Animation", {
|
|
100
99
|
"key": notice.uid,
|
|
101
|
-
"visible": notice.visible
|
|
100
|
+
"visible": notice.visible === undefined ? true : notice.visible,
|
|
102
101
|
"duration": 250,
|
|
103
102
|
"keyframes": [animationNotice['@enter'], animationNotice['@exit']]
|
|
104
103
|
}), /*#__PURE__*/_react["default"].createElement(SView, _ref2.cn("SView", _objectSpread(_objectSpread({}, notice), {}, {
|
|
@@ -149,7 +148,6 @@ var NoticeBubbleContainerRoot = /*#__PURE__*/function (_Component) {
|
|
|
149
148
|
warnings: warning
|
|
150
149
|
});
|
|
151
150
|
});
|
|
152
|
-
debugger;
|
|
153
151
|
props.manager.counter = 0;
|
|
154
152
|
_this._unsubscribe = props.manager.addListener(_this.handleChange);
|
|
155
153
|
return _this;
|
|
@@ -216,9 +214,9 @@ var ViewInfo = /*#__PURE__*/function (_Component2) {
|
|
|
216
214
|
|
|
217
215
|
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
218
216
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "timer", null);
|
|
219
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "handlerClose", function () {
|
|
217
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "handlerClose", function (e) {
|
|
220
218
|
// because call not only click
|
|
221
|
-
(0, _fire["default"])((0, _assertThisInitialized2["default"])(_this2), 'onClose');
|
|
219
|
+
(0, _fire["default"])((0, _assertThisInitialized2["default"])(_this2), 'onClose', e);
|
|
222
220
|
|
|
223
221
|
_this2.clearTimer();
|
|
224
222
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/NoticeBubble.js"],"names":["animationNotice","sstyled","Notices","props","styles","data","tag","SView","ViewInfo","visible","map","notice","uid","NoticeBubbleContainerRoot","notices","warnings","_unsubscribe","info","filter","type","warning","setState","manager","counter","addListener","handleChange","SNoticeBubble","Box","asProps","Children","disablePortal","state","ViewWarning","Component","style","clearTimer","timer","pause","resume","duration","Timer","handlerClose","clear","SInfo","SMessage","SAction","SDismiss","actionNode","action","forwardRef","onMouseEnter","onMouseLeave","children","other","handlerMouseEnter","handlerMouseLeave","SWarning","NoticeBubbleView","_notice","add","remove","update","NoticeBubbleWarningView","NoticeBubbleContainer","Info","Warning","NoticeBubble","NoticeBubbleWarning"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAMA,eAAe;AAAA;AAAGC,oBAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAArB;;AAoBA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,KAAD,EAAW;AAAA,MACjBC,MADiB,GACqCD,KADrC,CACjBC,MADiB;AAAA,oBACqCD,KADrC,CACTE,IADS;AAAA,MACTA,IADS,4BACF,EADE;AAAA,mBACqCF,KADrC,CACEG,GADF;AAAA,MACOC,KADP,2BACeC,QADf;AAAA,MACyBC,OADzB,GACqCN,KADrC,CACyBM,OADzB;AAGzB,SAAOJ,IAAI,CAACK,GAAL,CAAS,UAACC,MAAD,EAAY;AAAA;;AAC1B,mBAAO,mBAAQP,MAAR,CAAP,eACE,gCAAC,oBAAD;AAAA,aACOO,MAAM,CAACC,GADd;AAAA,iBAEWD,MAAM,CAACF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,gBADiE;AAEvEQ,EAAAA,OAAO,EAAEH;AAF8D,CAA3C,CAA9B;AAKA,IAAMI,YAAY,GAAGH,qBAAqB,CAACC,IAA3C;;AACA,IAAMG,mBAAmB,GAAGJ,qBAAqB,CAACE,OAAlD;;eAIeF,qB","sourcesContent":["import React from 'react';\nimport Portal from '@semcore/portal';\nimport manager from './NoticeBubbleManager';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport { Animation } from '@semcore/animation';\nimport { Box } from '@semcore/flex-box';\nimport fire from '@semcore/utils/lib/fire';\nimport isNode from '@semcore/utils/lib/isNode';\nimport { callAllEventHandlers } from '@semcore/utils/lib/assignProps';\nimport CloseXS from '@semcore/icon/lib/Close/xs';\nimport { Timer } from './utils';\n\nimport style from './style/notice-bubble.shadow.css';\n\nconst animationNotice = sstyled.css`\n @keyframes enter {\n from {\n transform: translate(100%, 0);\n }\n to {\n transform: translate(0, 0);\n }\n }\n\n @keyframes exit {\n from {\n opacity: 1;\n }\n to {\n opacity: 0;\n }\n }\n`;\n\nconst Notices = (props) => {\n const { styles, data = [], tag: SView = ViewInfo, visible } = props;\n\n return data.map((notice) => {\n return sstyled(styles)(\n <Animation\n key={notice.uid}\n visible={notice.visible || visible}\n duration={250}\n keyframes={[animationNotice['@enter'], animationNotice['@exit']]}\n >\n <SView {...notice} styles={notice.styles || styles} />\n </Animation>,\n );\n });\n};\n\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * ```\n *\n * Container is a portal (React.Portal) in the body, inserted once into any part of the application\n * and subscribes to manager updates(NoticeBubbleManager)\n * */\n\nclass NoticeBubbleContainerRoot extends Component {\n static displayName = 'NoticeBubbleContainer';\n static style = style;\n static defaultProps = {\n manager,\n };\n\n _unsubscribe = null;\n\n state = {\n notices: [],\n warnings: [],\n };\n\n constructor(props) {\n super(props);\n debugger;\n props.manager.counter = 0;\n this._unsubscribe = props.manager.addListener(this.handleChange);\n }\n\n componentWillUnmount = () => {\n if (this._unsubscribe) {\n this._unsubscribe();\n }\n };\n\n handleChange = (notices) => {\n const info = notices.filter((notice) => notice.type === 'info');\n const warning = notices.filter((notice) => notice.type === 'warning');\n\n this.setState({ notices: info, warnings: warning });\n };\n\n render() {\n const SNoticeBubble = Root;\n const { Children, styles, disablePortal } = this.asProps;\n const { notices, warnings } = this.state;\n\n return sstyled(styles)(\n <Portal disablePortal={disablePortal}>\n <SNoticeBubble render={Box}>\n <Children />\n <Notices styles={styles} data={warnings} tag={ViewWarning} />\n <Notices styles={styles} data={notices} tag={ViewInfo} />\n </SNoticeBubble>\n </Portal>,\n );\n }\n}\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * <NoticeBubble.Info/>\n * ```\n *\n * View component, the appearance of the notice\n * */\nclass ViewInfo extends Component {\n timer = null;\n\n componentDidMount() {\n const { duration } = this.props;\n if (duration) {\n this.timer = new Timer(this.handlerClose, duration);\n }\n }\n\n componentWillUnmount() {\n this.clearTimer();\n }\n\n clearTimer() {\n if (this.timer) {\n this.timer.clear();\n this.timer = null;\n }\n }\n\n handlerClose = () => {\n // because call not only click\n fire(this, 'onClose');\n this.clearTimer();\n };\n\n handlerMouseEnter = () => {\n if (this.timer) {\n this.timer.pause();\n }\n };\n\n handlerMouseLeave = () => {\n if (this.timer) {\n this.timer.resume();\n }\n };\n\n render() {\n const SInfo = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const SDismiss = 'div';\n const {\n action: actionNode,\n forwardRef,\n styles,\n onMouseEnter,\n onMouseLeave,\n children,\n ...other\n } = this.props;\n\n return sstyled(styles)(\n <SInfo\n role=\"alert\"\n {...other}\n ref={forwardRef}\n onMouseEnter={callAllEventHandlers(onMouseEnter, this.handlerMouseEnter)}\n onMouseLeave={callAllEventHandlers(onMouseLeave, this.handlerMouseLeave)}\n >\n <SDismiss title=\"Close\" onClick={this.handlerClose} aria-label=\"Close alert\">\n <CloseXS />\n </SDismiss>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SInfo>,\n );\n }\n}\n\nclass ViewWarning extends ViewInfo {\n static defaultProps = {\n type: 'warning',\n duration: 0,\n };\n\n render() {\n const SWarning = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const { action: actionNode, children, styles, forwardRef, ...other } = this.props;\n\n return sstyled(styles)(\n <SWarning ref={forwardRef} role=\"alert\" {...other}>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SWarning>,\n );\n }\n}\n\nclass NoticeBubbleView extends Component {\n static defaultProps = {\n duration: 5000,\n type: 'info',\n manager,\n };\n\n _notice = null;\n\n componentDidMount() {\n this._notice = this.asProps.manager.add(this.asProps);\n }\n\n componentWillUnmount() {\n if (this._notice) {\n this._notice.remove();\n }\n }\n\n componentDidUpdate() {\n if (this._notice) {\n this._notice.update(this.asProps);\n }\n }\n\n render() {\n return null;\n }\n}\n\nclass NoticeBubbleWarningView extends NoticeBubbleView {\n static defaultProps = {\n duration: 5000,\n type: 'warning',\n manager,\n };\n}\n\nconst NoticeBubbleContainer = createComponent(NoticeBubbleContainerRoot, {\n Info: NoticeBubbleView,\n Warning: NoticeBubbleWarningView,\n});\n\nconst NoticeBubble = NoticeBubbleContainer.Info;\nconst NoticeBubbleWarning = NoticeBubbleContainer.Warning;\n\nexport { NoticeBubble, NoticeBubbleWarning };\n\nexport default NoticeBubbleContainer;\n"],"file":"NoticeBubble.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/NoticeBubble.js"],"names":["animationNotice","sstyled","Notices","props","styles","data","tag","SView","ViewInfo","map","notice","uid","visible","undefined","NoticeBubbleContainerRoot","notices","warnings","_unsubscribe","info","filter","type","warning","setState","manager","counter","addListener","handleChange","SNoticeBubble","Box","asProps","Children","disablePortal","state","ViewWarning","Component","style","e","clearTimer","timer","pause","resume","duration","Timer","handlerClose","clear","SInfo","SMessage","SAction","SDismiss","actionNode","action","forwardRef","onMouseEnter","onMouseLeave","children","other","handlerMouseEnter","handlerMouseLeave","SWarning","NoticeBubbleView","_notice","add","remove","update","NoticeBubbleWarningView","NoticeBubbleContainer","Info","Warning","NoticeBubble","NoticeBubbleWarning"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAMA,eAAe;AAAA;AAAGC,oBAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAArB;;AAoBA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,KAAD,EAAW;AAAA,MACjBC,MADiB,GAC4BD,KAD5B,CACjBC,MADiB;AAAA,oBAC4BD,KAD5B,CACTE,IADS;AAAA,MACTA,IADS,4BACF,EADE;AAAA,mBAC4BF,KAD5B,CACEG,GADF;AAAA,MACOC,KADP,2BACeC,QADf;AAGzB,SAAOH,IAAI,CAACI,GAAL,CAAS,UAACC,MAAD,EAAY;AAAA;;AAC1B,mBAAO,mBAAQN,MAAR,CAAP,eACE,gCAAC,oBAAD;AAAA,aACOM,MAAM,CAACC,GADd;AAAA,iBAEWD,MAAM,CAACE,OAAP,KAAmBC,SAAnB,GAA+B,IAA/B,GAAsCH,MAAM,CAACE,OAFxD;AAAA,kBAGY,GAHZ;AAAA,mBAIa,CAACZ,eAAe,CAAC,QAAD,CAAhB,EAA4BA,eAAe,CAAC,OAAD,CAA3C;AAJb,qBAME,gCAAC,KAAD,oDAAWU,MAAX;AAAA,gBAA2BA,MAAM,CAACN,MAAP,IAAiBA;AAA5C,QANF,CADF;AAUD,GAXM,CAAP;AAYD,CAfD;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;IAEMU,yB;;;;;AAcJ,qCAAYX,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,qGAPJ,IAOI;AAAA,8FALX;AACNY,MAAAA,OAAO,EAA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,QAAQ,EAAE;AAFU,C;;IAoBlBkB,gB;;;;;;;;;;;;;;;iGAOM,I;;;;;;WAEV,6BAAoB;AAClB,WAAKC,OAAL,GAAe,KAAK/B,OAAL,CAAaN,OAAb,CAAqBsC,GAArB,CAAyB,KAAKhC,OAA9B,CAAf;AACD;;;WAED,gCAAuB;AACrB,UAAI,KAAK+B,OAAT,EAAkB;AAChB,aAAKA,OAAL,CAAaE,MAAb;AACD;AACF;;;WAED,8BAAqB;AACnB,UAAI,KAAKF,OAAT,EAAkB;AAChB,aAAKA,OAAL,CAAaG,MAAb,CAAoB,KAAKlC,OAAzB;AACD;AACF;;;WAED,kBAAS;AACP,aAAO,IAAP;AACD;;;EA3B4BK,e;;iCAAzByB,gB,kBACkB;AACpBlB,EAAAA,QAAQ,EAAE,IADU;AAEpBrB,EAAAA,IAAI,EAAE,MAFc;AAGpBG,EAAAA,OAAO,EAAPA;AAHoB,C;;IA6BlByC,uB;;;;;;;;;;;EAAgCL,gB;;iCAAhCK,uB,kBACkB;AACpBvB,EAAAA,QAAQ,EAAE,IADU;AAEpBrB,EAAAA,IAAI,EAAE,SAFc;AAGpBG,EAAAA,OAAO,EAAPA;AAHoB,C;AAOxB,IAAM0C,qBAAqB,GAAG,sBAAgBnD,yBAAhB,EAA2C;AACvEoD,EAAAA,IAAI,EAAEP,gBADiE;AAEvEQ,EAAAA,OAAO,EAAEH;AAF8D,CAA3C,CAA9B;AAKA,IAAMI,YAAY,GAAGH,qBAAqB,CAACC,IAA3C;;AACA,IAAMG,mBAAmB,GAAGJ,qBAAqB,CAACE,OAAlD;;eAIeF,qB","sourcesContent":["import React from 'react';\nimport Portal from '@semcore/portal';\nimport manager from './NoticeBubbleManager';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport { Animation } from '@semcore/animation';\nimport { Box } from '@semcore/flex-box';\nimport fire from '@semcore/utils/lib/fire';\nimport isNode from '@semcore/utils/lib/isNode';\nimport { callAllEventHandlers } from '@semcore/utils/lib/assignProps';\nimport CloseXS from '@semcore/icon/lib/Close/xs';\nimport { Timer } from './utils';\n\nimport style from './style/notice-bubble.shadow.css';\n\nconst animationNotice = sstyled.css`\n @keyframes enter {\n from {\n transform: translate(100%, 0);\n }\n to {\n transform: translate(0, 0);\n }\n }\n\n @keyframes exit {\n from {\n opacity: 1;\n }\n to {\n opacity: 0;\n }\n }\n`;\n\nconst Notices = (props) => {\n const { styles, data = [], tag: SView = ViewInfo } = props;\n\n return data.map((notice) => {\n return sstyled(styles)(\n <Animation\n key={notice.uid}\n visible={notice.visible === undefined ? true : notice.visible}\n duration={250}\n keyframes={[animationNotice['@enter'], animationNotice['@exit']]}\n >\n <SView {...notice} styles={notice.styles || styles} />\n </Animation>,\n );\n });\n};\n\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * ```\n *\n * Container is a portal (React.Portal) in the body, inserted once into any part of the application\n * and subscribes to manager updates(NoticeBubbleManager)\n * */\n\nclass NoticeBubbleContainerRoot extends Component {\n static displayName = 'NoticeBubbleContainer';\n static style = style;\n static defaultProps = {\n manager,\n };\n\n _unsubscribe = null;\n\n state = {\n notices: [],\n warnings: [],\n };\n\n constructor(props) {\n super(props);\n props.manager.counter = 0;\n this._unsubscribe = props.manager.addListener(this.handleChange);\n }\n\n componentWillUnmount = () => {\n if (this._unsubscribe) {\n this._unsubscribe();\n }\n };\n\n handleChange = (notices) => {\n const info = notices.filter((notice) => notice.type === 'info');\n const warning = notices.filter((notice) => notice.type === 'warning');\n\n this.setState({ notices: info, warnings: warning });\n };\n\n render() {\n const SNoticeBubble = Root;\n const { Children, styles, disablePortal } = this.asProps;\n const { notices, warnings } = this.state;\n\n return sstyled(styles)(\n <Portal disablePortal={disablePortal}>\n <SNoticeBubble render={Box}>\n <Children />\n <Notices styles={styles} data={warnings} tag={ViewWarning} />\n <Notices styles={styles} data={notices} tag={ViewInfo} />\n </SNoticeBubble>\n </Portal>,\n );\n }\n}\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * <NoticeBubble.Info/>\n * ```\n *\n * View component, the appearance of the notice\n * */\nclass ViewInfo extends Component {\n timer = null;\n\n componentDidMount() {\n const { duration } = this.props;\n if (duration) {\n this.timer = new Timer(this.handlerClose, duration);\n }\n }\n\n componentWillUnmount() {\n this.clearTimer();\n }\n\n clearTimer() {\n if (this.timer) {\n this.timer.clear();\n this.timer = null;\n }\n }\n\n handlerClose = (e) => {\n // because call not only click\n fire(this, 'onClose', e);\n this.clearTimer();\n };\n\n handlerMouseEnter = () => {\n if (this.timer) {\n this.timer.pause();\n }\n };\n\n handlerMouseLeave = () => {\n if (this.timer) {\n this.timer.resume();\n }\n };\n\n render() {\n const SInfo = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const SDismiss = 'div';\n const {\n action: actionNode,\n forwardRef,\n styles,\n onMouseEnter,\n onMouseLeave,\n children,\n ...other\n } = this.props;\n\n return sstyled(styles)(\n <SInfo\n role=\"alert\"\n {...other}\n ref={forwardRef}\n onMouseEnter={callAllEventHandlers(onMouseEnter, this.handlerMouseEnter)}\n onMouseLeave={callAllEventHandlers(onMouseLeave, this.handlerMouseLeave)}\n >\n <SDismiss title=\"Close\" onClick={this.handlerClose} aria-label=\"Close alert\">\n <CloseXS />\n </SDismiss>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SInfo>,\n );\n }\n}\n\nclass ViewWarning extends ViewInfo {\n static defaultProps = {\n type: 'warning',\n duration: 0,\n };\n\n render() {\n const SWarning = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const { action: actionNode, children, styles, forwardRef, ...other } = this.props;\n\n return sstyled(styles)(\n <SWarning ref={forwardRef} role=\"alert\" {...other}>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SWarning>,\n );\n }\n}\n\nclass NoticeBubbleView extends Component {\n static defaultProps = {\n duration: 5000,\n type: 'info',\n manager,\n };\n\n _notice = null;\n\n componentDidMount() {\n this._notice = this.asProps.manager.add(this.asProps);\n }\n\n componentWillUnmount() {\n if (this._notice) {\n this._notice.remove();\n }\n }\n\n componentDidUpdate() {\n if (this._notice) {\n this._notice.update(this.asProps);\n }\n }\n\n render() {\n return null;\n }\n}\n\nclass NoticeBubbleWarningView extends NoticeBubbleView {\n static defaultProps = {\n duration: 5000,\n type: 'warning',\n manager,\n };\n}\n\nconst NoticeBubbleContainer = createComponent(NoticeBubbleContainerRoot, {\n Info: NoticeBubbleView,\n Warning: NoticeBubbleWarningView,\n});\n\nconst NoticeBubble = NoticeBubbleContainer.Info;\nconst NoticeBubbleWarning = NoticeBubbleContainer.Warning;\n\nexport { NoticeBubble, NoticeBubbleWarning };\n\nexport default NoticeBubbleContainer;\n"],"file":"NoticeBubble.js"}
|
|
@@ -15,6 +15,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
15
15
|
|
|
16
16
|
var _eventEmitter = _interopRequireDefault(require("@semcore/utils/lib/eventEmitter"));
|
|
17
17
|
|
|
18
|
+
var _assignProps = require("@semcore/utils/lib/assignProps");
|
|
19
|
+
|
|
18
20
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
19
21
|
|
|
20
22
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -39,45 +41,28 @@ var NoticeBubbleManager = /*#__PURE__*/function () {
|
|
|
39
41
|
key: "createItem",
|
|
40
42
|
value: function createItem(props) {
|
|
41
43
|
var manager = this;
|
|
42
|
-
this.counter++;
|
|
43
44
|
return _objectSpread(_objectSpread({
|
|
44
|
-
uid: this.counter,
|
|
45
45
|
type: 'info'
|
|
46
46
|
}, props), {}, {
|
|
47
|
-
onClose: function
|
|
48
|
-
if (props.
|
|
49
|
-
|
|
50
|
-
args[_key] = arguments[_key];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
props.onClose.apply(this, args);
|
|
47
|
+
onClose: (0, _assignProps.callAllEventHandlers)(props.onClose, function () {
|
|
48
|
+
if (props.visible === undefined) {
|
|
49
|
+
manager.remove(props.uid);
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
if (this.props.visible === undefined) {
|
|
57
|
-
manager.remove(this.props.uid);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
51
|
+
})
|
|
60
52
|
});
|
|
61
53
|
}
|
|
62
54
|
}, {
|
|
63
55
|
key: "emit",
|
|
64
56
|
value: function emit() {
|
|
65
|
-
|
|
66
|
-
if (item.visible === undefined) {
|
|
67
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
68
|
-
visible: true
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return item;
|
|
73
|
-
});
|
|
74
|
-
this.emitter.emit(EVENT_NAME, list);
|
|
57
|
+
this.emitter.emit(EVENT_NAME, this.items);
|
|
75
58
|
}
|
|
76
59
|
}, {
|
|
77
60
|
key: "add",
|
|
78
61
|
value: function add(props) {
|
|
79
|
-
var
|
|
80
|
-
var
|
|
62
|
+
var uid = this.counter++;
|
|
63
|
+
var item = this.createItem(_objectSpread({
|
|
64
|
+
uid: uid
|
|
65
|
+
}, props));
|
|
81
66
|
this.items.push(item);
|
|
82
67
|
this.emit();
|
|
83
68
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/NoticeBubbleManager.js"],"names":["EVENT_NAME","NoticeBubbleManager","emitter","EventEmitter","fn","subscribe","props","manager","
|
|
1
|
+
{"version":3,"sources":["../../src/NoticeBubbleManager.js"],"names":["EVENT_NAME","NoticeBubbleManager","emitter","EventEmitter","fn","subscribe","props","manager","type","onClose","visible","undefined","remove","uid","emit","items","counter","item","createItem","push","update","bind","index","findIndex","splice"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;;;;;AAEA,IAAMA,UAAU,GAAG,QAAnB;;IAEMC,mB;AAKJ,iCAAc;AAAA;AAAA,oDAJN,EAIM;AAAA,sDAHJ,IAGI;AAAA,sDAFJ,CAEI;AACZ,SAAKC,OAAL,GAAe,IAAIC,wBAAJ,EAAf;AACD;;;;WAED,qBAAYC,EAAZ,EAAgB;AACd,aAAO,KAAKF,OAAL,CAAaG,SAAb,CAAuBL,UAAvB,EAAmCI,EAAnC,CAAP;AACD;;;WAED,oBAAWE,KAAX,EAAkB;AAChB,UAAMC,OAAO,GAAG,IAAhB;AAEA;AACEC,QAAAA,IAAI,EAAE;AADR,SAEKF,KAFL;AAGEG,QAAAA,OAAO,EAAE,uCAAqBH,KAAK,CAACG,OAA3B,EAAoC,YAAM;AACjD,cAAIH,KAAK,CAACI,OAAN,KAAkBC,SAAtB,EAAiC;AAC/BJ,YAAAA,OAAO,CAACK,MAAR,CAAeN,KAAK,CAACO,GAArB;AACD;AACF,SAJQ;AAHX;AASD;;;WAED,gBAAO;AACL,WAAKX,OAAL,CAAaY,IAAb,CAAkBd,UAAlB,EAA8B,KAAKe,KAAnC;AACD;;;WAED,aAAIT,KAAJ,EAAW;AACT,UAAMO,GAAG,GAAG,KAAKG,OAAL,EAAZ;AACA,UAAMC,IAAI,GAAG,KAAKC,UAAL;AAAkBL,QAAAA,GAAG,EAAHA;AAAlB,SAA0BP,KAA1B,EAAb;AACA,WAAKS,KAAL,CAAWI,IAAX,CAAgBF,IAAhB;AACA,WAAKH,IAAL;AACA,aAAO;AACLD,QAAAA,GAAG,EAAHA,GADK;AAELO,QAAAA,MAAM,EAAE,KAAKA,MAAL,CAAYC,IAAZ,CAAiB,IAAjB,EAAuBR,GAAvB,CAFH;AAGLD,QAAAA,MAAM,EAAE,KAAKA,MAAL,CAAYS,IAAZ,CAAiB,IAAjB,EAAuBR,GAAvB;AAHH,OAAP;AAKD;;;WAED,gBAAOA,GAAP,EAAYP,KAAZ,EAAmB;AACjB,UAAMgB,KAAK,GAAG,KAAKP,KAAL,CAAWQ,SAAX,CAAqB,UAACN,IAAD;AAAA,eAAUA,IAAI,CAACJ,GAAL,KAAaA,GAAvB;AAAA,OAArB,CAAd;;AACA,UAAIS,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,aAAKP,KAAL,CAAWO,KAAX,IAAoB,KAAKJ,UAAL,iCACf,KAAKH,KAAL,CAAWO,KAAX,CADe,GAEfhB,KAFe,EAApB;AAIA,aAAKQ,IAAL;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD;;;WAED,gBAAOD,GAAP,EAAY;AACV,UAAMS,KAAK,GAAG,KAAKP,KAAL,CAAWQ,SAAX,CAAqB,UAACN,IAAD;AAAA,eAAUA,IAAI,CAACJ,GAAL,KAAaA,GAAvB;AAAA,OAArB,CAAd;;AACA,UAAIS,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,aAAKP,KAAL,CAAWS,MAAX,CAAkBF,KAAlB,EAAyB,CAAzB;AACA,aAAKR,IAAL;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD;;;;;;;eAIY,IAAIb,mBAAJ,E","sourcesContent":["import EventEmitter from '@semcore/utils/lib/eventEmitter';\nimport { callAllEventHandlers } from '@semcore/utils/lib/assignProps';\n\nconst EVENT_NAME = 'CHANGE';\n\nclass NoticeBubbleManager {\n items = [];\n emitter = null;\n counter = 0;\n\n constructor() {\n this.emitter = new EventEmitter();\n }\n\n addListener(fn) {\n return this.emitter.subscribe(EVENT_NAME, fn);\n }\n\n createItem(props) {\n const manager = this;\n\n return {\n type: 'info',\n ...props,\n onClose: callAllEventHandlers(props.onClose, () => {\n if (props.visible === undefined) {\n manager.remove(props.uid);\n }\n }),\n };\n }\n\n emit() {\n this.emitter.emit(EVENT_NAME, this.items);\n }\n\n add(props) {\n const uid = this.counter++;\n const item = this.createItem({ uid, ...props });\n this.items.push(item);\n this.emit();\n return {\n uid,\n update: this.update.bind(this, uid),\n remove: this.remove.bind(this, uid),\n };\n }\n\n update(uid, props) {\n const index = this.items.findIndex((item) => item.uid === uid);\n if (index !== -1) {\n this.items[index] = this.createItem({\n ...this.items[index],\n ...props,\n });\n this.emit();\n return true;\n }\n return false;\n }\n\n remove(uid) {\n const index = this.items.findIndex((item) => item.uid === uid);\n if (index !== -1) {\n this.items.splice(index, 1);\n this.emit();\n return true;\n }\n return false;\n }\n}\n\nexport { NoticeBubbleManager };\nexport default new NoticeBubbleManager();\n"],"file":"NoticeBubbleManager.js"}
|
package/lib/es6/NoticeBubble.js
CHANGED
|
@@ -34,18 +34,18 @@ var style = (
|
|
|
34
34
|
/*__reshadow_css_start__*/
|
|
35
35
|
_sstyled.insert(
|
|
36
36
|
/*__inner_css_start__*/
|
|
37
|
-
".
|
|
37
|
+
".___SInfo_1t051_gg_,.___SView_1t051_gg_,.___SWarning_1t051_gg_{position:relative;margin-bottom:12px;padding:12px 24px 12px 12px;width:100%;min-height:42px;border-radius:3px;overflow:hidden;box-sizing:border-box}.___SInfo_1t051_gg_{background:#333}.___SWarning_1t051_gg_{background:#ff7f00}.___SMessage_1t051_gg_{font-size:12px;color:#fff;line-height:1.5}.___SDismiss_1t051_gg_{cursor:pointer;position:absolute;right:0;top:0;padding:8px;color:#757575}.___SDismiss_1t051_gg_:hover{color:#ccc}.___SAction_1t051_gg_{margin-top:8px}.___SNoticeBubble_1t051_gg_{width:300px;position:fixed;z-index:1010;right:10px;top:10px}@media (max-width:767px){.___SNoticeBubble_1t051_gg_{width:calc(100% - 20px)}}"
|
|
38
38
|
/*__inner_css_end__*/
|
|
39
39
|
, "1nxod8h_gg_")
|
|
40
40
|
/*__reshadow_css_end__*/
|
|
41
41
|
, {
|
|
42
|
-
"__SInfo": "
|
|
43
|
-
"__SView": "
|
|
44
|
-
"__SWarning": "
|
|
45
|
-
"__SMessage": "
|
|
46
|
-
"__SDismiss": "
|
|
47
|
-
"__SAction": "
|
|
48
|
-
"__SNoticeBubble": "
|
|
42
|
+
"__SInfo": "___SInfo_1t051_gg_",
|
|
43
|
+
"__SView": "___SView_1t051_gg_",
|
|
44
|
+
"__SWarning": "___SWarning_1t051_gg_",
|
|
45
|
+
"__SMessage": "___SMessage_1t051_gg_",
|
|
46
|
+
"__SDismiss": "___SDismiss_1t051_gg_",
|
|
47
|
+
"__SAction": "___SAction_1t051_gg_",
|
|
48
|
+
"__SNoticeBubble": "___SNoticeBubble_1t051_gg_"
|
|
49
49
|
});
|
|
50
50
|
var animationNotice = (
|
|
51
51
|
/*__reshadow_css_start__*/
|
|
@@ -65,14 +65,13 @@ var Notices = function Notices(props) {
|
|
|
65
65
|
_props$data = props.data,
|
|
66
66
|
data = _props$data === void 0 ? [] : _props$data,
|
|
67
67
|
_props$tag = props.tag,
|
|
68
|
-
SView = _props$tag === void 0 ? ViewInfo : _props$tag
|
|
69
|
-
visible = props.visible;
|
|
68
|
+
SView = _props$tag === void 0 ? ViewInfo : _props$tag;
|
|
70
69
|
return data.map(function (notice) {
|
|
71
70
|
var _ref2;
|
|
72
71
|
|
|
73
72
|
return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(Animation, _ref2.cn("Animation", {
|
|
74
73
|
"key": notice.uid,
|
|
75
|
-
"visible": notice.visible
|
|
74
|
+
"visible": notice.visible === undefined ? true : notice.visible,
|
|
76
75
|
"duration": 250,
|
|
77
76
|
"keyframes": [animationNotice['@enter'], animationNotice['@exit']]
|
|
78
77
|
}), /*#__PURE__*/React.createElement(SView, _ref2.cn("SView", _objectSpread(_objectSpread({}, notice), {}, {
|
|
@@ -129,7 +128,6 @@ var NoticeBubbleContainerRoot = /*#__PURE__*/function (_Component) {
|
|
|
129
128
|
});
|
|
130
129
|
});
|
|
131
130
|
|
|
132
|
-
debugger;
|
|
133
131
|
props.manager.counter = 0;
|
|
134
132
|
_this._unsubscribe = props.manager.addListener(_this.handleChange);
|
|
135
133
|
return _this;
|
|
@@ -201,9 +199,9 @@ var ViewInfo = /*#__PURE__*/function (_Component2) {
|
|
|
201
199
|
|
|
202
200
|
_defineProperty(_assertThisInitialized(_this2), "timer", null);
|
|
203
201
|
|
|
204
|
-
_defineProperty(_assertThisInitialized(_this2), "handlerClose", function () {
|
|
202
|
+
_defineProperty(_assertThisInitialized(_this2), "handlerClose", function (e) {
|
|
205
203
|
// because call not only click
|
|
206
|
-
fire(_assertThisInitialized(_this2), 'onClose');
|
|
204
|
+
fire(_assertThisInitialized(_this2), 'onClose', e);
|
|
207
205
|
|
|
208
206
|
_this2.clearTimer();
|
|
209
207
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/NoticeBubble.js"],"names":["React","Portal","manager","createComponent","Component","sstyled","Root","Animation","Box","fire","isNode","callAllEventHandlers","CloseXS","Timer","animationNotice","Notices","props","styles","data","tag","SView","ViewInfo","visible","map","notice","uid","NoticeBubbleContainerRoot","notices","warnings","_unsubscribe","info","filter","type","warning","setState","counter","addListener","handleChange","SNoticeBubble","asProps","Children","disablePortal","state","ViewWarning","style","clearTimer","timer","pause","resume","duration","handlerClose","clear","SInfo","SMessage","SAction","SDismiss","actionNode","action","forwardRef","onMouseEnter","onMouseLeave","children","other","handlerMouseEnter","handlerMouseLeave","SWarning","NoticeBubbleView","_notice","add","remove","update","NoticeBubbleWarningView","NoticeBubbleContainer","Info","Warning","NoticeBubble","NoticeBubbleWarning"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,OAAOC,OAAP,MAAoB,uBAApB;AACA,OAAOC,e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from '@semcore/portal';\nimport manager from './NoticeBubbleManager';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport { Animation } from '@semcore/animation';\nimport { Box } from '@semcore/flex-box';\nimport fire from '@semcore/utils/lib/fire';\nimport isNode from '@semcore/utils/lib/isNode';\nimport { callAllEventHandlers } from '@semcore/utils/lib/assignProps';\nimport CloseXS from '@semcore/icon/lib/Close/xs';\nimport { Timer } from './utils';\n\nimport style from './style/notice-bubble.shadow.css';\n\nconst animationNotice = sstyled.css`\n @keyframes enter {\n from {\n transform: translate(100%, 0);\n }\n to {\n transform: translate(0, 0);\n }\n }\n\n @keyframes exit {\n from {\n opacity: 1;\n }\n to {\n opacity: 0;\n }\n }\n`;\n\nconst Notices = (props) => {\n const { styles, data = [], tag: SView = ViewInfo, visible } = props;\n\n return data.map((notice) => {\n return sstyled(styles)(\n <Animation\n key={notice.uid}\n visible={notice.visible || visible}\n duration={250}\n keyframes={[animationNotice['@enter'], animationNotice['@exit']]}\n >\n <SView {...notice} styles={notice.styles || styles} />\n </Animation>,\n );\n });\n};\n\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * ```\n *\n * Container is a portal (React.Portal) in the body, inserted once into any part of the application\n * and subscribes to manager updates(NoticeBubbleManager)\n * */\n\nclass NoticeBubbleContainerRoot extends Component {\n static displayName = 'NoticeBubbleContainer';\n static style = style;\n static defaultProps = {\n manager,\n };\n\n _unsubscribe = null;\n\n state = {\n notices: [],\n warnings: [],\n };\n\n constructor(props) {\n super(props);\n debugger;\n props.manager.counter = 0;\n this._unsubscribe = props.manager.addListener(this.handleChange);\n }\n\n componentWillUnmount = () => {\n if (this._unsubscribe) {\n this._unsubscribe();\n }\n };\n\n handleChange = (notices) => {\n const info = notices.filter((notice) => notice.type === 'info');\n const warning = notices.filter((notice) => notice.type === 'warning');\n\n this.setState({ notices: info, warnings: warning });\n };\n\n render() {\n const SNoticeBubble = Root;\n const { Children, styles, disablePortal } = this.asProps;\n const { notices, warnings } = this.state;\n\n return sstyled(styles)(\n <Portal disablePortal={disablePortal}>\n <SNoticeBubble render={Box}>\n <Children />\n <Notices styles={styles} data={warnings} tag={ViewWarning} />\n <Notices styles={styles} data={notices} tag={ViewInfo} />\n </SNoticeBubble>\n </Portal>,\n );\n }\n}\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * <NoticeBubble.Info/>\n * ```\n *\n * View component, the appearance of the notice\n * */\nclass ViewInfo extends Component {\n timer = null;\n\n componentDidMount() {\n const { duration } = this.props;\n if (duration) {\n this.timer = new Timer(this.handlerClose, duration);\n }\n }\n\n componentWillUnmount() {\n this.clearTimer();\n }\n\n clearTimer() {\n if (this.timer) {\n this.timer.clear();\n this.timer = null;\n }\n }\n\n handlerClose = () => {\n // because call not only click\n fire(this, 'onClose');\n this.clearTimer();\n };\n\n handlerMouseEnter = () => {\n if (this.timer) {\n this.timer.pause();\n }\n };\n\n handlerMouseLeave = () => {\n if (this.timer) {\n this.timer.resume();\n }\n };\n\n render() {\n const SInfo = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const SDismiss = 'div';\n const {\n action: actionNode,\n forwardRef,\n styles,\n onMouseEnter,\n onMouseLeave,\n children,\n ...other\n } = this.props;\n\n return sstyled(styles)(\n <SInfo\n role=\"alert\"\n {...other}\n ref={forwardRef}\n onMouseEnter={callAllEventHandlers(onMouseEnter, this.handlerMouseEnter)}\n onMouseLeave={callAllEventHandlers(onMouseLeave, this.handlerMouseLeave)}\n >\n <SDismiss title=\"Close\" onClick={this.handlerClose} aria-label=\"Close alert\">\n <CloseXS />\n </SDismiss>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SInfo>,\n );\n }\n}\n\nclass ViewWarning extends ViewInfo {\n static defaultProps = {\n type: 'warning',\n duration: 0,\n };\n\n render() {\n const SWarning = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const { action: actionNode, children, styles, forwardRef, ...other } = this.props;\n\n return sstyled(styles)(\n <SWarning ref={forwardRef} role=\"alert\" {...other}>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SWarning>,\n );\n }\n}\n\nclass NoticeBubbleView extends Component {\n static defaultProps = {\n duration: 5000,\n type: 'info',\n manager,\n };\n\n _notice = null;\n\n componentDidMount() {\n this._notice = this.asProps.manager.add(this.asProps);\n }\n\n componentWillUnmount() {\n if (this._notice) {\n this._notice.remove();\n }\n }\n\n componentDidUpdate() {\n if (this._notice) {\n this._notice.update(this.asProps);\n }\n }\n\n render() {\n return null;\n }\n}\n\nclass NoticeBubbleWarningView extends NoticeBubbleView {\n static defaultProps = {\n duration: 5000,\n type: 'warning',\n manager,\n };\n}\n\nconst NoticeBubbleContainer = createComponent(NoticeBubbleContainerRoot, {\n Info: NoticeBubbleView,\n Warning: NoticeBubbleWarningView,\n});\n\nconst NoticeBubble = NoticeBubbleContainer.Info;\nconst NoticeBubbleWarning = NoticeBubbleContainer.Warning;\n\nexport { NoticeBubble, NoticeBubbleWarning };\n\nexport default NoticeBubbleContainer;\n"],"file":"NoticeBubble.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/NoticeBubble.js"],"names":["React","Portal","manager","createComponent","Component","sstyled","Root","Animation","Box","fire","isNode","callAllEventHandlers","CloseXS","Timer","animationNotice","Notices","props","styles","data","tag","SView","ViewInfo","map","notice","uid","visible","undefined","NoticeBubbleContainerRoot","notices","warnings","_unsubscribe","info","filter","type","warning","setState","counter","addListener","handleChange","SNoticeBubble","asProps","Children","disablePortal","state","ViewWarning","style","e","clearTimer","timer","pause","resume","duration","handlerClose","clear","SInfo","SMessage","SAction","SDismiss","actionNode","action","forwardRef","onMouseEnter","onMouseLeave","children","other","handlerMouseEnter","handlerMouseLeave","SWarning","NoticeBubbleView","_notice","add","remove","update","NoticeBubbleWarningView","NoticeBubbleContainer","Info","Warning","NoticeBubble","NoticeBubbleWarning"],"mappings":";;;;;;;;;;;;;;;;;;;AA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A,IAAMG,mBAAmB,GAAGJ,qBAAqB,CAACE,OAAlD;AAEA,SAASC,YAAT,EAAuBC,mBAAvB;AAEA,eAAeJ,qBAAf","sourcesContent":["import React from 'react';\nimport Portal from '@semcore/portal';\nimport manager from './NoticeBubbleManager';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport { Animation } from '@semcore/animation';\nimport { Box } from '@semcore/flex-box';\nimport fire from '@semcore/utils/lib/fire';\nimport isNode from '@semcore/utils/lib/isNode';\nimport { callAllEventHandlers } from '@semcore/utils/lib/assignProps';\nimport CloseXS from '@semcore/icon/lib/Close/xs';\nimport { Timer } from './utils';\n\nimport style from './style/notice-bubble.shadow.css';\n\nconst animationNotice = sstyled.css`\n @keyframes enter {\n from {\n transform: translate(100%, 0);\n }\n to {\n transform: translate(0, 0);\n }\n }\n\n @keyframes exit {\n from {\n opacity: 1;\n }\n to {\n opacity: 0;\n }\n }\n`;\n\nconst Notices = (props) => {\n const { styles, data = [], tag: SView = ViewInfo } = props;\n\n return data.map((notice) => {\n return sstyled(styles)(\n <Animation\n key={notice.uid}\n visible={notice.visible === undefined ? true : notice.visible}\n duration={250}\n keyframes={[animationNotice['@enter'], animationNotice['@exit']]}\n >\n <SView {...notice} styles={notice.styles || styles} />\n </Animation>,\n );\n });\n};\n\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * ```\n *\n * Container is a portal (React.Portal) in the body, inserted once into any part of the application\n * and subscribes to manager updates(NoticeBubbleManager)\n * */\n\nclass NoticeBubbleContainerRoot extends Component {\n static displayName = 'NoticeBubbleContainer';\n static style = style;\n static defaultProps = {\n manager,\n };\n\n _unsubscribe = null;\n\n state = {\n notices: [],\n warnings: [],\n };\n\n constructor(props) {\n super(props);\n props.manager.counter = 0;\n this._unsubscribe = props.manager.addListener(this.handleChange);\n }\n\n componentWillUnmount = () => {\n if (this._unsubscribe) {\n this._unsubscribe();\n }\n };\n\n handleChange = (notices) => {\n const info = notices.filter((notice) => notice.type === 'info');\n const warning = notices.filter((notice) => notice.type === 'warning');\n\n this.setState({ notices: info, warnings: warning });\n };\n\n render() {\n const SNoticeBubble = Root;\n const { Children, styles, disablePortal } = this.asProps;\n const { notices, warnings } = this.state;\n\n return sstyled(styles)(\n <Portal disablePortal={disablePortal}>\n <SNoticeBubble render={Box}>\n <Children />\n <Notices styles={styles} data={warnings} tag={ViewWarning} />\n <Notices styles={styles} data={notices} tag={ViewInfo} />\n </SNoticeBubble>\n </Portal>,\n );\n }\n}\n/**\n * ```js\n * import { NoticeBubble } from \"@semcore/notice-bubble\"\n * <NoticeBubble.Info/>\n * ```\n *\n * View component, the appearance of the notice\n * */\nclass ViewInfo extends Component {\n timer = null;\n\n componentDidMount() {\n const { duration } = this.props;\n if (duration) {\n this.timer = new Timer(this.handlerClose, duration);\n }\n }\n\n componentWillUnmount() {\n this.clearTimer();\n }\n\n clearTimer() {\n if (this.timer) {\n this.timer.clear();\n this.timer = null;\n }\n }\n\n handlerClose = (e) => {\n // because call not only click\n fire(this, 'onClose', e);\n this.clearTimer();\n };\n\n handlerMouseEnter = () => {\n if (this.timer) {\n this.timer.pause();\n }\n };\n\n handlerMouseLeave = () => {\n if (this.timer) {\n this.timer.resume();\n }\n };\n\n render() {\n const SInfo = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const SDismiss = 'div';\n const {\n action: actionNode,\n forwardRef,\n styles,\n onMouseEnter,\n onMouseLeave,\n children,\n ...other\n } = this.props;\n\n return sstyled(styles)(\n <SInfo\n role=\"alert\"\n {...other}\n ref={forwardRef}\n onMouseEnter={callAllEventHandlers(onMouseEnter, this.handlerMouseEnter)}\n onMouseLeave={callAllEventHandlers(onMouseLeave, this.handlerMouseLeave)}\n >\n <SDismiss title=\"Close\" onClick={this.handlerClose} aria-label=\"Close alert\">\n <CloseXS />\n </SDismiss>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SInfo>,\n );\n }\n}\n\nclass ViewWarning extends ViewInfo {\n static defaultProps = {\n type: 'warning',\n duration: 0,\n };\n\n render() {\n const SWarning = Box;\n const SMessage = 'div';\n const SAction = 'div';\n const { action: actionNode, children, styles, forwardRef, ...other } = this.props;\n\n return sstyled(styles)(\n <SWarning ref={forwardRef} role=\"alert\" {...other}>\n <SMessage>{children}</SMessage>\n {isNode(actionNode) ? <SAction>{actionNode}</SAction> : null}\n </SWarning>,\n );\n }\n}\n\nclass NoticeBubbleView extends Component {\n static defaultProps = {\n duration: 5000,\n type: 'info',\n manager,\n };\n\n _notice = null;\n\n componentDidMount() {\n this._notice = this.asProps.manager.add(this.asProps);\n }\n\n componentWillUnmount() {\n if (this._notice) {\n this._notice.remove();\n }\n }\n\n componentDidUpdate() {\n if (this._notice) {\n this._notice.update(this.asProps);\n }\n }\n\n render() {\n return null;\n }\n}\n\nclass NoticeBubbleWarningView extends NoticeBubbleView {\n static defaultProps = {\n duration: 5000,\n type: 'warning',\n manager,\n };\n}\n\nconst NoticeBubbleContainer = createComponent(NoticeBubbleContainerRoot, {\n Info: NoticeBubbleView,\n Warning: NoticeBubbleWarningView,\n});\n\nconst NoticeBubble = NoticeBubbleContainer.Info;\nconst NoticeBubbleWarning = NoticeBubbleContainer.Warning;\n\nexport { NoticeBubble, NoticeBubbleWarning };\n\nexport default NoticeBubbleContainer;\n"],"file":"NoticeBubble.js"}
|
|
@@ -7,6 +7,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
7
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
8
|
|
|
9
9
|
import EventEmitter from '@semcore/utils/lib/eventEmitter';
|
|
10
|
+
import { callAllEventHandlers } from '@semcore/utils/lib/assignProps';
|
|
10
11
|
var EVENT_NAME = 'CHANGE';
|
|
11
12
|
|
|
12
13
|
var NoticeBubbleManager = /*#__PURE__*/function () {
|
|
@@ -31,45 +32,28 @@ var NoticeBubbleManager = /*#__PURE__*/function () {
|
|
|
31
32
|
key: "createItem",
|
|
32
33
|
value: function createItem(props) {
|
|
33
34
|
var manager = this;
|
|
34
|
-
this.counter++;
|
|
35
35
|
return _objectSpread(_objectSpread({
|
|
36
|
-
uid: this.counter,
|
|
37
36
|
type: 'info'
|
|
38
37
|
}, props), {}, {
|
|
39
|
-
onClose: function
|
|
40
|
-
if (props.
|
|
41
|
-
|
|
42
|
-
args[_key] = arguments[_key];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
props.onClose.apply(this, args);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (this.props.visible === undefined) {
|
|
49
|
-
manager.remove(this.props.uid);
|
|
38
|
+
onClose: callAllEventHandlers(props.onClose, function () {
|
|
39
|
+
if (props.visible === undefined) {
|
|
40
|
+
manager.remove(props.uid);
|
|
50
41
|
}
|
|
51
|
-
}
|
|
42
|
+
})
|
|
52
43
|
});
|
|
53
44
|
}
|
|
54
45
|
}, {
|
|
55
46
|
key: "emit",
|
|
56
47
|
value: function emit() {
|
|
57
|
-
|
|
58
|
-
if (item.visible === undefined) {
|
|
59
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
60
|
-
visible: true
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return item;
|
|
65
|
-
});
|
|
66
|
-
this.emitter.emit(EVENT_NAME, list);
|
|
48
|
+
this.emitter.emit(EVENT_NAME, this.items);
|
|
67
49
|
}
|
|
68
50
|
}, {
|
|
69
51
|
key: "add",
|
|
70
52
|
value: function add(props) {
|
|
71
|
-
var
|
|
72
|
-
var
|
|
53
|
+
var uid = this.counter++;
|
|
54
|
+
var item = this.createItem(_objectSpread({
|
|
55
|
+
uid: uid
|
|
56
|
+
}, props));
|
|
73
57
|
this.items.push(item);
|
|
74
58
|
this.emit();
|
|
75
59
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/NoticeBubbleManager.js"],"names":["EventEmitter","EVENT_NAME","NoticeBubbleManager","emitter","fn","subscribe","props","manager","
|
|
1
|
+
{"version":3,"sources":["../../src/NoticeBubbleManager.js"],"names":["EventEmitter","callAllEventHandlers","EVENT_NAME","NoticeBubbleManager","emitter","fn","subscribe","props","manager","type","onClose","visible","undefined","remove","uid","emit","items","counter","item","createItem","push","update","bind","index","findIndex","splice"],"mappings":";;;;;;;;AAAA,OAAOA,YAAP,MAAyB,iCAAzB;AACA,SAASC,oBAAT,QAAqC,gCAArC;AAEA,IAAMC,UAAU,GAAG,QAAnB;;IAEMC,mB;AAKJ,iCAAc;AAAA;;AAAA,mCAJN,EAIM;;AAAA,qCAHJ,IAGI;;AAAA,qCAFJ,CAEI;;AACZ,SAAKC,OAAL,GAAe,IAAIJ,YAAJ,EAAf;AACD;;;;WAED,qBAAYK,EAAZ,EAAgB;AACd,aAAO,KAAKD,OAAL,CAAaE,SAAb,CAAuBJ,UAAvB,EAAmCG,EAAnC,CAAP;AACD;;;WAED,oBAAWE,KAAX,EAAkB;AAChB,UAAMC,OAAO,GAAG,IAAhB;AAEA;AACEC,QAAAA,IAAI,EAAE;AADR,SAEKF,KAFL;AAGEG,QAAAA,OAAO,EAAET,oBAAoB,CAACM,KAAK,CAACG,OAAP,EAAgB,YAAM;AACjD,cAAIH,KAAK,CAACI,OAAN,KAAkBC,SAAtB,EAAiC;AAC/BJ,YAAAA,OAAO,CAACK,MAAR,CAAeN,KAAK,CAACO,GAArB;AACD;AACF,SAJ4B;AAH/B;AASD;;;WAED,gBAAO;AACL,WAAKV,OAAL,CAAaW,IAAb,CAAkBb,UAAlB,EAA8B,KAAKc,KAAnC;AACD;;;WAED,aAAIT,KAAJ,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,EAAf","sourcesContent":["import EventEmitter from '@semcore/utils/lib/eventEmitter';\nimport { callAllEventHandlers } from '@semcore/utils/lib/assignProps';\n\nconst EVENT_NAME = 'CHANGE';\n\nclass NoticeBubbleManager {\n items = [];\n emitter = null;\n counter = 0;\n\n constructor() {\n this.emitter = new EventEmitter();\n }\n\n addListener(fn) {\n return this.emitter.subscribe(EVENT_NAME, fn);\n }\n\n createItem(props) {\n const manager = this;\n\n return {\n type: 'info',\n ...props,\n onClose: callAllEventHandlers(props.onClose, () => {\n if (props.visible === undefined) {\n manager.remove(props.uid);\n }\n }),\n };\n }\n\n emit() {\n this.emitter.emit(EVENT_NAME, this.items);\n }\n\n add(props) {\n const uid = this.counter++;\n const item = this.createItem({ uid, ...props });\n this.items.push(item);\n this.emit();\n return {\n uid,\n update: this.update.bind(this, uid),\n remove: this.remove.bind(this, uid),\n };\n }\n\n update(uid, props) {\n const index = this.items.findIndex((item) => item.uid === uid);\n if (index !== -1) {\n this.items[index] = this.createItem({\n ...this.items[index],\n ...props,\n });\n this.emit();\n return true;\n }\n return false;\n }\n\n remove(uid) {\n const index = this.items.findIndex((item) => item.uid === uid);\n if (index !== -1) {\n this.items.splice(index, 1);\n this.emit();\n return true;\n }\n return false;\n }\n}\n\nexport { NoticeBubbleManager };\nexport default new NoticeBubbleManager();\n"],"file":"NoticeBubbleManager.js"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -38,13 +38,7 @@ export interface INoticeBubbleProps extends IBoxProps {
|
|
|
38
38
|
action?: React.ReactNode;
|
|
39
39
|
|
|
40
40
|
/** Triggered when the notice is closed */
|
|
41
|
-
onClose?: () => void;
|
|
42
|
-
|
|
43
|
-
/** Triggered on mouseEnter */
|
|
44
|
-
onMouseEnter?: (e?: React.SyntheticEvent) => void;
|
|
45
|
-
|
|
46
|
-
/** Triggered on mouseLeave */
|
|
47
|
-
onMouseLeave?: (e?: React.SyntheticEvent) => void;
|
|
41
|
+
onClose?: (e?: React.SyntheticEvent) => void;
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
export interface INoticeBubbleManager {
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/notice-bubble",
|
|
3
3
|
"description": "SEMRush NoticeBubble Component",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.2.2",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
8
8
|
"author": "Roman Lysov <r.lysov@semrush.com>",
|
|
9
|
-
"sideEffects":
|
|
10
|
-
"lib/*/NoticeBubble.js"
|
|
11
|
-
],
|
|
9
|
+
"sideEffects": false,
|
|
12
10
|
"license": "MIT",
|
|
13
11
|
"scripts": {
|
|
14
12
|
"build": "build --source=js",
|
package/src/NoticeBubble.js
CHANGED
|
@@ -33,13 +33,13 @@ const animationNotice = sstyled.css`
|
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
35
|
const Notices = (props) => {
|
|
36
|
-
const { styles, data = [], tag: SView = ViewInfo
|
|
36
|
+
const { styles, data = [], tag: SView = ViewInfo } = props;
|
|
37
37
|
|
|
38
38
|
return data.map((notice) => {
|
|
39
39
|
return sstyled(styles)(
|
|
40
40
|
<Animation
|
|
41
41
|
key={notice.uid}
|
|
42
|
-
visible={notice.visible
|
|
42
|
+
visible={notice.visible === undefined ? true : notice.visible}
|
|
43
43
|
duration={250}
|
|
44
44
|
keyframes={[animationNotice['@enter'], animationNotice['@exit']]}
|
|
45
45
|
>
|
|
@@ -74,7 +74,6 @@ class NoticeBubbleContainerRoot extends Component {
|
|
|
74
74
|
|
|
75
75
|
constructor(props) {
|
|
76
76
|
super(props);
|
|
77
|
-
debugger;
|
|
78
77
|
props.manager.counter = 0;
|
|
79
78
|
this._unsubscribe = props.manager.addListener(this.handleChange);
|
|
80
79
|
}
|
|
@@ -137,9 +136,9 @@ class ViewInfo extends Component {
|
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
handlerClose = () => {
|
|
139
|
+
handlerClose = (e) => {
|
|
141
140
|
// because call not only click
|
|
142
|
-
fire(this, 'onClose');
|
|
141
|
+
fire(this, 'onClose', e);
|
|
143
142
|
this.clearTimer();
|
|
144
143
|
};
|
|
145
144
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import EventEmitter from '@semcore/utils/lib/eventEmitter';
|
|
2
|
+
import { callAllEventHandlers } from '@semcore/utils/lib/assignProps';
|
|
2
3
|
|
|
3
4
|
const EVENT_NAME = 'CHANGE';
|
|
4
5
|
|
|
@@ -17,35 +18,25 @@ class NoticeBubbleManager {
|
|
|
17
18
|
|
|
18
19
|
createItem(props) {
|
|
19
20
|
const manager = this;
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
return {
|
|
22
|
-
uid: this.counter,
|
|
23
23
|
type: 'info',
|
|
24
24
|
...props,
|
|
25
|
-
onClose:
|
|
26
|
-
if (props.
|
|
27
|
-
props.
|
|
28
|
-
}
|
|
29
|
-
if (this.props.visible === undefined) {
|
|
30
|
-
manager.remove(this.props.uid);
|
|
25
|
+
onClose: callAllEventHandlers(props.onClose, () => {
|
|
26
|
+
if (props.visible === undefined) {
|
|
27
|
+
manager.remove(props.uid);
|
|
31
28
|
}
|
|
32
|
-
},
|
|
29
|
+
}),
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
emit() {
|
|
37
|
-
|
|
38
|
-
if (item.visible === undefined) {
|
|
39
|
-
return { ...item, visible: true };
|
|
40
|
-
}
|
|
41
|
-
return item;
|
|
42
|
-
});
|
|
43
|
-
this.emitter.emit(EVENT_NAME, list);
|
|
34
|
+
this.emitter.emit(EVENT_NAME, this.items);
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
add(props) {
|
|
47
|
-
const
|
|
48
|
-
const { uid }
|
|
38
|
+
const uid = this.counter++;
|
|
39
|
+
const item = this.createItem({ uid, ...props });
|
|
49
40
|
this.items.push(item);
|
|
50
41
|
this.emit();
|
|
51
42
|
return {
|
package/src/index.d.ts
CHANGED
|
@@ -38,13 +38,7 @@ export interface INoticeBubbleProps extends IBoxProps {
|
|
|
38
38
|
action?: React.ReactNode;
|
|
39
39
|
|
|
40
40
|
/** Triggered when the notice is closed */
|
|
41
|
-
onClose?: () => void;
|
|
42
|
-
|
|
43
|
-
/** Triggered on mouseEnter */
|
|
44
|
-
onMouseEnter?: (e?: React.SyntheticEvent) => void;
|
|
45
|
-
|
|
46
|
-
/** Triggered on mouseLeave */
|
|
47
|
-
onMouseLeave?: (e?: React.SyntheticEvent) => void;
|
|
41
|
+
onClose?: (e?: React.SyntheticEvent) => void;
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
export interface INoticeBubbleManager {
|