-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathIterableEmbeddedView.tsx
More file actions
47 lines (42 loc) · 1.62 KB
/
IterableEmbeddedView.tsx
File metadata and controls
47 lines (42 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useMemo } from 'react';
import { IterableEmbeddedViewType } from '../enums/IterableEmbeddedViewType';
import { IterableEmbeddedBanner } from './IterableEmbeddedBanner';
import { IterableEmbeddedCard } from './IterableEmbeddedCard';
import { IterableEmbeddedNotification } from './IterableEmbeddedNotification/IterableEmbeddedNotification';
import type { IterableEmbeddedComponentProps } from '../types/IterableEmbeddedComponentProps';
/**
* The props for the IterableEmbeddedView component.
*/
interface IterableEmbeddedViewProps extends IterableEmbeddedComponentProps {
/** The type of view to render. */
viewType: IterableEmbeddedViewType;
}
/**
*
* @param viewType - The type of view to render.
* @param message - The message to render.
* @param config - The config for the IterableEmbeddedView component, most likely used to style the view.
* @param onButtonClick - The function to call when a button is clicked.
* @returns The IterableEmbeddedView component.
*
* This component is used to render pre-created, customizable message displays
* included with Iterables RN SDK: cards, banners, and notifications.
*/
export const IterableEmbeddedView = ({
viewType,
...props
}: IterableEmbeddedViewProps) => {
const Cmp = useMemo(() => {
switch (viewType) {
case IterableEmbeddedViewType.Card:
return IterableEmbeddedCard;
case IterableEmbeddedViewType.Notification:
return IterableEmbeddedNotification;
case IterableEmbeddedViewType.Banner:
return IterableEmbeddedBanner;
default:
return null;
}
}, [viewType]);
return Cmp ? <Cmp {...props} /> : null;
};