@semcore/notice-bubble 16.1.12 → 16.2.0-prerelease.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.
- package/CHANGELOG.md +7 -0
- package/lib/cjs/NoticeBubble.js +131 -91
- package/lib/cjs/NoticeBubble.js.map +1 -1
- package/lib/cjs/NoticeBubble.type.js +2 -0
- package/lib/cjs/NoticeBubble.type.js.map +1 -0
- package/lib/cjs/NoticeBubbleManager.js +32 -25
- package/lib/cjs/NoticeBubbleManager.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils.js +17 -4
- package/lib/cjs/utils.js.map +1 -1
- package/lib/es6/NoticeBubble.js +131 -91
- package/lib/es6/NoticeBubble.js.map +1 -1
- package/lib/es6/NoticeBubble.type.js +2 -0
- package/lib/es6/NoticeBubble.type.js.map +1 -0
- package/lib/es6/NoticeBubbleManager.js +32 -25
- package/lib/es6/NoticeBubbleManager.js.map +1 -1
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/utils.js +17 -4
- package/lib/es6/utils.js.map +1 -1
- package/lib/esm/NoticeBubble.mjs +120 -80
- package/lib/esm/NoticeBubbleManager.mjs +32 -25
- package/lib/esm/utils.mjs +17 -4
- package/lib/types/NoticeBubble.d.ts +33 -0
- package/lib/types/NoticeBubble.type.d.ts +130 -0
- package/lib/types/NoticeBubbleManager.d.ts +24 -0
- package/lib/types/index.d.ts +7 -167
- package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +58 -0
- package/lib/types/utils.d.ts +14 -0
- package/package.json +7 -6
- package/lib/cjs/index.d.js +0 -2
- package/lib/cjs/index.d.js.map +0 -1
- package/lib/es6/index.d.js +0 -2
- package/lib/es6/index.d.js.map +0 -1
package/lib/esm/NoticeBubble.mjs
CHANGED
|
@@ -1,80 +1,58 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
1
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
5
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
6
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
7
|
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
6
8
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
7
9
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
9
10
|
import { createComponent, sstyled, assignProps, Component } from "@semcore/core";
|
|
10
|
-
import { Animation } from "@semcore/
|
|
11
|
+
import { Box, Animation } from "@semcore/base-components";
|
|
11
12
|
import Button from "@semcore/button";
|
|
12
|
-
import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
|
|
13
13
|
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
14
14
|
import fire from "@semcore/core/lib/utils/fire";
|
|
15
15
|
import { getFocusableIn } from "@semcore/core/lib/utils/focus-lock/getFocusableIn";
|
|
16
16
|
import isNode from "@semcore/core/lib/utils/isNode";
|
|
17
|
-
import {
|
|
17
|
+
import { useForkRef } from "@semcore/core/lib/utils/ref";
|
|
18
18
|
import { contextThemeEnhance } from "@semcore/core/lib/utils/ThemeProvider";
|
|
19
19
|
import { setFocus, useFocusLock } from "@semcore/core/lib/utils/use/useFocusLock";
|
|
20
|
-
import {
|
|
20
|
+
import { cssVariableEnhance } from "@semcore/core/lib/utils/useCssVariable";
|
|
21
21
|
import { ZIndexStackingContextProvider, zIndexStackingEnhance } from "@semcore/core/lib/utils/zIndexStacking";
|
|
22
|
-
import {
|
|
22
|
+
import { Flex } from "@semcore/flex-box";
|
|
23
23
|
import CloseIcon from "@semcore/icon/Close/m";
|
|
24
24
|
import Portal from "@semcore/portal";
|
|
25
25
|
import React from "react";
|
|
26
26
|
import noticeBubbleDefaultManager from "./NoticeBubbleManager.mjs";
|
|
27
27
|
import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
|
|
28
28
|
import { Timer } from "./utils.mjs";
|
|
29
|
-
var _excluded = ["focusLock"]
|
|
29
|
+
var _excluded = ["focusLock"];
|
|
30
30
|
/*!__reshadow-styles__:"./style/notice-bubble.shadow.css"*/
|
|
31
31
|
var style = (
|
|
32
32
|
/*__reshadow_css_start__*/
|
|
33
33
|
(sstyled.insert(
|
|
34
34
|
/*__inner_css_start__*/
|
|
35
|
-
"@keyframes
|
|
35
|
+
"@keyframes enter_fiqqt{0%{transform:translate(100%,0);max-height:0;overflow:hidden}to{transform:translate(0,0);max-height:100vh;overflow:hidden}}@keyframes exit_fiqqt{0%{max-height:100vh;overflow:hidden;opacity:1}to{max-height:0;overflow:hidden;opacity:0}}.___SBubble_fiqqt_gg_,.___SView_fiqqt_gg_{position:relative;margin-bottom:var(--intergalactic-spacing-3x, 12px);padding:var(--intergalactic-spacing-3x, 12px);padding-right:calc(var(--intergalactic-spacing-8x, 32px) + var(--intergalactic-spacing-1x, 4px));width:100%;border-radius:var(--intergalactic-popper-rounded, 6px);overflow:hidden;box-sizing:border-box;color:var(--intergalactic-text-primary-invert, #ffffff);gap:var(--intergalactic-spacing-2x, 8px)}.___SBubble_fiqqt_gg_._type_info_fiqqt_gg_,.___SView_fiqqt_gg_._type_info_fiqqt_gg_{background:var(--intergalactic-bg-primary-invert, #191b23)}.___SBubble_fiqqt_gg_._type_warning_fiqqt_gg_,.___SView_fiqqt_gg_._type_warning_fiqqt_gg_{background:var(--intergalactic-bg-primary-critical, #ff4953)}.___SContent_fiqqt_gg_{flex-direction:column;gap:var(--intergalactic-spacing-2x, 8px);flex:1}.___SMessage_fiqqt_gg_{font-size:var(--intergalactic-fs-200, 14px);line-height:var(--intergalactic-lh-200, 142%)}.___SDismiss_fiqqt_gg_{cursor:pointer;position:absolute;right:0;top:0;margin-top:var(--intergalactic-spacing-2x, 8px);margin-right:var(--intergalactic-spacing-2x, 8px);margin-bottom:var(--intergalactic-spacing-2x, 8px);flex-shrink:0;border:0;background:0 0}.___SDismiss_fiqqt_gg_.__use_fiqqt_gg_{padding:0 1px}.___SIcon_fiqqt_gg_{justify-content:center;align-items:center;height:var(--intergalactic-spacing-5x, 20px)}.___SNoticeBubble_fiqqt_gg_{width:300px;position:fixed;right:var(--intergalactic-spacing-3x, 12px);top:var(--intergalactic-spacing-3x, 12px)}@media (max-width:767px){.___SNoticeBubble_fiqqt_gg_{width:calc(100% - var(--intergalactic-spacing-6x, 24px))}}.___SNoticeBubble_fiqqt_gg_.__disablePortal_fiqqt_gg_{position:sticky;margin-left:auto;height:0}.___SMessage_fiqqt_gg_ a{color:var(--intergalactic-text-link-invert, #8ecdff)}.___SNoticeAriaLiveWrapper_fiqqt_gg_{display:contents}",
|
|
36
36
|
/*__inner_css_end__*/
|
|
37
|
-
"
|
|
37
|
+
"fiqqt_gg_"
|
|
38
38
|
), /*__reshadow_css_end__*/
|
|
39
39
|
{
|
|
40
|
-
"__SContent": "
|
|
41
|
-
"__SMessage": "
|
|
42
|
-
"__SDismiss": "
|
|
43
|
-
"_use": "
|
|
44
|
-
"__SIcon": "
|
|
45
|
-
"__SNoticeBubble": "
|
|
46
|
-
"_disablePortal": "
|
|
47
|
-
"__SNoticeAriaLiveWrapper": "
|
|
48
|
-
"@enter": "
|
|
49
|
-
"@exit": "
|
|
50
|
-
"__SBubble": "
|
|
51
|
-
"__SView": "
|
|
52
|
-
"_type_info": "
|
|
53
|
-
"_type_warning": "
|
|
40
|
+
"__SContent": "___SContent_fiqqt_gg_",
|
|
41
|
+
"__SMessage": "___SMessage_fiqqt_gg_",
|
|
42
|
+
"__SDismiss": "___SDismiss_fiqqt_gg_",
|
|
43
|
+
"_use": "__use_fiqqt_gg_",
|
|
44
|
+
"__SIcon": "___SIcon_fiqqt_gg_",
|
|
45
|
+
"__SNoticeBubble": "___SNoticeBubble_fiqqt_gg_",
|
|
46
|
+
"_disablePortal": "__disablePortal_fiqqt_gg_",
|
|
47
|
+
"__SNoticeAriaLiveWrapper": "___SNoticeAriaLiveWrapper_fiqqt_gg_",
|
|
48
|
+
"@enter": "enter_fiqqt",
|
|
49
|
+
"@exit": "exit_fiqqt",
|
|
50
|
+
"__SBubble": "___SBubble_fiqqt_gg_",
|
|
51
|
+
"__SView": "___SView_fiqqt_gg_",
|
|
52
|
+
"_type_info": "_type_info_fiqqt_gg_",
|
|
53
|
+
"_type_warning": "_type_warning_fiqqt_gg_"
|
|
54
54
|
})
|
|
55
55
|
);
|
|
56
|
-
var Notices = function Notices2(props) {
|
|
57
|
-
var styles = props.styles, _props$data = props.data, data = _props$data === void 0 ? [] : _props$data, _props$tag = props.tag, SView = _props$tag === void 0 ? ViewInfo : _props$tag;
|
|
58
|
-
var ref = React.useRef();
|
|
59
|
-
var durationStr = useCssVariable("--intergalactic-duration-popper", "200", ref);
|
|
60
|
-
var duration = React.useMemo(function() {
|
|
61
|
-
return Number.parseInt(durationStr, 10);
|
|
62
|
-
}, [durationStr]);
|
|
63
|
-
return data.map(function(notice) {
|
|
64
|
-
var _ref2, _notice$visible;
|
|
65
|
-
return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(Animation, _ref2.cn("Animation", {
|
|
66
|
-
"key": notice.uid,
|
|
67
|
-
"initialAnimation": notice.initialAnimation,
|
|
68
|
-
"visible": (_notice$visible = notice.visible) !== null && _notice$visible !== void 0 ? _notice$visible : true,
|
|
69
|
-
"duration": duration,
|
|
70
|
-
"keyframes": [styles["@enter"], styles["@exit"]],
|
|
71
|
-
"ref": ref
|
|
72
|
-
}), /* @__PURE__ */ React.createElement(SView, _ref2.cn("SView", _objectSpread(_objectSpread({}, notice), {}, {
|
|
73
|
-
"styles": notice.styles || styles,
|
|
74
|
-
"getI18nText": props.getI18nText
|
|
75
|
-
}))));
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
56
|
var NoticeBubbleContainerRoot = /* @__PURE__ */ (function(_Component) {
|
|
79
57
|
function NoticeBubbleContainerRoot2() {
|
|
80
58
|
var _this;
|
|
@@ -86,6 +64,7 @@ var NoticeBubbleContainerRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
86
64
|
_defineProperty(_this, "_unsubscribe", null);
|
|
87
65
|
_defineProperty(_this, "state", {
|
|
88
66
|
notices: [],
|
|
67
|
+
infos: [],
|
|
89
68
|
warnings: []
|
|
90
69
|
});
|
|
91
70
|
_defineProperty(_this, "componentWillUnmount", function() {
|
|
@@ -94,16 +73,10 @@ var NoticeBubbleContainerRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
94
73
|
}
|
|
95
74
|
});
|
|
96
75
|
_defineProperty(_this, "handleChange", function(notices) {
|
|
97
|
-
var info = notices.filter(function(notice) {
|
|
98
|
-
return notice.type === "info";
|
|
99
|
-
});
|
|
100
|
-
var warning = notices.filter(function(notice) {
|
|
101
|
-
return notice.type === "warning";
|
|
102
|
-
});
|
|
103
76
|
_this.setState({
|
|
104
|
-
notices
|
|
105
|
-
warnings: warning
|
|
77
|
+
notices
|
|
106
78
|
});
|
|
79
|
+
_this.forceUpdate();
|
|
107
80
|
});
|
|
108
81
|
return _this;
|
|
109
82
|
}
|
|
@@ -119,8 +92,28 @@ var NoticeBubbleContainerRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
119
92
|
var _ref = this.asProps, _ref3;
|
|
120
93
|
var SNoticeBubble = Box;
|
|
121
94
|
var SNoticeAriaLiveWrapper = "div";
|
|
122
|
-
var _this$asProps = this.asProps, Children = _this$asProps.Children, styles = _this$asProps.styles, disablePortal = _this$asProps.disablePortal, getI18nText = _this$asProps.getI18nText, ref = _this$asProps.ref, parentZIndexStacking = _this$asProps.parentZIndexStacking;
|
|
123
|
-
var
|
|
95
|
+
var _this$asProps = this.asProps, Children = _this$asProps.Children, styles = _this$asProps.styles, disablePortal = _this$asProps.disablePortal, getI18nText = _this$asProps.getI18nText, ref = _this$asProps.ref, parentZIndexStacking = _this$asProps.parentZIndexStacking, duration = _this$asProps.duration, containerNode = _this$asProps.containerNode;
|
|
96
|
+
var notices = this.state.notices;
|
|
97
|
+
if (containerNode) {
|
|
98
|
+
return notices.map(function(notice) {
|
|
99
|
+
var _ref2;
|
|
100
|
+
var SView = notice.type === "warning" ? ViewWarning : ViewInfo;
|
|
101
|
+
return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(PortalForNoticeItem, _ref2.cn("PortalForNoticeItem", _objectSpread({
|
|
102
|
+
"key": notice.uid,
|
|
103
|
+
"tag": SView,
|
|
104
|
+
"containerNode": containerNode,
|
|
105
|
+
"animationDuration": duration,
|
|
106
|
+
"styles": styles,
|
|
107
|
+
"getI18nText": getI18nText
|
|
108
|
+
}, notice)));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
var infos = notices.filter(function(notice) {
|
|
112
|
+
return notice.type === "info";
|
|
113
|
+
});
|
|
114
|
+
var warnings = notices.filter(function(notice) {
|
|
115
|
+
return notice.type === "warning";
|
|
116
|
+
});
|
|
124
117
|
return _ref3 = sstyled(styles), /* @__PURE__ */ React.createElement(ZIndexStackingContextProvider, _ref3.cn("ZIndexStackingContextProvider", {
|
|
125
118
|
"designToken": "z-index-notice-bubble"
|
|
126
119
|
}), /* @__PURE__ */ React.createElement(Portal, _ref3.cn("Portal", {
|
|
@@ -131,25 +124,40 @@ var NoticeBubbleContainerRoot = /* @__PURE__ */ (function(_Component) {
|
|
|
131
124
|
"role": "region",
|
|
132
125
|
"aria-label": getI18nText("notification"),
|
|
133
126
|
"zIndex": parentZIndexStacking
|
|
134
|
-
}, _ref))), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {})),
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
}, _ref))), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {})), warnings.map(function(notice) {
|
|
128
|
+
var _ref4;
|
|
129
|
+
var SView = ViewWarning;
|
|
130
|
+
return _ref4 = sstyled(styles), /* @__PURE__ */ React.createElement(SView, _ref4.cn("SView", _objectSpread({
|
|
131
|
+
"key": notice.uid,
|
|
132
|
+
"animationDuration": duration,
|
|
133
|
+
"styles": styles,
|
|
134
|
+
"getI18nText": getI18nText
|
|
135
|
+
}, notice)));
|
|
136
|
+
}), /* @__PURE__ */ React.createElement(SNoticeAriaLiveWrapper, _ref3.cn("SNoticeAriaLiveWrapper", {
|
|
140
137
|
"aria-live": "polite"
|
|
141
|
-
}),
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
"
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
}), infos.map(function(notice) {
|
|
139
|
+
var _ref5;
|
|
140
|
+
var SView = ViewInfo;
|
|
141
|
+
return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(SView, _ref5.cn("SView", _objectSpread({
|
|
142
|
+
"key": notice.uid,
|
|
143
|
+
"animationDuration": duration,
|
|
144
|
+
"styles": styles,
|
|
145
|
+
"getI18nText": getI18nText
|
|
146
|
+
}, notice)));
|
|
147
|
+
})))));
|
|
147
148
|
}
|
|
148
149
|
}]);
|
|
149
150
|
})(Component);
|
|
150
151
|
_defineProperty(NoticeBubbleContainerRoot, "displayName", "NoticeBubbleContainer");
|
|
151
152
|
_defineProperty(NoticeBubbleContainerRoot, "style", style);
|
|
152
|
-
_defineProperty(NoticeBubbleContainerRoot, "enhance", [i18nEnhance(localizedMessages), contextThemeEnhance(), zIndexStackingEnhance("z-index-notice-bubble")
|
|
153
|
+
_defineProperty(NoticeBubbleContainerRoot, "enhance", [i18nEnhance(localizedMessages), contextThemeEnhance(), zIndexStackingEnhance("z-index-notice-bubble"), cssVariableEnhance({
|
|
154
|
+
variable: "--intergalactic-duration-popper",
|
|
155
|
+
fallback: 200,
|
|
156
|
+
map: function map(v) {
|
|
157
|
+
return Number.parseInt(v, 10);
|
|
158
|
+
},
|
|
159
|
+
prop: "duration"
|
|
160
|
+
})]);
|
|
153
161
|
_defineProperty(NoticeBubbleContainerRoot, "defaultProps", {
|
|
154
162
|
manager: noticeBubbleDefaultManager,
|
|
155
163
|
i18n: localizedMessages,
|
|
@@ -157,13 +165,37 @@ _defineProperty(NoticeBubbleContainerRoot, "defaultProps", {
|
|
|
157
165
|
});
|
|
158
166
|
var FocusLock = /* @__PURE__ */ React.forwardRef(function(props, outerRef) {
|
|
159
167
|
var focusLock = props.focusLock, other = _objectWithoutProperties(props, _excluded);
|
|
160
|
-
var innerRef = React.useRef();
|
|
168
|
+
var innerRef = React.useRef(null);
|
|
161
169
|
useFocusLock(innerRef, false, "auto", !focusLock, true);
|
|
162
170
|
var ref = useForkRef(outerRef, innerRef);
|
|
163
171
|
return /* @__PURE__ */ React.createElement(Flex, _extends({
|
|
164
172
|
ref
|
|
165
173
|
}, other));
|
|
166
174
|
});
|
|
175
|
+
var PortalForNoticeItem = function PortalForNoticeItem2(props) {
|
|
176
|
+
var _React$useState = React.useState(false), _React$useState2 = _slicedToArray(_React$useState, 2), showContent = _React$useState2[0], setShowContent = _React$useState2[1];
|
|
177
|
+
React.useEffect(function() {
|
|
178
|
+
setTimeout(function() {
|
|
179
|
+
setShowContent(true);
|
|
180
|
+
}, 200);
|
|
181
|
+
}, []);
|
|
182
|
+
var SNoticeAriaLiveWrapper = "div";
|
|
183
|
+
var Tag = props.tag;
|
|
184
|
+
if (props.type === "info") {
|
|
185
|
+
return /* @__PURE__ */ React.createElement(ZIndexStackingContextProvider, {
|
|
186
|
+
designToken: "z-index-notice-bubble"
|
|
187
|
+
}, /* @__PURE__ */ React.createElement(Portal, {
|
|
188
|
+
nodeToMount: props.containerNode
|
|
189
|
+
}, /* @__PURE__ */ React.createElement(SNoticeAriaLiveWrapper, {
|
|
190
|
+
"aria-live": "polite"
|
|
191
|
+
}, showContent && /* @__PURE__ */ React.createElement(Tag, props))));
|
|
192
|
+
}
|
|
193
|
+
return /* @__PURE__ */ React.createElement(ZIndexStackingContextProvider, {
|
|
194
|
+
designToken: "z-index-notice-bubble"
|
|
195
|
+
}, /* @__PURE__ */ React.createElement(Portal, {
|
|
196
|
+
nodeToMount: props.containerNode
|
|
197
|
+
}, /* @__PURE__ */ React.createElement(Tag, props)));
|
|
198
|
+
};
|
|
167
199
|
var ViewInfo = /* @__PURE__ */ (function(_Component2) {
|
|
168
200
|
function ViewInfo2() {
|
|
169
201
|
var _this2;
|
|
@@ -193,9 +225,10 @@ var ViewInfo = /* @__PURE__ */ (function(_Component2) {
|
|
|
193
225
|
_this2.timer.resume();
|
|
194
226
|
});
|
|
195
227
|
_defineProperty(_this2, "handleBodyMouseMove", function(event) {
|
|
196
|
-
var _this2$timer;
|
|
228
|
+
var _this2$timer, _this2$ref$current;
|
|
197
229
|
if (!((_this2$timer = _this2.timer) !== null && _this2$timer !== void 0 && _this2$timer.paused)) return;
|
|
198
|
-
var rect = _this2.ref.current.getBoundingClientRect();
|
|
230
|
+
var rect = (_this2$ref$current = _this2.ref.current) === null || _this2$ref$current === void 0 ? void 0 : _this2$ref$current.getBoundingClientRect();
|
|
231
|
+
if (!rect) return;
|
|
199
232
|
var mouseInRect = event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
|
|
200
233
|
if (mouseInRect) return;
|
|
201
234
|
_this2.timer.resume();
|
|
@@ -241,21 +274,28 @@ var ViewInfo = /* @__PURE__ */ (function(_Component2) {
|
|
|
241
274
|
}, {
|
|
242
275
|
key: "render",
|
|
243
276
|
value: function render() {
|
|
244
|
-
var
|
|
277
|
+
var _ref6;
|
|
245
278
|
var SBubble = FocusLock;
|
|
246
279
|
var SDismiss = Button;
|
|
247
280
|
var SContent = Flex;
|
|
248
281
|
var SMessage = "div";
|
|
249
282
|
var SAction = "div";
|
|
250
283
|
var SIcon = Flex;
|
|
251
|
-
var _this$props = this.props,
|
|
252
|
-
return
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
284
|
+
var _this$props = this.props, styles = _this$props.styles, getI18nText = _this$props.getI18nText, visible = _this$props.visible, type = _this$props.type, initialAnimation = _this$props.initialAnimation, animationDuration = _this$props.animationDuration, icon = _this$props.icon, children = _this$props.children, action = _this$props.action, focusLock = _this$props.focusLock;
|
|
285
|
+
return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(Animation, _ref6.cn("Animation", {
|
|
286
|
+
"initialAnimation": initialAnimation,
|
|
287
|
+
"visible": visible !== null && visible !== void 0 ? visible : true,
|
|
288
|
+
"duration": animationDuration,
|
|
289
|
+
"keyframes": [styles["@enter"], styles["@exit"]]
|
|
290
|
+
}), /* @__PURE__ */ React.createElement(SBubble, _ref6.cn("SBubble", {
|
|
291
|
+
"type": type,
|
|
292
|
+
"ref": this.ref,
|
|
293
|
+
"onMouseEnter": this.handleMouseEnter,
|
|
294
|
+
"onMouseLeave": this.handleMouseLeave,
|
|
256
295
|
"onKeyDown": this.handleKeydown,
|
|
257
|
-
"role": type === "warning" ? "alert" :
|
|
258
|
-
|
|
296
|
+
"role": type === "warning" ? "alert" : void 0,
|
|
297
|
+
"focusLock": focusLock
|
|
298
|
+
}), /* @__PURE__ */ React.createElement(SDismiss, _ref6.cn("SDismiss", {
|
|
259
299
|
"aria-haspopup": void 0,
|
|
260
300
|
"type": "button",
|
|
261
301
|
"use": "tertiary",
|
|
@@ -270,7 +310,7 @@ var ViewInfo = /* @__PURE__ */ (function(_Component2) {
|
|
|
270
310
|
}), /* @__PURE__ */ React.createElement(Button.Addon, {
|
|
271
311
|
tag: CloseIcon,
|
|
272
312
|
color: "icon-primary-invert"
|
|
273
|
-
})), isNode(icon) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SIcon,
|
|
313
|
+
})), isNode(icon) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SIcon, _ref6.cn("SIcon", {}), icon), /* @__PURE__ */ React.createElement(SContent, _ref6.cn("SContent", {}), /* @__PURE__ */ React.createElement(SMessage, _ref6.cn("SMessage", {}), children), isNode(action) ? /* @__PURE__ */ React.createElement(SAction, _ref6.cn("SAction", {}), action) : null)) : /* @__PURE__ */ React.createElement(SContent, _ref6.cn("SContent", {}), /* @__PURE__ */ React.createElement(SMessage, _ref6.cn("SMessage", {}), children), isNode(action) ? /* @__PURE__ */ React.createElement(SAction, _ref6.cn("SAction", {}), action) : null)));
|
|
274
314
|
}
|
|
275
315
|
}]);
|
|
276
316
|
})(Component);
|
|
@@ -11,28 +11,15 @@ var NoticeBubbleManager = /* @__PURE__ */ (function() {
|
|
|
11
11
|
function NoticeBubbleManager2() {
|
|
12
12
|
_classCallCheck(this, NoticeBubbleManager2);
|
|
13
13
|
_defineProperty(this, "items", []);
|
|
14
|
-
_defineProperty(this, "emitter",
|
|
14
|
+
_defineProperty(this, "emitter", new EventEmitter());
|
|
15
15
|
_defineProperty(this, "counter", 0);
|
|
16
|
-
_defineProperty(this, "replaceTimer",
|
|
17
|
-
this.emitter = new EventEmitter();
|
|
16
|
+
_defineProperty(this, "replaceTimer", null);
|
|
18
17
|
}
|
|
19
18
|
return _createClass(NoticeBubbleManager2, [{
|
|
20
19
|
key: "addListener",
|
|
21
20
|
value: function addListener(fn) {
|
|
22
21
|
return this.emitter.subscribe(EVENT_NAME, fn);
|
|
23
22
|
}
|
|
24
|
-
}, {
|
|
25
|
-
key: "createItem",
|
|
26
|
-
value: function createItem(props) {
|
|
27
|
-
var manager = this;
|
|
28
|
-
return _objectSpread(_objectSpread({
|
|
29
|
-
type: "info"
|
|
30
|
-
}, props), {}, {
|
|
31
|
-
onClose: callAllEventHandlers(props.onClose, function() {
|
|
32
|
-
manager.remove(props.uid);
|
|
33
|
-
})
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
23
|
}, {
|
|
37
24
|
key: "emit",
|
|
38
25
|
value: function emit() {
|
|
@@ -41,18 +28,26 @@ var NoticeBubbleManager = /* @__PURE__ */ (function() {
|
|
|
41
28
|
}, {
|
|
42
29
|
key: "add",
|
|
43
30
|
value: function add(props) {
|
|
31
|
+
var _this = this;
|
|
44
32
|
var uid = this.counter++;
|
|
45
33
|
var ref = /* @__PURE__ */ React.createRef();
|
|
46
34
|
var focus = function focus2() {
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
setTimeout(function() {
|
|
36
|
+
if (ref.current) {
|
|
37
|
+
setFocus(ref.current);
|
|
38
|
+
}
|
|
49
39
|
}, 0);
|
|
50
40
|
};
|
|
51
|
-
var item =
|
|
41
|
+
var item = _objectSpread(_objectSpread({
|
|
42
|
+
type: "info",
|
|
52
43
|
uid,
|
|
53
44
|
visible: props.initialAnimation ? true : void 0,
|
|
54
45
|
forwardRef: ref
|
|
55
|
-
}, props)
|
|
46
|
+
}, props), {}, {
|
|
47
|
+
onClose: callAllEventHandlers(props.onClose, function() {
|
|
48
|
+
_this.remove(uid);
|
|
49
|
+
})
|
|
50
|
+
});
|
|
56
51
|
this.items.push(item);
|
|
57
52
|
this.emit();
|
|
58
53
|
return {
|
|
@@ -71,16 +66,28 @@ var NoticeBubbleManager = /* @__PURE__ */ (function() {
|
|
|
71
66
|
return item.uid === uid;
|
|
72
67
|
});
|
|
73
68
|
if (index !== -1) {
|
|
74
|
-
this.items[index] =
|
|
69
|
+
this.items[index] = _objectSpread(_objectSpread({}, this.items[index]), props);
|
|
75
70
|
this.emit();
|
|
76
71
|
return true;
|
|
77
72
|
}
|
|
78
73
|
return false;
|
|
79
74
|
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "replace",
|
|
77
|
+
value: function replace(uid, props) {
|
|
78
|
+
var _this2 = this;
|
|
79
|
+
if (this.replaceTimer) {
|
|
80
|
+
clearTimeout(this.replaceTimer);
|
|
81
|
+
}
|
|
82
|
+
this.remove(uid);
|
|
83
|
+
this.replaceTimer = setTimeout(function() {
|
|
84
|
+
_this2.add(props);
|
|
85
|
+
}, 300);
|
|
86
|
+
}
|
|
80
87
|
}, {
|
|
81
88
|
key: "replaceLast",
|
|
82
89
|
value: function replaceLast(props) {
|
|
83
|
-
var
|
|
90
|
+
var _this3 = this;
|
|
84
91
|
if (this.replaceTimer) {
|
|
85
92
|
clearTimeout(this.replaceTimer);
|
|
86
93
|
}
|
|
@@ -89,23 +96,23 @@ var NoticeBubbleManager = /* @__PURE__ */ (function() {
|
|
|
89
96
|
this.remove(this.counter - 1);
|
|
90
97
|
}
|
|
91
98
|
this.replaceTimer = setTimeout(function() {
|
|
92
|
-
|
|
99
|
+
_this3.add(props);
|
|
93
100
|
}, 300);
|
|
94
101
|
}
|
|
95
102
|
}, {
|
|
96
103
|
key: "remove",
|
|
97
104
|
value: function remove(uid) {
|
|
98
|
-
var
|
|
105
|
+
var _this4 = this;
|
|
99
106
|
var item = this.items.find(function(item2) {
|
|
100
107
|
return item2.uid === uid;
|
|
101
108
|
});
|
|
102
109
|
if (item) {
|
|
103
110
|
item.visible = false;
|
|
104
111
|
setTimeout(function() {
|
|
105
|
-
|
|
112
|
+
_this4.items = _this4.items.filter(function(item2) {
|
|
106
113
|
return item2.uid !== uid;
|
|
107
114
|
});
|
|
108
|
-
|
|
115
|
+
_this4.emit();
|
|
109
116
|
}, 1e3);
|
|
110
117
|
this.emit();
|
|
111
118
|
return true;
|
package/lib/esm/utils.mjs
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
4
|
var Timer = /* @__PURE__ */ (function() {
|
|
4
5
|
function Timer2(callback, delay) {
|
|
5
6
|
_classCallCheck(this, Timer2);
|
|
7
|
+
_defineProperty(this, "delay", void 0);
|
|
8
|
+
_defineProperty(this, "callback", void 0);
|
|
9
|
+
_defineProperty(this, "remaining", void 0);
|
|
10
|
+
_defineProperty(this, "timerId", null);
|
|
11
|
+
_defineProperty(this, "start", 0);
|
|
12
|
+
_defineProperty(this, "paused", void 0);
|
|
6
13
|
this.callback = callback;
|
|
7
14
|
this.delay = delay;
|
|
8
15
|
this.remaining = delay;
|
|
@@ -12,7 +19,9 @@ var Timer = /* @__PURE__ */ (function() {
|
|
|
12
19
|
return _createClass(Timer2, [{
|
|
13
20
|
key: "pause",
|
|
14
21
|
value: function pause() {
|
|
15
|
-
|
|
22
|
+
if (this.timerId) {
|
|
23
|
+
clearTimeout(this.timerId);
|
|
24
|
+
}
|
|
16
25
|
this.remaining -= Date.now() - this.start;
|
|
17
26
|
this.paused = true;
|
|
18
27
|
}
|
|
@@ -21,8 +30,10 @@ var Timer = /* @__PURE__ */ (function() {
|
|
|
21
30
|
value: function resume() {
|
|
22
31
|
this.start = Date.now();
|
|
23
32
|
this.paused = false;
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
if (this.timerId) {
|
|
34
|
+
clearTimeout(this.timerId);
|
|
35
|
+
}
|
|
36
|
+
this.timerId = window.setTimeout(this.callback, this.remaining);
|
|
26
37
|
}
|
|
27
38
|
}, {
|
|
28
39
|
key: "reset",
|
|
@@ -33,7 +44,9 @@ var Timer = /* @__PURE__ */ (function() {
|
|
|
33
44
|
}, {
|
|
34
45
|
key: "clear",
|
|
35
46
|
value: function clear() {
|
|
36
|
-
|
|
47
|
+
if (this.timerId) {
|
|
48
|
+
clearTimeout(this.timerId);
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
51
|
}]);
|
|
39
52
|
})();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Component } from '@semcore/core';
|
|
2
|
+
import type { Intergalactic } from '@semcore/core';
|
|
3
|
+
import type { AddedNoticeMeta, NoticeBubbleContainerProps, NoticeBubbleProps, NoticeBubbleWarningProps } from './NoticeBubble.type';
|
|
4
|
+
import type { NoticeBubbleManager } from './NoticeBubbleManager';
|
|
5
|
+
declare class NoticeBubbleView extends Component<{
|
|
6
|
+
manager: NoticeBubbleManager;
|
|
7
|
+
} & (NoticeBubbleProps | NoticeBubbleWarningProps)> {
|
|
8
|
+
static defaultProps: {
|
|
9
|
+
duration: number;
|
|
10
|
+
type: string;
|
|
11
|
+
manager: NoticeBubbleManager;
|
|
12
|
+
};
|
|
13
|
+
_notice: null | AddedNoticeMeta;
|
|
14
|
+
componentDidMount(): void;
|
|
15
|
+
componentWillUnmount(): void;
|
|
16
|
+
componentDidUpdate(): void;
|
|
17
|
+
render(): null;
|
|
18
|
+
}
|
|
19
|
+
declare class NoticeBubbleWarningView extends NoticeBubbleView {
|
|
20
|
+
static defaultProps: {
|
|
21
|
+
duration: number;
|
|
22
|
+
type: string;
|
|
23
|
+
manager: NoticeBubbleManager;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare const NoticeBubbleContainer: Intergalactic.Component<"div", NoticeBubbleContainerProps> & {
|
|
27
|
+
Info: typeof NoticeBubbleView;
|
|
28
|
+
Warning: typeof NoticeBubbleWarningView;
|
|
29
|
+
};
|
|
30
|
+
declare const NoticeBubble: typeof NoticeBubbleView;
|
|
31
|
+
declare const NoticeBubbleWarning: typeof NoticeBubbleWarningView;
|
|
32
|
+
export { NoticeBubble, NoticeBubbleWarning };
|
|
33
|
+
export default NoticeBubbleContainer;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { PortalProps, BoxProps } from '@semcore/base-components';
|
|
2
|
+
import type { UnknownProperties, Intergalactic } from '@semcore/core';
|
|
3
|
+
import type { useI18n } from '@semcore/core/lib/utils/enhances/WithI18n';
|
|
4
|
+
import type { NodeByRef } from '@semcore/core/lib/utils/ref';
|
|
5
|
+
import type { RefObject } from 'react';
|
|
6
|
+
/** @deprecated */
|
|
7
|
+
export interface INoticeBubbleContainerProps extends NoticeBubbleContainerProps, UnknownProperties {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated. Pass noticeBubbleContainer property from window.sm2.getNoticeBubbleContainer()
|
|
11
|
+
*/
|
|
12
|
+
export type NoticeBubbleContainerPortalProps = PortalProps;
|
|
13
|
+
export type NoticeBubbleContainerProps = BoxProps & NoticeBubbleContainerPortalProps & {
|
|
14
|
+
/** Ref or element to mount bubbles in. You should use element form window.sm2.getNoticeBubbleContainer() */
|
|
15
|
+
containerNode?: NodeByRef;
|
|
16
|
+
/** Manager copy */
|
|
17
|
+
manager?: NoticeBubbleManagerClass;
|
|
18
|
+
/** Specifies the locale for i18n support */
|
|
19
|
+
locale?: string;
|
|
20
|
+
};
|
|
21
|
+
export type NoticeBubbleViewItemProps = NoticeBubbleProps & {
|
|
22
|
+
containerNode?: NodeByRef;
|
|
23
|
+
animationDuration: number;
|
|
24
|
+
getI18nText: ReturnType<typeof useI18n>;
|
|
25
|
+
styles: React.DetailedHTMLProps<React.StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement> | undefined;
|
|
26
|
+
};
|
|
27
|
+
/** @deprecated */
|
|
28
|
+
export interface INoticeBubbleProps extends NoticeBubbleProps, UnknownProperties {
|
|
29
|
+
}
|
|
30
|
+
export type NoticeBubbleProps = BoxProps & {
|
|
31
|
+
/** Notice type */
|
|
32
|
+
type?: 'info' | 'warning';
|
|
33
|
+
/**
|
|
34
|
+
* Notice display duration. Set to 0 to disable auto-close.
|
|
35
|
+
*/
|
|
36
|
+
duration?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Enables animation on first rendering.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
initialAnimation?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Use it for complex notices with important controls.
|
|
44
|
+
* If enabled, browser focus will be locked in the notice
|
|
45
|
+
* until it's closed. After close focus should return to the element
|
|
46
|
+
* where it was placed before notice appear.
|
|
47
|
+
*/
|
|
48
|
+
focusLock?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Notice visibility.
|
|
51
|
+
*/
|
|
52
|
+
visible?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Control under the notice children.
|
|
55
|
+
* */
|
|
56
|
+
action?: React.ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* Callback triggered by "Close" icon click.
|
|
59
|
+
* */
|
|
60
|
+
onClose?: (e?: React.SyntheticEvent) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Notice content.
|
|
63
|
+
* */
|
|
64
|
+
children?: React.ReactNode;
|
|
65
|
+
manager?: NoticeBubbleManagerClass;
|
|
66
|
+
icon?: React.ReactElement;
|
|
67
|
+
};
|
|
68
|
+
/** @deprecated */
|
|
69
|
+
export interface INoticeBubbleInfoProps extends NoticeBubbleInfoProps, UnknownProperties {
|
|
70
|
+
}
|
|
71
|
+
export type NoticeBubbleInfoProps = NoticeBubbleProps & {
|
|
72
|
+
readonly type?: 'info';
|
|
73
|
+
};
|
|
74
|
+
/** @deprecated */
|
|
75
|
+
export interface INoticeBubbleWarningProps extends NoticeBubbleWarningProps, UnknownProperties {
|
|
76
|
+
}
|
|
77
|
+
export type NoticeBubbleWarningProps = NoticeBubbleProps & {
|
|
78
|
+
readonly type?: 'warning';
|
|
79
|
+
};
|
|
80
|
+
export type AddedNoticeMeta = {
|
|
81
|
+
uid: number;
|
|
82
|
+
update: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => boolean;
|
|
83
|
+
remove: () => boolean;
|
|
84
|
+
ref: RefObject<HTMLElement>;
|
|
85
|
+
focus: () => void;
|
|
86
|
+
};
|
|
87
|
+
/** @deprecated */
|
|
88
|
+
export interface INoticeBubbleManager extends NoticeBubbleManagerClass, UnknownProperties {
|
|
89
|
+
}
|
|
90
|
+
export type NoticeBubbleManagerClass = {
|
|
91
|
+
/**
|
|
92
|
+
* Creates and shows a notice.
|
|
93
|
+
* */
|
|
94
|
+
add: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => AddedNoticeMeta;
|
|
95
|
+
/**
|
|
96
|
+
* Updates notice by uid.
|
|
97
|
+
* @deprecated use replace instead.
|
|
98
|
+
*/
|
|
99
|
+
update: (uid: number, props: Partial<NoticeBubbleInfoProps> | Partial<NoticeBubbleWarningProps>) => boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Removes notice by uid.
|
|
102
|
+
* */
|
|
103
|
+
remove: (uid: number) => boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Replace notice by uid.
|
|
106
|
+
*/
|
|
107
|
+
replace: (uid: number, props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Replace last notice (if it is existing)
|
|
110
|
+
*/
|
|
111
|
+
replaceLast: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => void;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated use `NoticeBubbleManager` instead.
|
|
115
|
+
* */
|
|
116
|
+
export declare const NoticeBubble: Intergalactic.Component<'div', NoticeBubbleInfoProps>;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated use `NoticeBubbleManager` instead.
|
|
119
|
+
* */
|
|
120
|
+
export declare const NoticeBubbleWarning: Intergalactic.Component<'div', NoticeBubbleWarningProps>;
|
|
121
|
+
export declare const NoticeBubbleContainer: Intergalactic.Component<'div', NoticeBubbleContainerProps> & {
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated use `NoticeBubbleManager` instead.
|
|
124
|
+
* */
|
|
125
|
+
Info: typeof NoticeBubble;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated use `NoticeBubbleManager` instead.
|
|
128
|
+
* */
|
|
129
|
+
Warning: typeof NoticeBubbleWarning;
|
|
130
|
+
};
|