@aws-amplify/ui-react-notifications 1.0.14 → 2.0.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/dist/esm/components/InAppMessaging/Backdrop/Backdrop.mjs +9 -1
- package/dist/esm/components/InAppMessaging/Backdrop/withBackdrop.mjs +15 -1
- package/dist/esm/components/InAppMessaging/BannerMessage/BannerMessage.mjs +27 -1
- package/dist/esm/components/InAppMessaging/BannerMessage/constants.mjs +4 -1
- package/dist/esm/components/InAppMessaging/CloseIconButton/CloseIconButton.mjs +10 -1
- package/dist/esm/components/InAppMessaging/FullScreenMessage/FullScreenMessage.mjs +29 -1
- package/dist/esm/components/InAppMessaging/FullScreenMessage/constants.mjs +4 -1
- package/dist/esm/components/InAppMessaging/InAppMessageDisplay/InAppMessageDisplay.mjs +50 -1
- package/dist/esm/components/InAppMessaging/InAppMessageDisplay/handleMessageLinkAction.mjs +23 -1
- package/dist/esm/components/InAppMessaging/MessageLayout/MessageLayout.mjs +33 -1
- package/dist/esm/components/InAppMessaging/MessageLayout/constants.mjs +21 -1
- package/dist/esm/components/InAppMessaging/MessageLayout/utils.mjs +22 -1
- package/dist/esm/components/InAppMessaging/ModalMessage/ModalMessage.mjs +23 -1
- package/dist/esm/components/InAppMessaging/ModalMessage/constants.mjs +6 -1
- package/dist/esm/components/InAppMessaging/hooks/useMessageImage/types.mjs +9 -1
- package/dist/esm/components/InAppMessaging/hooks/useMessageImage/useMessageImage.mjs +40 -1
- package/dist/esm/components/InAppMessaging/hooks/useMessageProps/useMessageProps.mjs +33 -1
- package/dist/esm/components/InAppMessaging/hooks/useMessageProps/utils.mjs +62 -1
- package/dist/esm/components/InAppMessaging/withInAppMessaging/withInAppMessaging.mjs +13 -1
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/version.mjs +3 -0
- package/dist/index.js +394 -1
- package/dist/styles.css +298 -684
- package/dist/types/components/InAppMessaging/MessageLayout/constants.d.ts +6 -6
- package/dist/types/components/InAppMessaging/MessageLayout/utils.d.ts +1 -1
- package/dist/types/components/InAppMessaging/ModalMessage/constants.d.ts +1 -1
- package/dist/types/components/InAppMessaging/hooks/useMessageImage/useMessageImage.d.ts +2 -2
- package/dist/types/components/InAppMessaging/index.d.ts +1 -1
- package/dist/types/version.d.ts +1 -0
- package/package.json +8 -31
- package/dist/esm/node_modules/tslib/tslib.es6.mjs +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1,394 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var uiReactCoreNotifications = require('@aws-amplify/ui-react-core-notifications');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var uiReact = require('@aws-amplify/ui-react');
|
|
8
|
+
var uiReactCore = require('@aws-amplify/ui-react-core');
|
|
9
|
+
var ui = require('@aws-amplify/ui');
|
|
10
|
+
var utils = require('aws-amplify/utils');
|
|
11
|
+
var internal = require('@aws-amplify/ui-react/internal');
|
|
12
|
+
var tinycolor = require('tinycolor2');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
function _interopNamespace(e) {
|
|
17
|
+
if (e && e.__esModule) return e;
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n["default"] = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
35
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
36
|
+
var tinycolor__default = /*#__PURE__*/_interopDefaultLegacy(tinycolor);
|
|
37
|
+
|
|
38
|
+
var ImagePrefetchStatus;
|
|
39
|
+
(function (ImagePrefetchStatus) {
|
|
40
|
+
ImagePrefetchStatus["Aborted"] = "ABORTED";
|
|
41
|
+
ImagePrefetchStatus["Failure"] = "FAILURE";
|
|
42
|
+
ImagePrefetchStatus["Fetching"] = "FETCHING";
|
|
43
|
+
ImagePrefetchStatus["Success"] = "SUCCESS";
|
|
44
|
+
})(ImagePrefetchStatus || (ImagePrefetchStatus = {}));
|
|
45
|
+
|
|
46
|
+
const logger$1 = new utils.ConsoleLogger('InAppMessaging');
|
|
47
|
+
/**
|
|
48
|
+
* Handles prefetching for message images
|
|
49
|
+
*
|
|
50
|
+
* @param image contains image source
|
|
51
|
+
* @returns message image dimensions and fetching related booleans
|
|
52
|
+
*/
|
|
53
|
+
function useMessageImage(image) {
|
|
54
|
+
const { src } = image ?? {};
|
|
55
|
+
const shouldPrefetch = !!src;
|
|
56
|
+
// set initial status to fetching if prefetch is required
|
|
57
|
+
const [prefetchStatus, setPrefetchStatus] = React.useState(shouldPrefetch ? ImagePrefetchStatus.Fetching : null);
|
|
58
|
+
const isImageFetching = prefetchStatus === ImagePrefetchStatus.Fetching;
|
|
59
|
+
const hasRenderableImage = prefetchStatus === ImagePrefetchStatus.Success;
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if (!shouldPrefetch) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const img = new Image();
|
|
65
|
+
img.onload = () => {
|
|
66
|
+
setPrefetchStatus(ImagePrefetchStatus.Success);
|
|
67
|
+
};
|
|
68
|
+
img.onabort = () => {
|
|
69
|
+
logger$1.error(`Image load aborted: ${src}`);
|
|
70
|
+
setPrefetchStatus(ImagePrefetchStatus.Aborted);
|
|
71
|
+
};
|
|
72
|
+
img.onerror = () => {
|
|
73
|
+
logger$1.error(`Image failed to load: ${src}`);
|
|
74
|
+
setPrefetchStatus(ImagePrefetchStatus.Failure);
|
|
75
|
+
};
|
|
76
|
+
img.src = src;
|
|
77
|
+
}, [shouldPrefetch, src]);
|
|
78
|
+
return { hasRenderableImage, isImageFetching };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Utility for extracting message payload style
|
|
83
|
+
*
|
|
84
|
+
* @param props message props
|
|
85
|
+
*
|
|
86
|
+
* @returns message payload-specific styles
|
|
87
|
+
*/
|
|
88
|
+
const getPayloadStyle = ({ body, container, header, primaryButton, secondaryButton, }) => ({
|
|
89
|
+
body: body?.style ?? {},
|
|
90
|
+
container: container?.style ?? {},
|
|
91
|
+
header: header?.style ?? {},
|
|
92
|
+
primaryButton: primaryButton?.style ?? {},
|
|
93
|
+
secondaryButton: secondaryButton?.style ?? {},
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Receives message styling and returns style property values for use with in-app message
|
|
97
|
+
* UI components. Handles resolving style precedence between payload and custom styles
|
|
98
|
+
*
|
|
99
|
+
* Styles resolve precedence from lowest to highest:
|
|
100
|
+
* 1. Payload styles
|
|
101
|
+
* 2. Custom (override) styles
|
|
102
|
+
*
|
|
103
|
+
* @param params message style params
|
|
104
|
+
*
|
|
105
|
+
* @returns message component styles
|
|
106
|
+
*/
|
|
107
|
+
function getMessageStyles({ styleParams, }) {
|
|
108
|
+
const { payloadStyle, overrideStyle } = styleParams;
|
|
109
|
+
return {
|
|
110
|
+
// message body style
|
|
111
|
+
body: {
|
|
112
|
+
...payloadStyle?.body,
|
|
113
|
+
...overrideStyle?.body,
|
|
114
|
+
},
|
|
115
|
+
// close button style - not defined in payload, override only
|
|
116
|
+
closeIconButton: overrideStyle?.closeIconButton ?? {},
|
|
117
|
+
// message container style
|
|
118
|
+
container: {
|
|
119
|
+
...payloadStyle?.container,
|
|
120
|
+
...overrideStyle?.container,
|
|
121
|
+
},
|
|
122
|
+
// message header style
|
|
123
|
+
header: {
|
|
124
|
+
...payloadStyle?.header,
|
|
125
|
+
...overrideStyle?.header,
|
|
126
|
+
},
|
|
127
|
+
// image style - not defined in payload, override only
|
|
128
|
+
image: overrideStyle?.image ?? {},
|
|
129
|
+
// message primary button style
|
|
130
|
+
primaryButton: {
|
|
131
|
+
...payloadStyle?.primaryButton,
|
|
132
|
+
...overrideStyle?.primaryButton,
|
|
133
|
+
},
|
|
134
|
+
// message secondary button style
|
|
135
|
+
secondaryButton: {
|
|
136
|
+
...payloadStyle?.secondaryButton,
|
|
137
|
+
...overrideStyle?.secondaryButton,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Handle common message UI component prop logic including render booleans, and
|
|
144
|
+
* style resolving
|
|
145
|
+
*
|
|
146
|
+
* @param props message UI component props
|
|
147
|
+
*
|
|
148
|
+
* @returns message UI component render related booleans and styles
|
|
149
|
+
*/
|
|
150
|
+
function useMessageProps(props) {
|
|
151
|
+
const { image, onDisplay } = props;
|
|
152
|
+
const hasDisplayed = React.useRef(false);
|
|
153
|
+
const { hasRenderableImage, isImageFetching } = useMessageImage(image);
|
|
154
|
+
const shouldRenderMessage = !isImageFetching;
|
|
155
|
+
React.useEffect(() => {
|
|
156
|
+
if (!hasDisplayed.current && shouldRenderMessage) {
|
|
157
|
+
onDisplay?.();
|
|
158
|
+
hasDisplayed.current = true;
|
|
159
|
+
}
|
|
160
|
+
}, [onDisplay, shouldRenderMessage]);
|
|
161
|
+
const styles = React.useMemo(() => getMessageStyles({
|
|
162
|
+
styleParams: {
|
|
163
|
+
payloadStyle: getPayloadStyle(props),
|
|
164
|
+
overrideStyle: props.style,
|
|
165
|
+
},
|
|
166
|
+
}), [props]);
|
|
167
|
+
return { hasRenderableImage, shouldRenderMessage, styles };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function CloseIconButton({ className, dismissButtonLabel = 'Dismiss message', onClick, style, ...rest }) {
|
|
171
|
+
return (React__namespace.createElement(uiReact.Button, { ariaLabel: dismissButtonLabel, className: className, onClick: onClick, style: style, variation: "link", ...rest },
|
|
172
|
+
React__namespace.createElement(internal.IconClose, { "aria-hidden": "true", size: "1.5rem" })));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Base block class for MessageLayout
|
|
176
|
+
const BLOCK_CLASS$3 = 'amplify-inappmessaging-messagelayout';
|
|
177
|
+
// Element classes for MessageLayout
|
|
178
|
+
const BUTTON_CLASS = `${BLOCK_CLASS$3}__button`;
|
|
179
|
+
const CLOSE_BUTTON_CLASS = `${BLOCK_CLASS$3}__close-button`;
|
|
180
|
+
const CONTENT_CLASS = `${BLOCK_CLASS$3}__content`;
|
|
181
|
+
const HEADER_CLASS = `${BLOCK_CLASS$3}__header`;
|
|
182
|
+
const IMAGE_CONTAINER_CLASS = `${BLOCK_CLASS$3}__image-container`;
|
|
183
|
+
const TEXT_CONTAINER_CLASS = `${BLOCK_CLASS$3}__text-container`;
|
|
184
|
+
// Test IDs
|
|
185
|
+
const BODY_TEXT_TEST_ID = 'inappmessaging-messagelayout-bodytext';
|
|
186
|
+
const BUTTON_GROUP_TEST_ID = 'inappmessaging-messagelayout-buttongroup';
|
|
187
|
+
const CONTENT_TEST_ID = 'inappmessaging-messagelayout-content';
|
|
188
|
+
const HEADER_TEXT_TEST_ID = 'inappmessaging-messagelayout-headertext';
|
|
189
|
+
const IMAGE_CONTAINER_TEST_ID = 'inappmessaging-messagelayout-imagecontainer';
|
|
190
|
+
const MESSAGE_LAYOUT_TEST_ID = 'inappmessaging-messagelayout';
|
|
191
|
+
const PRIMARY_BUTTON_TEST_ID = 'inappmessaging-messagelayout-primarybutton';
|
|
192
|
+
const SECONDARY_BUTTON_TEST_ID = 'inappmessaging-messagelayout-secondarybutton';
|
|
193
|
+
const TEXT_CONTAINER_TEST_ID = 'inappmessaging-messagelayout-textcontainer';
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Utility for determining the class modifier for an In-App Messaging button
|
|
197
|
+
* based on its background color
|
|
198
|
+
*
|
|
199
|
+
* @param buttonStyles button styles which should contain the background color
|
|
200
|
+
* @param defaultModifier modifier that should be returned in cases where
|
|
201
|
+
* background color is undefined
|
|
202
|
+
*
|
|
203
|
+
* @returns the modifier - either 'light' or 'dark'
|
|
204
|
+
*/
|
|
205
|
+
const getButtonModifier = (buttonStyles, defaultModifier = 'light') => {
|
|
206
|
+
const { backgroundColor } = buttonStyles ?? {};
|
|
207
|
+
if (!backgroundColor) {
|
|
208
|
+
return defaultModifier;
|
|
209
|
+
}
|
|
210
|
+
const color = tinycolor__default["default"](backgroundColor);
|
|
211
|
+
return color.isDark() ? 'dark' : 'light';
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const isMessageButton = (button) => !ui.isEmpty(button);
|
|
215
|
+
function MessageLayout({ body, buttonSize, hasRenderableImage, header, image, onClose, orientation = 'vertical', primaryButton, secondaryButton, styles, }) {
|
|
216
|
+
const buttonModifiers = React__namespace.useMemo(() => ({
|
|
217
|
+
primary: getButtonModifier(styles.primaryButton),
|
|
218
|
+
secondary: getButtonModifier(styles.secondaryButton),
|
|
219
|
+
}), [styles]);
|
|
220
|
+
const isHorizontal = orientation === 'horizontal';
|
|
221
|
+
const closeButton = (React__namespace.createElement(CloseIconButton, { className: CLOSE_BUTTON_CLASS, onClick: onClose, style: styles.closeIconButton }));
|
|
222
|
+
const hasPrimaryButton = isMessageButton(primaryButton);
|
|
223
|
+
const hasSecondaryButton = isMessageButton(secondaryButton);
|
|
224
|
+
const hasButtons = hasPrimaryButton || hasSecondaryButton;
|
|
225
|
+
return (React__namespace.createElement(uiReact.Flex, { className: BLOCK_CLASS$3, "data-testid": MESSAGE_LAYOUT_TEST_ID, style: styles.container },
|
|
226
|
+
!isHorizontal && React__namespace.createElement(uiReact.Flex, { justifyContent: "flex-end" }, closeButton),
|
|
227
|
+
React__namespace.createElement(uiReact.Flex, { className: ui.classNames(CONTENT_CLASS, `${CONTENT_CLASS}--${orientation}`), "data-testid": CONTENT_TEST_ID },
|
|
228
|
+
hasRenderableImage && (React__namespace.createElement(uiReact.Flex, { className: ui.classNames(IMAGE_CONTAINER_CLASS, `${IMAGE_CONTAINER_CLASS}--${orientation}`), "data-testid": IMAGE_CONTAINER_TEST_ID },
|
|
229
|
+
React__namespace.createElement(uiReact.Image, { alt: "In-App Message Image", src: image?.src, style: styles.image }))),
|
|
230
|
+
React__namespace.createElement(uiReact.Flex, { className: ui.classNames(TEXT_CONTAINER_CLASS, `${TEXT_CONTAINER_CLASS}--${orientation}`), "data-testid": TEXT_CONTAINER_TEST_ID },
|
|
231
|
+
header?.content && (React__namespace.createElement(uiReact.Heading, { className: HEADER_CLASS, isTruncated: true, level: 2, style: styles.header, testId: HEADER_TEXT_TEST_ID }, header.content)),
|
|
232
|
+
body?.content && (React__namespace.createElement(uiReact.Text, { style: styles.body, testId: BODY_TEXT_TEST_ID }, body.content))),
|
|
233
|
+
isHorizontal && React__namespace.createElement(uiReact.Flex, { alignItems: "flex-start" }, closeButton)),
|
|
234
|
+
hasButtons && (React__namespace.createElement(uiReact.ButtonGroup, { size: buttonSize, testId: BUTTON_GROUP_TEST_ID },
|
|
235
|
+
hasSecondaryButton && (React__namespace.createElement(uiReact.Button, { className: ui.classNames(BUTTON_CLASS, `${BUTTON_CLASS}--${buttonModifiers.secondary}`), onClick: secondaryButton.onAction, style: styles.secondaryButton, testId: SECONDARY_BUTTON_TEST_ID }, secondaryButton.title)),
|
|
236
|
+
hasPrimaryButton && (React__namespace.createElement(uiReact.Button, { className: ui.classNames(BUTTON_CLASS, `${BUTTON_CLASS}--${buttonModifiers.primary}`), onClick: primaryButton.onAction, style: styles.primaryButton, testId: PRIMARY_BUTTON_TEST_ID }, primaryButton.title))))));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Base block class for BannerMessage
|
|
240
|
+
const BLOCK_CLASS$2 = 'amplify-inappmessaging-bannermessage';
|
|
241
|
+
|
|
242
|
+
function BannerMessage(props) {
|
|
243
|
+
const messageProps = useMessageProps(props);
|
|
244
|
+
const shouldBeFullWidth = uiReact.useBreakpointValue([true, true, false]);
|
|
245
|
+
const { shouldRenderMessage, styles } = messageProps;
|
|
246
|
+
if (!shouldRenderMessage) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
const { alignment = 'right', position = 'top' } = props;
|
|
250
|
+
const isCenterMiddle = alignment === 'center' && position === 'middle';
|
|
251
|
+
return (React__default["default"].createElement(uiReact.Flex, { className: ui.classNames(BLOCK_CLASS$2, {
|
|
252
|
+
[`${BLOCK_CLASS$2}--${position}`]: !isCenterMiddle,
|
|
253
|
+
[`${BLOCK_CLASS$2}--${alignment}`]: !isCenterMiddle,
|
|
254
|
+
[`${BLOCK_CLASS$2}--center-middle`]: isCenterMiddle,
|
|
255
|
+
[`${BLOCK_CLASS$2}--full-width`]: shouldBeFullWidth,
|
|
256
|
+
}), role: "dialog", testId: `inappmessaging-${position}banner-dialog` },
|
|
257
|
+
React__default["default"].createElement(MessageLayout, { ...props, ...messageProps, orientation: "horizontal", buttonSize: "small", styles: styles })));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const BACKDROP_TEST_ID = 'inappmessaging-backdrop';
|
|
261
|
+
function Backdrop({ onClick, ...rest }) {
|
|
262
|
+
return (React__default["default"].createElement(uiReact.View, { className: "amplify-inappmessaging-backdrop", "data-testid": BACKDROP_TEST_ID, onClick: onClick, ...rest }));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function withBackdrop(Content, options = {}) {
|
|
266
|
+
return function ContentWithBackdrop(props) {
|
|
267
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
268
|
+
React__default["default"].createElement(Backdrop, { ...options }),
|
|
269
|
+
React__default["default"].createElement(uiReact.Flex, { className: "amplify-inappmessaging-backdrop-content-container" },
|
|
270
|
+
React__default["default"].createElement(uiReact.View, { className: "amplify-inappmessaging-backdrop-content" },
|
|
271
|
+
React__default["default"].createElement(Content, { ...props })))));
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Base block class for FullScreenMessage
|
|
276
|
+
const BLOCK_CLASS$1 = 'amplify-inappmessaging-fullscreenmessage';
|
|
277
|
+
|
|
278
|
+
function FullScreenMessage(props) {
|
|
279
|
+
const messageProps = useMessageProps(props);
|
|
280
|
+
const shouldBeFullScreen = uiReact.useBreakpointValue([true, true, false]);
|
|
281
|
+
const { shouldRenderMessage, styles } = messageProps;
|
|
282
|
+
const { onClose: onClick } = props;
|
|
283
|
+
if (!shouldRenderMessage) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const Message = () => (React__namespace.createElement(uiReact.Flex, { className: ui.classNames(BLOCK_CLASS$1, {
|
|
287
|
+
[`${BLOCK_CLASS$1}--fullscreen`]: shouldBeFullScreen,
|
|
288
|
+
}), role: "dialog", testId: "inappmessaging-fullscreen-dialog" },
|
|
289
|
+
React__namespace.createElement(MessageLayout, { ...props, ...messageProps, styles: styles })));
|
|
290
|
+
if (shouldBeFullScreen) {
|
|
291
|
+
return React__namespace.createElement(Message, null);
|
|
292
|
+
}
|
|
293
|
+
const MessageWithBackdrop = withBackdrop(Message, { onClick });
|
|
294
|
+
return React__namespace.createElement(MessageWithBackdrop, null);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Base block class for ModalMessage
|
|
298
|
+
const BLOCK_CLASS = 'amplify-inappmessaging-modalmessage';
|
|
299
|
+
// Element classes for ModalMessage
|
|
300
|
+
const DIALOG_CLASS = `${BLOCK_CLASS}__dialog`;
|
|
301
|
+
|
|
302
|
+
function ModalMessage(props) {
|
|
303
|
+
const messageProps = useMessageProps(props);
|
|
304
|
+
const shouldBeFullWidth = uiReact.useBreakpointValue([true, true, false]);
|
|
305
|
+
const { shouldRenderMessage, styles } = messageProps;
|
|
306
|
+
if (!shouldRenderMessage) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
return (React__namespace.createElement(uiReact.Flex, { className: BLOCK_CLASS },
|
|
310
|
+
React__namespace.createElement(uiReact.Flex, { className: ui.classNames(DIALOG_CLASS, {
|
|
311
|
+
[`${DIALOG_CLASS}--full-width`]: shouldBeFullWidth,
|
|
312
|
+
}), role: "dialog", testId: "inappmessaging-modal-dialog" },
|
|
313
|
+
React__namespace.createElement(MessageLayout, { ...props, ...messageProps, styles: styles }))));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const logger = new utils.ConsoleLogger('InAppMessaging');
|
|
317
|
+
const handleMessageLinkAction = (input) => {
|
|
318
|
+
let url;
|
|
319
|
+
try {
|
|
320
|
+
url = new URL(input);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
logger.warn(`Unsupported url provided: ${input}`);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const { protocol } = url;
|
|
327
|
+
const isHttpProtocol = protocol === 'http:';
|
|
328
|
+
const isHttpsProtocol = protocol === 'https:';
|
|
329
|
+
if (!(isHttpProtocol || isHttpsProtocol)) {
|
|
330
|
+
logger.warn(`Unsupported url protocol provided: ${protocol}`);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
window.open(input);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const VERSION = '1.0.13';
|
|
337
|
+
|
|
338
|
+
// TODO: replace below components incrementally as they become available
|
|
339
|
+
function CarouselMessage(_) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
const platformComponents = {
|
|
343
|
+
BannerMessage,
|
|
344
|
+
CarouselMessage,
|
|
345
|
+
FullScreenMessage,
|
|
346
|
+
ModalMessage,
|
|
347
|
+
};
|
|
348
|
+
const onMessageAction = ({ action, url }) => {
|
|
349
|
+
uiReactCoreNotifications.handleMessageAction({
|
|
350
|
+
action,
|
|
351
|
+
url,
|
|
352
|
+
handleMessageLinkAction,
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
function InAppMessageDisplay({ components: overrideComponents, }) {
|
|
356
|
+
const components = React__default["default"].useMemo(() => ({ ...platformComponents, ...overrideComponents }), [overrideComponents]);
|
|
357
|
+
const { Component, props } = uiReactCoreNotifications.useMessage({
|
|
358
|
+
components,
|
|
359
|
+
onMessageAction,
|
|
360
|
+
});
|
|
361
|
+
uiReactCore.useSetUserAgent({
|
|
362
|
+
componentName: 'InAppMessaging',
|
|
363
|
+
packageName: 'react-notifications',
|
|
364
|
+
version: VERSION,
|
|
365
|
+
});
|
|
366
|
+
// There is currently no way to pass In-App Message payload variants so we
|
|
367
|
+
// will fix the theme around In-App Messaging components to always assume
|
|
368
|
+
// light mode
|
|
369
|
+
return (React__default["default"].createElement(uiReact.ThemeProvider, { colorMode: "light" },
|
|
370
|
+
React__default["default"].createElement(Component, { ...props })));
|
|
371
|
+
}
|
|
372
|
+
InAppMessageDisplay.BannerMessage = BannerMessage;
|
|
373
|
+
InAppMessageDisplay.CarouselMessage = CarouselMessage;
|
|
374
|
+
InAppMessageDisplay.FullScreenMessage = FullScreenMessage;
|
|
375
|
+
InAppMessageDisplay.ModalMessage = ModalMessage;
|
|
376
|
+
|
|
377
|
+
function withInAppMessaging(Component, options) {
|
|
378
|
+
return function WrappedWithInAppMessaging(props) {
|
|
379
|
+
return (React__default["default"].createElement(uiReactCoreNotifications.InAppMessagingProvider, null,
|
|
380
|
+
React__default["default"].createElement(InAppMessageDisplay, { ...options }),
|
|
381
|
+
React__default["default"].createElement(Component, { ...props })));
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
Object.defineProperty(exports, 'InAppMessagingProvider', {
|
|
386
|
+
enumerable: true,
|
|
387
|
+
get: function () { return uiReactCoreNotifications.InAppMessagingProvider; }
|
|
388
|
+
});
|
|
389
|
+
Object.defineProperty(exports, 'useInAppMessaging', {
|
|
390
|
+
enumerable: true,
|
|
391
|
+
get: function () { return uiReactCoreNotifications.useInAppMessaging; }
|
|
392
|
+
});
|
|
393
|
+
exports.InAppMessageDisplay = InAppMessageDisplay;
|
|
394
|
+
exports.withInAppMessaging = withInAppMessaging;
|