@aws-amplify/ui-react-core 0.0.0-next-1019db2-20230515214701 → 0.0.0-next-b3182f2-20230516210236

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/esm/InAppMessaging/context/InAppMessagingContext/InAppMessagingContext.mjs +5 -0
  2. package/dist/esm/InAppMessaging/context/InAppMessagingProvider/InAppMessagingProvider.mjs +25 -0
  3. package/dist/esm/InAppMessaging/hooks/useInAppMessaging/useInAppMessaging.mjs +18 -0
  4. package/dist/esm/InAppMessaging/hooks/useMessage/useMessage.mjs +78 -0
  5. package/dist/esm/InAppMessaging/hooks/useMessage/utils.mjs +43 -0
  6. package/dist/esm/InAppMessaging/utils/handleMessageAction.mjs +16 -0
  7. package/dist/esm/index.mjs +5 -1
  8. package/dist/index.js +162 -1
  9. package/dist/types/InAppMessaging/context/InAppMessagingContext/InAppMessagingContext.d.ts +9 -0
  10. package/dist/types/InAppMessaging/context/InAppMessagingContext/index.d.ts +1 -0
  11. package/dist/types/InAppMessaging/context/InAppMessagingProvider/InAppMessagingProvider.d.ts +5 -0
  12. package/dist/types/InAppMessaging/context/InAppMessagingProvider/index.d.ts +1 -0
  13. package/dist/types/InAppMessaging/context/index.d.ts +2 -0
  14. package/dist/types/InAppMessaging/hooks/index.d.ts +2 -0
  15. package/dist/types/InAppMessaging/hooks/useInAppMessaging/index.d.ts +1 -0
  16. package/dist/types/InAppMessaging/hooks/useInAppMessaging/useInAppMessaging.d.ts +7 -0
  17. package/dist/types/InAppMessaging/hooks/useMessage/index.d.ts +1 -0
  18. package/dist/types/InAppMessaging/hooks/useMessage/types.d.ts +18 -0
  19. package/dist/types/InAppMessaging/hooks/useMessage/useMessage.d.ts +9 -0
  20. package/dist/types/InAppMessaging/hooks/useMessage/utils.d.ts +9 -0
  21. package/dist/types/InAppMessaging/index.d.ts +4 -0
  22. package/dist/types/InAppMessaging/types.d.ts +52 -0
  23. package/dist/types/InAppMessaging/utils/handleMessageAction.d.ts +9 -0
  24. package/dist/types/InAppMessaging/utils/index.d.ts +1 -0
  25. package/dist/types/index.d.ts +1 -1
  26. package/package.json +2 -2
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+
3
+ const InAppMessagingContext = createContext(null);
4
+
5
+ export { InAppMessagingContext as default };
@@ -0,0 +1,25 @@
1
+ import React, { useState, useEffect, useCallback, useMemo } from 'react';
2
+ import { Notifications } from '@aws-amplify/notifications';
3
+ import InAppMessagingContext from '../InAppMessagingContext/InAppMessagingContext.mjs';
4
+
5
+ const { InAppMessaging } = Notifications;
6
+ function InAppMessagingProvider({ children, }) {
7
+ const [message, setMessage] = useState(null);
8
+ useEffect(() => {
9
+ const listener = InAppMessaging.onMessageReceived((message) => {
10
+ setMessage(message);
11
+ });
12
+ return listener.remove;
13
+ }, []);
14
+ const clearMessage = useCallback(() => {
15
+ setMessage(null);
16
+ }, []);
17
+ const value = useMemo(() => ({
18
+ clearMessage,
19
+ displayMessage: setMessage,
20
+ message,
21
+ }), [clearMessage, message]);
22
+ return (React.createElement(InAppMessagingContext.Provider, { value: value }, children));
23
+ }
24
+
25
+ export { InAppMessagingProvider as default };
@@ -0,0 +1,18 @@
1
+ import { useContext } from 'react';
2
+ import InAppMessagingContext from '../../context/InAppMessagingContext/InAppMessagingContext.mjs';
3
+ import '@aws-amplify/notifications';
4
+
5
+ /**
6
+ * Utility hook used to access the InAppMessagingContext values
7
+ *
8
+ * @returns {InAppMessagingContextType} InAppMessaging context values
9
+ */
10
+ function useInAppMessaging() {
11
+ const inAppMessagingContext = useContext(InAppMessagingContext);
12
+ if (!inAppMessagingContext) {
13
+ throw new Error('InAppMessagingContext is empty, did you forget the InAppMessagingProvider?');
14
+ }
15
+ return inAppMessagingContext;
16
+ }
17
+
18
+ export { useInAppMessaging as default };
@@ -0,0 +1,78 @@
1
+ import { ConsoleLogger } from '@aws-amplify/core';
2
+ import { InAppMessageInteractionEvent, Notifications } from '@aws-amplify/notifications';
3
+ import { isNil } from '@aws-amplify/ui';
4
+ import RenderNothing from '../../../components/RenderNothing/RenderNothing.mjs';
5
+ import useInAppMessaging from '../useInAppMessaging/useInAppMessaging.mjs';
6
+ import { getContentProps, getPositionProp } from './utils.mjs';
7
+
8
+ const EMPTY_PROPS = Object.freeze({});
9
+ const logger = new ConsoleLogger('Notifications.InAppMessaging');
10
+ const { InAppMessaging } = Notifications;
11
+ /**
12
+ * Utility hook for parsing a message and retrieving its corresponding UI component and props
13
+ *
14
+ * @param {UseMessageParams} props - platform specific UI components, action handler, and styles
15
+ * @returns {UseMessage} message UI component and props
16
+ */
17
+ function useMessage({ components, onMessageAction, }) {
18
+ const { clearMessage, message } = useInAppMessaging();
19
+ const { BannerMessage, CarouselMessage, FullScreenMessage, ModalMessage } = components;
20
+ if (isNil(message)) {
21
+ return {
22
+ Component: RenderNothing,
23
+ props: EMPTY_PROPS,
24
+ };
25
+ }
26
+ const { content, layout } = message;
27
+ const onActionCallback = () => {
28
+ InAppMessaging.notifyMessageInteraction(message, InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN);
29
+ clearMessage();
30
+ };
31
+ const onClose = () => {
32
+ InAppMessaging.notifyMessageInteraction(message, InAppMessageInteractionEvent.MESSAGE_DISMISSED);
33
+ clearMessage();
34
+ };
35
+ const onDisplay = () => {
36
+ InAppMessaging.notifyMessageInteraction(message, InAppMessageInteractionEvent.MESSAGE_DISPLAYED);
37
+ };
38
+ switch (layout) {
39
+ case 'BOTTOM_BANNER':
40
+ case 'MIDDLE_BANNER':
41
+ case 'TOP_BANNER': {
42
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
43
+ onClose,
44
+ onDisplay, position: getPositionProp(layout) });
45
+ return { Component: BannerMessage, props };
46
+ }
47
+ case 'CAROUSEL': {
48
+ const props = {
49
+ data: content === null || content === void 0 ? void 0 : content.map((item) => getContentProps(item, onMessageAction, onActionCallback)),
50
+ layout,
51
+ onClose,
52
+ onDisplay,
53
+ };
54
+ return { Component: CarouselMessage, props };
55
+ }
56
+ case 'FULL_SCREEN': {
57
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
58
+ onClose,
59
+ onDisplay });
60
+ return { Component: FullScreenMessage, props };
61
+ }
62
+ case 'MODAL': {
63
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
64
+ onClose,
65
+ onDisplay });
66
+ return { Component: ModalMessage, props };
67
+ }
68
+ default: {
69
+ logger.info(`Received unknown InAppMessage layout: ${layout}`);
70
+ return {
71
+ Component: RenderNothing,
72
+ props: EMPTY_PROPS,
73
+ };
74
+ }
75
+ }
76
+ }
77
+
78
+ export { EMPTY_PROPS, useMessage as default };
@@ -0,0 +1,43 @@
1
+ import { __rest } from '../../../node_modules/tslib/tslib.es6.mjs';
2
+ import { ConsoleLogger } from '@aws-amplify/core';
3
+
4
+ const logger = new ConsoleLogger('Notifications.InAppMessaging');
5
+ const positions = {
6
+ BOTTOM_BANNER: 'bottom',
7
+ MIDDLE_BANNER: 'middle',
8
+ TOP_BANNER: 'top',
9
+ };
10
+ const getPositionProp = (layout) => positions[layout];
11
+ const getActionHandler = (actionParams, onMessageAction, onActionCallback) => ({
12
+ onAction() {
13
+ try {
14
+ onMessageAction(actionParams);
15
+ }
16
+ catch (e) {
17
+ logger.error(`Message action failure: ${e}`);
18
+ }
19
+ finally {
20
+ onActionCallback();
21
+ }
22
+ },
23
+ });
24
+ const getButtonProps = (_a, onMessageAction, onActionCallback) => {
25
+ var { action, url } = _a, baseButtonProps = __rest(_a, ["action", "url"]);
26
+ return (Object.assign(Object.assign({}, baseButtonProps), getActionHandler({ action, url }, onMessageAction, onActionCallback)));
27
+ };
28
+ const getContentProps = (content, onMessageAction, onActionCallback) => {
29
+ const props = {};
30
+ if (!content) {
31
+ return props;
32
+ }
33
+ const { primaryButton, secondaryButton } = content, restContent = __rest(content, ["primaryButton", "secondaryButton"]);
34
+ if (primaryButton) {
35
+ props.primaryButton = getButtonProps(primaryButton, onMessageAction, onActionCallback);
36
+ }
37
+ if (secondaryButton) {
38
+ props.secondaryButton = getButtonProps(secondaryButton, onMessageAction, onActionCallback);
39
+ }
40
+ return Object.assign(Object.assign({}, props), restContent);
41
+ };
42
+
43
+ export { getActionHandler, getContentProps, getPositionProp };
@@ -0,0 +1,16 @@
1
+ import { ConsoleLogger } from '@aws-amplify/core';
2
+ import { isString } from '@aws-amplify/ui';
3
+
4
+ const logger = new ConsoleLogger('Notifications.InAppMessaging');
5
+ const handleMessageAction = ({ action, handleMessageLinkAction, url, }) => {
6
+ logger.info(`Handle action: ${action}`);
7
+ if (action === 'LINK' || action === 'DEEP_LINK') {
8
+ if (!isString(url)) {
9
+ logger.warn(`url must be of type string. Received: ${url}`);
10
+ return;
11
+ }
12
+ handleMessageLinkAction(url);
13
+ }
14
+ };
15
+
16
+ export { handleMessageAction as default };
@@ -4,7 +4,11 @@ export { default as useAuthenticator } from './Authenticator/hooks/useAuthentica
4
4
  export { default as useAuthenticatorRoute } from './Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.mjs';
5
5
  export { default as useAuthenticatorInitMachine } from './Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.mjs';
6
6
  export { isComponentRouteKey as isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents } from './Authenticator/hooks/utils.mjs';
7
- export { default as RenderNothing } from './components/RenderNothing/RenderNothing.mjs';
7
+ export { default as useInAppMessaging } from './InAppMessaging/hooks/useInAppMessaging/useInAppMessaging.mjs';
8
+ export { default as useMessage } from './InAppMessaging/hooks/useMessage/useMessage.mjs';
9
+ import './InAppMessaging/context/InAppMessagingContext/InAppMessagingContext.mjs';
10
+ export { default as InAppMessagingProvider } from './InAppMessaging/context/InAppMessagingProvider/InAppMessagingProvider.mjs';
11
+ export { default as handleMessageAction } from './InAppMessaging/utils/handleMessageAction.mjs';
8
12
  export { default as usePreviousValue } from './hooks/usePreviousValue.mjs';
9
13
  export { default as useHasValueUpdated } from './hooks/useHasValueUpdated.mjs';
10
14
  export { templateJoin } from './utils/index.mjs';
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ var React = require('react');
6
6
  var react = require('@xstate/react');
7
7
  var awsAmplify = require('aws-amplify');
8
8
  var ui = require('@aws-amplify/ui');
9
+ var notifications = require('@aws-amplify/notifications');
10
+ var core = require('@aws-amplify/core');
9
11
 
10
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
13
 
@@ -458,6 +460,162 @@ function useAuthenticatorInitMachine(data) {
458
460
  }, [initializeMachine, route, data]);
459
461
  }
460
462
 
463
+ const InAppMessagingContext = React.createContext(null);
464
+
465
+ const { InAppMessaging: InAppMessaging$1 } = notifications.Notifications;
466
+ function InAppMessagingProvider({ children, }) {
467
+ const [message, setMessage] = React.useState(null);
468
+ React.useEffect(() => {
469
+ const listener = InAppMessaging$1.onMessageReceived((message) => {
470
+ setMessage(message);
471
+ });
472
+ return listener.remove;
473
+ }, []);
474
+ const clearMessage = React.useCallback(() => {
475
+ setMessage(null);
476
+ }, []);
477
+ const value = React.useMemo(() => ({
478
+ clearMessage,
479
+ displayMessage: setMessage,
480
+ message,
481
+ }), [clearMessage, message]);
482
+ return (React__default["default"].createElement(InAppMessagingContext.Provider, { value: value }, children));
483
+ }
484
+
485
+ /**
486
+ * Utility hook used to access the InAppMessagingContext values
487
+ *
488
+ * @returns {InAppMessagingContextType} InAppMessaging context values
489
+ */
490
+ function useInAppMessaging() {
491
+ const inAppMessagingContext = React.useContext(InAppMessagingContext);
492
+ if (!inAppMessagingContext) {
493
+ throw new Error('InAppMessagingContext is empty, did you forget the InAppMessagingProvider?');
494
+ }
495
+ return inAppMessagingContext;
496
+ }
497
+
498
+ const logger$2 = new core.ConsoleLogger('Notifications.InAppMessaging');
499
+ const positions = {
500
+ BOTTOM_BANNER: 'bottom',
501
+ MIDDLE_BANNER: 'middle',
502
+ TOP_BANNER: 'top',
503
+ };
504
+ const getPositionProp = (layout) => positions[layout];
505
+ const getActionHandler = (actionParams, onMessageAction, onActionCallback) => ({
506
+ onAction() {
507
+ try {
508
+ onMessageAction(actionParams);
509
+ }
510
+ catch (e) {
511
+ logger$2.error(`Message action failure: ${e}`);
512
+ }
513
+ finally {
514
+ onActionCallback();
515
+ }
516
+ },
517
+ });
518
+ const getButtonProps = (_a, onMessageAction, onActionCallback) => {
519
+ var { action, url } = _a, baseButtonProps = __rest(_a, ["action", "url"]);
520
+ return (Object.assign(Object.assign({}, baseButtonProps), getActionHandler({ action, url }, onMessageAction, onActionCallback)));
521
+ };
522
+ const getContentProps = (content, onMessageAction, onActionCallback) => {
523
+ const props = {};
524
+ if (!content) {
525
+ return props;
526
+ }
527
+ const { primaryButton, secondaryButton } = content, restContent = __rest(content, ["primaryButton", "secondaryButton"]);
528
+ if (primaryButton) {
529
+ props.primaryButton = getButtonProps(primaryButton, onMessageAction, onActionCallback);
530
+ }
531
+ if (secondaryButton) {
532
+ props.secondaryButton = getButtonProps(secondaryButton, onMessageAction, onActionCallback);
533
+ }
534
+ return Object.assign(Object.assign({}, props), restContent);
535
+ };
536
+
537
+ const EMPTY_PROPS = Object.freeze({});
538
+ const logger$1 = new core.ConsoleLogger('Notifications.InAppMessaging');
539
+ const { InAppMessaging } = notifications.Notifications;
540
+ /**
541
+ * Utility hook for parsing a message and retrieving its corresponding UI component and props
542
+ *
543
+ * @param {UseMessageParams} props - platform specific UI components, action handler, and styles
544
+ * @returns {UseMessage} message UI component and props
545
+ */
546
+ function useMessage({ components, onMessageAction, }) {
547
+ const { clearMessage, message } = useInAppMessaging();
548
+ const { BannerMessage, CarouselMessage, FullScreenMessage, ModalMessage } = components;
549
+ if (ui.isNil(message)) {
550
+ return {
551
+ Component: RenderNothing,
552
+ props: EMPTY_PROPS,
553
+ };
554
+ }
555
+ const { content, layout } = message;
556
+ const onActionCallback = () => {
557
+ InAppMessaging.notifyMessageInteraction(message, notifications.InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN);
558
+ clearMessage();
559
+ };
560
+ const onClose = () => {
561
+ InAppMessaging.notifyMessageInteraction(message, notifications.InAppMessageInteractionEvent.MESSAGE_DISMISSED);
562
+ clearMessage();
563
+ };
564
+ const onDisplay = () => {
565
+ InAppMessaging.notifyMessageInteraction(message, notifications.InAppMessageInteractionEvent.MESSAGE_DISPLAYED);
566
+ };
567
+ switch (layout) {
568
+ case 'BOTTOM_BANNER':
569
+ case 'MIDDLE_BANNER':
570
+ case 'TOP_BANNER': {
571
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
572
+ onClose,
573
+ onDisplay, position: getPositionProp(layout) });
574
+ return { Component: BannerMessage, props };
575
+ }
576
+ case 'CAROUSEL': {
577
+ const props = {
578
+ data: content === null || content === void 0 ? void 0 : content.map((item) => getContentProps(item, onMessageAction, onActionCallback)),
579
+ layout,
580
+ onClose,
581
+ onDisplay,
582
+ };
583
+ return { Component: CarouselMessage, props };
584
+ }
585
+ case 'FULL_SCREEN': {
586
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
587
+ onClose,
588
+ onDisplay });
589
+ return { Component: FullScreenMessage, props };
590
+ }
591
+ case 'MODAL': {
592
+ const props = Object.assign(Object.assign({}, getContentProps(content === null || content === void 0 ? void 0 : content[0], onMessageAction, onActionCallback)), { layout,
593
+ onClose,
594
+ onDisplay });
595
+ return { Component: ModalMessage, props };
596
+ }
597
+ default: {
598
+ logger$1.info(`Received unknown InAppMessage layout: ${layout}`);
599
+ return {
600
+ Component: RenderNothing,
601
+ props: EMPTY_PROPS,
602
+ };
603
+ }
604
+ }
605
+ }
606
+
607
+ const logger = new core.ConsoleLogger('Notifications.InAppMessaging');
608
+ const handleMessageAction = ({ action, handleMessageLinkAction, url, }) => {
609
+ logger.info(`Handle action: ${action}`);
610
+ if (action === 'LINK' || action === 'DEEP_LINK') {
611
+ if (!ui.isString(url)) {
612
+ logger.warn(`url must be of type string. Received: ${url}`);
613
+ return;
614
+ }
615
+ handleMessageLinkAction(url);
616
+ }
617
+ };
618
+
461
619
  function usePreviousValue(value) {
462
620
  const previous = React.useRef();
463
621
  // update ref post render
@@ -482,7 +640,8 @@ function templateJoin(values, template) {
482
640
  }
483
641
 
484
642
  exports.AuthenticatorProvider = AuthenticatorProvider;
485
- exports.RenderNothing = RenderNothing;
643
+ exports.InAppMessagingProvider = InAppMessagingProvider;
644
+ exports.handleMessageAction = handleMessageAction;
486
645
  exports.isAuthenticatorComponentRouteKey = isComponentRouteKey;
487
646
  exports.resolveAuthenticatorComponents = resolveAuthenticatorComponents;
488
647
  exports.templateJoin = templateJoin;
@@ -490,4 +649,6 @@ exports.useAuthenticator = useAuthenticator;
490
649
  exports.useAuthenticatorInitMachine = useAuthenticatorInitMachine;
491
650
  exports.useAuthenticatorRoute = useAuthenticatorRoute;
492
651
  exports.useHasValueUpdated = useHasValueUpdated;
652
+ exports.useInAppMessaging = useInAppMessaging;
653
+ exports.useMessage = useMessage;
493
654
  exports.usePreviousValue = usePreviousValue;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { Message } from '../../types';
3
+ export interface InAppMessagingContextType {
4
+ clearMessage: () => void;
5
+ displayMessage: (message: Message) => void;
6
+ message: Message | null;
7
+ }
8
+ declare const InAppMessagingContext: import("react").Context<InAppMessagingContextType | null>;
9
+ export default InAppMessagingContext;
@@ -0,0 +1 @@
1
+ export { default as InAppMessagingContext, InAppMessagingContextType, } from './InAppMessagingContext';
@@ -0,0 +1,5 @@
1
+ import { ReactNode } from 'react';
2
+ export interface InAppMessagingProviderProps {
3
+ children: ReactNode;
4
+ }
5
+ export default function InAppMessagingProvider({ children, }: InAppMessagingProviderProps): JSX.Element;
@@ -0,0 +1 @@
1
+ export { default as InAppMessagingProvider } from './InAppMessagingProvider';
@@ -0,0 +1,2 @@
1
+ export * from './InAppMessagingContext';
2
+ export * from './InAppMessagingProvider';
@@ -0,0 +1,2 @@
1
+ export * from './useInAppMessaging';
2
+ export * from './useMessage';
@@ -0,0 +1 @@
1
+ export { default as useInAppMessaging } from './useInAppMessaging';
@@ -0,0 +1,7 @@
1
+ import { InAppMessagingContextType } from '../../context';
2
+ /**
3
+ * Utility hook used to access the InAppMessagingContext values
4
+ *
5
+ * @returns {InAppMessagingContextType} InAppMessaging context values
6
+ */
7
+ export default function useInAppMessaging(): InAppMessagingContextType;
@@ -0,0 +1 @@
1
+ export { default as useMessage } from './useMessage';
@@ -0,0 +1,18 @@
1
+ import { BannerMessageCommonProps, BannerMessageComponent, CarouselMessageCommonProps, CarouselMessageComponent, FullScreenMessageCommonProps, FullScreenMessageComponent, ModalMessageCommonProps, ModalMessageComponent, OnMessageAction } from '../../types';
2
+ interface Components<PlatformStyleProps> {
3
+ BannerMessage: BannerMessageComponent<PlatformStyleProps>;
4
+ CarouselMessage: CarouselMessageComponent<PlatformStyleProps>;
5
+ FullScreenMessage: FullScreenMessageComponent<PlatformStyleProps>;
6
+ ModalMessage: ModalMessageComponent<PlatformStyleProps>;
7
+ }
8
+ export interface UseMessageParams<PlatformStyleProps> {
9
+ components: Components<PlatformStyleProps>;
10
+ onMessageAction: OnMessageAction;
11
+ }
12
+ type MessageComponent<PlatformStyleProps> = BannerMessageComponent<PlatformStyleProps> | CarouselMessageComponent<PlatformStyleProps> | FullScreenMessageComponent<PlatformStyleProps> | ModalMessageComponent<PlatformStyleProps>;
13
+ type MessageProps<PlatformStyleProps> = BannerMessageCommonProps<PlatformStyleProps> | CarouselMessageCommonProps<PlatformStyleProps> | FullScreenMessageCommonProps<PlatformStyleProps> | ModalMessageCommonProps<PlatformStyleProps>;
14
+ export interface UseMessage<PlatformStyleProps> {
15
+ Component: MessageComponent<PlatformStyleProps>;
16
+ props: MessageProps<PlatformStyleProps>;
17
+ }
18
+ export {};
@@ -0,0 +1,9 @@
1
+ import { UseMessage, UseMessageParams } from './types';
2
+ export declare const EMPTY_PROPS: Readonly<{}>;
3
+ /**
4
+ * Utility hook for parsing a message and retrieving its corresponding UI component and props
5
+ *
6
+ * @param {UseMessageParams} props - platform specific UI components, action handler, and styles
7
+ * @returns {UseMessage} message UI component and props
8
+ */
9
+ export default function useMessage<PlatformStyleProps>({ components, onMessageAction, }: UseMessageParams<PlatformStyleProps>): UseMessage<PlatformStyleProps>;
@@ -0,0 +1,9 @@
1
+ import { BannerMessageLayouts, MessageAction, MessageComponentPosition, MessageContent, MessageContentProps, OnMessageAction } from '../../types';
2
+ export declare const getPositionProp: (layout: BannerMessageLayouts) => MessageComponentPosition;
3
+ export declare const getActionHandler: (actionParams: {
4
+ action: MessageAction;
5
+ url?: string;
6
+ }, onMessageAction: OnMessageAction, onActionCallback: () => void) => {
7
+ onAction: () => void;
8
+ };
9
+ export declare const getContentProps: (content: MessageContent, onMessageAction: OnMessageAction, onActionCallback: () => void) => MessageContentProps;
@@ -0,0 +1,4 @@
1
+ export * from './hooks';
2
+ export * from './context';
3
+ export * from './types';
4
+ export * from './utils';
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { InAppMessage, InAppMessageAction, InAppMessageButton, InAppMessageContent, InAppMessageImage, InAppMessageLayout, InAppMessageStyle, InAppMessageTextAlign } from '@aws-amplify/notifications';
3
+ export type Message = InAppMessage;
4
+ export type MessageAction = InAppMessageAction;
5
+ export type MessageButton = InAppMessageButton;
6
+ export type MessageContent = InAppMessageContent;
7
+ export type MessageImage = InAppMessageImage;
8
+ export type MessageLayout = InAppMessageLayout;
9
+ export type MessageStyle = InAppMessageStyle;
10
+ export type MessageTextAlign = InAppMessageTextAlign;
11
+ export type OnMessageAction = (params: {
12
+ action: MessageAction;
13
+ url?: string | undefined;
14
+ }) => void;
15
+ export interface MessageButtonProps extends Omit<MessageButton, 'action' | 'url'> {
16
+ onAction: () => void;
17
+ }
18
+ export interface MessageContentProps extends Omit<MessageContent, 'primaryButton' | 'secondaryButton'> {
19
+ primaryButton?: MessageButtonProps;
20
+ secondaryButton?: MessageButtonProps;
21
+ }
22
+ export interface MessageComponentBaseProps<Style = unknown> extends MessageCommonProps<Style>, MessageContentProps {
23
+ }
24
+ export interface MessageCommonProps<PlatformStyleProps> {
25
+ layout: MessageLayout;
26
+ onClose?: () => void;
27
+ onDisplay?: () => void;
28
+ style?: PlatformStyleProps;
29
+ }
30
+ export type BannerMessageLayouts = 'BOTTOM_BANNER' | 'MIDDLE_BANNER' | 'TOP_BANNER';
31
+ export type MessageComponentPosition = 'bottom' | 'middle' | 'top';
32
+ export interface BannerMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps>, MessageContentProps {
33
+ position?: MessageComponentPosition;
34
+ }
35
+ export interface CarouselMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps> {
36
+ data?: MessageContentProps[];
37
+ }
38
+ export interface FullScreenMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps>, MessageContentProps {
39
+ }
40
+ export interface ModalMessageCommonProps<PlatformStyleProps> extends MessageCommonProps<PlatformStyleProps>, MessageContentProps {
41
+ }
42
+ export interface MessagePayloadStyle {
43
+ body?: MessageStyle;
44
+ container?: MessageStyle;
45
+ header?: MessageStyle;
46
+ primaryButton?: MessageStyle;
47
+ secondaryButton?: MessageStyle;
48
+ }
49
+ export type BannerMessageComponent<PlatformStyleProps> = React.ComponentType<BannerMessageCommonProps<PlatformStyleProps>>;
50
+ export type CarouselMessageComponent<PlatformStyleProps> = React.ComponentType<CarouselMessageCommonProps<PlatformStyleProps>>;
51
+ export type FullScreenMessageComponent<PlatformStyleProps> = React.ComponentType<FullScreenMessageCommonProps<PlatformStyleProps>>;
52
+ export type ModalMessageComponent<PlatformStyleProps> = React.ComponentType<ModalMessageCommonProps<PlatformStyleProps>>;
@@ -0,0 +1,9 @@
1
+ import { MessageAction } from '../types';
2
+ export type HandleMessageLinkAction = (url: string) => void | Promise<void>;
3
+ interface HandleMessageActionParams {
4
+ action: MessageAction;
5
+ handleMessageLinkAction: HandleMessageLinkAction;
6
+ url: string | undefined;
7
+ }
8
+ declare const handleMessageAction: ({ action, handleMessageLinkAction, url, }: HandleMessageActionParams) => void;
9
+ export default handleMessageAction;
@@ -0,0 +1 @@
1
+ export { default as handleMessageAction, HandleMessageLinkAction, } from './handleMessageAction';
@@ -1,4 +1,4 @@
1
1
  export { AuthenticatorComponentDefaults, AuthenticatorComponentDefaultProps, AuthenticatorComponentOverrides, AuthenticatorFooterComponent, AuthenticatorFormFieldsComponent, AuthenticatorHeaderComponent, AuthenticatorLegacyField, AuthenticatorMachineContext, AuthenticatorProvider, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, UseAuthenticator, useAuthenticatorInitMachine, UseAuthenticatorRoute, } from './Authenticator';
2
- export { RenderNothing } from './components';
2
+ export { BannerMessageCommonProps, BannerMessageComponent, CarouselMessageCommonProps, CarouselMessageComponent, FullScreenMessageCommonProps, FullScreenMessageComponent, handleMessageAction, HandleMessageLinkAction, InAppMessagingProvider, MessageButtonProps, MessageCommonProps, MessageComponentBaseProps, MessageContentProps, MessageImage, MessageLayout, MessagePayloadStyle, MessageTextAlign, ModalMessageCommonProps, ModalMessageComponent, OnMessageAction, useInAppMessaging, useMessage, } from './InAppMessaging';
3
3
  export { useHasValueUpdated, usePreviousValue } from './hooks';
4
4
  export { templateJoin } from './utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-core",
3
- "version": "0.0.0-next-1019db2-20230515214701",
3
+ "version": "0.0.0-next-b3182f2-20230516210236",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "react-native": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "typecheck": "tsc --noEmit"
32
32
  },
33
33
  "dependencies": {
34
- "@aws-amplify/ui": "0.0.0-next-1019db2-20230515214701",
34
+ "@aws-amplify/ui": "0.0.0-next-b3182f2-20230516210236",
35
35
  "@xstate/react": "3.0.1",
36
36
  "lodash": "4.17.21",
37
37
  "xstate": "^4.33.6"