Skip to content

Commit c9311c9

Browse files
authored
Merge pull request #834 from Iterable/loren/embedded/SDK-393-cleanup
[SDK-393] cleanup
2 parents 17deaef + e0c9d7f commit c9311c9

10 files changed

Lines changed: 160 additions & 25 deletions

File tree

src/embedded/components/IterableEmbeddedBanner/IterableEmbeddedBanner.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,26 @@ import {
1919
} from './IterableEmbeddedBanner.styles';
2020

2121
/**
22-
* TODO: figure out how default action works.
22+
* The IterableEmbeddedBanner component is used to render a banner message.
23+
*
24+
* @param config - The config for the IterableEmbeddedBanner component.
25+
* @param message - The message to render.
26+
* @param onButtonClick - The function to call when a button is clicked.
27+
* @param onMessageClick - The function to call when the message is clicked.
28+
* @returns The IterableEmbeddedBanner component.
29+
*
30+
* @example
31+
* ```tsx
32+
* return (
33+
* <IterableEmbeddedBanner
34+
* config={config}
35+
* message={message}
36+
* onButtonClick={onButtonClick}
37+
* onMessageClick={onMessageClick}
38+
* />
39+
* );
40+
* ```
2341
*/
24-
2542
export const IterableEmbeddedBanner = ({
2643
config,
2744
message,

src/embedded/components/IterableEmbeddedCard/IterableEmbeddedCard.tsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,39 @@ import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbedde
1616
import { IMAGE_HEIGHT, styles } from './IterableEmbeddedCard.styles';
1717

1818
/**
19-
* TODO: Add default action click handler. See IterableEmbeddedView for functionality.
19+
* The IterableEmbeddedCard component is used to render a card message.
20+
*
21+
* @param config - The config for the IterableEmbeddedCard component.
22+
* @param message - The message to render.
23+
* @param onButtonClick - The function to call when a button is clicked.
24+
* @param onMessageClick - The function to call when the message is clicked.
25+
* @returns The IterableEmbeddedCard component.
26+
*
27+
* @example
28+
* ```tsx
29+
* return (
30+
* <IterableEmbeddedCard
31+
* config={config}
32+
* message={message}
33+
* onButtonClick={onButtonClick}
34+
* onMessageClick={onMessageClick}
35+
* />
36+
* );
37+
* ```
2038
*/
21-
2239
export const IterableEmbeddedCard = ({
2340
config,
2441
message,
2542
onButtonClick = () => {},
2643
onMessageClick = () => {},
2744
}: IterableEmbeddedComponentProps) => {
28-
const {
29-
handleButtonClick,
30-
handleMessageClick,
31-
media,
32-
parsedStyles,
33-
} = useEmbeddedView(IterableEmbeddedViewType.Card, {
34-
message,
35-
config,
36-
onButtonClick,
37-
onMessageClick,
38-
});
45+
const { handleButtonClick, handleMessageClick, media, parsedStyles } =
46+
useEmbeddedView(IterableEmbeddedViewType.Card, {
47+
message,
48+
config,
49+
onButtonClick,
50+
onMessageClick,
51+
});
3952
const buttons = message?.elements?.buttons ?? [];
4053

4154
return (
@@ -64,8 +77,7 @@ export const IterableEmbeddedCard = ({
6477
uri: media.url as string,
6578
height: PixelRatio.getPixelSizeForLayoutSize(IMAGE_HEIGHT),
6679
}
67-
:
68-
IterableLogoGrey
80+
: IterableLogoGrey
6981
}
7082
style={
7183
media.shouldShow

src/embedded/components/IterableEmbeddedNotification/IterableEmbeddedNotification.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ import { useEmbeddedView } from '../../hooks/useEmbeddedView';
1212
import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbeddedComponentProps';
1313
import { styles } from './IterableEmbeddedNotification.styles';
1414

15+
/**
16+
* The IterableEmbeddedNotification component is used to render a notification message.
17+
*
18+
* @param config - The config for the IterableEmbeddedNotification component.
19+
* @param message - The message to render.
20+
* @param onButtonClick - The function to call when a button is clicked.
21+
* @param onMessageClick - The function to call when the message is clicked.
22+
* @returns The IterableEmbeddedNotification component.
23+
*
24+
* @example
25+
* ```tsx
26+
* return (
27+
* <IterableEmbeddedNotification
28+
* config={config}
29+
* message={message}
30+
* onButtonClick={onButtonClick}
31+
* onMessageClick={onMessageClick}
32+
* />
33+
* );
34+
* ```
35+
*/
1536
export const IterableEmbeddedNotification = ({
1637
config,
1738
message,

src/embedded/components/IterableEmbeddedView.tsx

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { IterableEmbeddedNotification } from './IterableEmbeddedNotification';
99
/**
1010
* The props for the IterableEmbeddedView component.
1111
*/
12-
interface IterableEmbeddedViewProps extends IterableEmbeddedComponentProps {
12+
export interface IterableEmbeddedViewProps
13+
extends IterableEmbeddedComponentProps {
1314
/** The type of view to render. */
1415
viewType: IterableEmbeddedViewType;
1516
}
@@ -20,10 +21,78 @@ interface IterableEmbeddedViewProps extends IterableEmbeddedComponentProps {
2021
* @param message - The message to render.
2122
* @param config - The config for the IterableEmbeddedView component, most likely used to style the view.
2223
* @param onButtonClick - The function to call when a button is clicked.
24+
* @param onMessageClick - The function to call when the message is clicked.
2325
* @returns The IterableEmbeddedView component.
2426
*
25-
* This component is used to render pre-created, customizable message displays
26-
* included with Iterables RN SDK: cards, banners, and notifications.
27+
* This component is used to render the following pre-created, customizable
28+
* message displays included with Iterables RN SDK: cards, banners, and
29+
* notifications.
30+
*
31+
* @example
32+
* ```tsx
33+
* import {
34+
* IterableAction,
35+
* IterableEmbeddedView,
36+
* IterableEmbeddedViewType,
37+
* type IterableEmbeddedMessage,
38+
* type IterableEmbeddedMessageElementsButton,
39+
* } from '@iterable/react-native-sdk';
40+
*
41+
* // See `IterableEmbeddedViewType` for available view types.
42+
* const viewType = IterableEmbeddedViewType.Card;
43+
*
44+
* // Messages usually come from the embedded manager. `placementIds` is `number[] | null`
45+
* // (use `null` to load messages for all placements), for example:
46+
* // Iterable.embeddedManager.getMessages([101, 102]).then((messages) => { ... });
47+
* const message: IterableEmbeddedMessage = {
48+
* metadata: {
49+
* messageId: 'test-message-123',
50+
* placementId: 101,
51+
* },
52+
* elements: {
53+
* title: 'Test Title',
54+
* body: 'Test Body',
55+
* buttons: [
56+
* {
57+
* id: 'button-1',
58+
* title: 'Button 1',
59+
* action: new IterableAction('openUrl', 'https://example.com/one'),
60+
* },
61+
* {
62+
* id: 'button-2',
63+
* title: 'Button 2',
64+
* action: new IterableAction('openUrl', 'https://example.com/two'),
65+
* },
66+
* ],
67+
* },
68+
* };
69+
*
70+
* // The config is used to style the component.
71+
* // See `IterableEmbeddedViewConfig` for available config options.
72+
* const config = { backgroundColor: '#FFFFFF', borderRadius: 8 };
73+
*
74+
* // `onButtonClick` will be called when a button is clicked.
75+
* // This callback allows you to add custom logic in addition to the SDK's default handling.
76+
* const onButtonClick = (button: IterableEmbeddedMessageElementsButton) => {
77+
* console.log('Button clicked', button.id, button.title, button.action);
78+
* };
79+
*
80+
* // `onMessageClick` will be called when the message is clicked anywhere outside of a button.
81+
* // If a default action is set, it will be handled prior to this callback.
82+
* const onMessageClick = () => {
83+
* console.log('Message clicked');
84+
* };
85+
*
86+
* return (
87+
* <IterableEmbeddedView
88+
* viewType={viewType}
89+
* message={message}
90+
* config={config}
91+
* onButtonClick={onButtonClick}
92+
* onMessageClick={onMessageClick}
93+
* />
94+
* );
95+
* ```
2796
*/
2897
export const IterableEmbeddedView = ({
2998
viewType,

src/embedded/enums/IterableEmbeddedViewType.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
* The view type for an embedded message.
33
*/
44
export enum IterableEmbeddedViewType {
5-
/** The embedded view is a banner */
5+
/**
6+
* [Banner](https://support.iterable.com/hc/en-us/articles/23230946708244-Out-of-the-Box-Views-for-Embedded-Messages#banners) Out of the Box (OOTB) view.
7+
*/
68
Banner = 0,
7-
/** The embedded view is a card */
9+
/**
10+
* [Card](https://support.iterable.com/hc/en-us/articles/23230946708244-Out-of-the-Box-Views-for-Embedded-Messages#cards) Out of the Box (OOTB) view.
11+
*/
812
Card = 1,
9-
/** The embedded view is a notification */
13+
/**
14+
* [Notification](https://support.iterable.com/hc/en-us/articles/23230946708244-Out-of-the-Box-Views-for-Embedded-Messages#notifications) Out of the Box (OOTB) view.
15+
*/
1016
Notification = 2,
1117
}

src/embedded/hooks/useEmbeddedView/getMedia.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import { IterableEmbeddedViewType } from '../../enums';
1010
* @returns The media to render.
1111
*
1212
* @example
13+
* ```ts
1314
* const media = getMedia(IterableEmbeddedViewType.Notification, message);
1415
* console.log(media.url);
1516
* console.log(media.caption);
1617
* console.log(media.shouldShow ? 'true' : 'false');
18+
* ```
1719
*/
1820
export const getMedia = (
1921
/** The type of view to render. */

src/embedded/hooks/useEmbeddedView/getStyles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const getDefaultStyle = <T>(
3737
* @returns The styles.
3838
*
3939
* @example
40+
* ```ts
4041
* const styles = getStyles(IterableEmbeddedViewType.Notification, {
4142
* backgroundColor: '#000000',
4243
* borderColor: '#000000',
@@ -45,6 +46,7 @@ const getDefaultStyle = <T>(
4546
* primaryBtnBackgroundColor: '#000000',
4647
* primaryBtnTextColor: '#000000',
4748
* });
49+
* ```
4850
*/
4951
export const getStyles = (
5052
viewType: IterableEmbeddedViewType,

src/embedded/hooks/useEmbeddedView/useEmbeddedView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const noop = () => {};
1616
* @returns The embedded view.
1717
*
1818
* @example
19+
* ```tsx
1920
* const { handleButtonClick, handleMessageClick, media, parsedStyles } = useEmbeddedView(IterableEmbeddedViewType.Notification, {
2021
* message,
2122
* config,
@@ -30,6 +31,7 @@ const noop = () => {};
3031
* <Text>{parsedStyles.backgroundColor}</Text>
3132
* </View>
3233
* );
34+
* ```
3335
*/
3436
export const useEmbeddedView = (
3537
/** The type of view to render. */
@@ -51,7 +53,7 @@ export const useEmbeddedView = (
5153

5254
const handleButtonClick = useCallback(
5355
(button: IterableEmbeddedMessageElementsButton) => {
54-
onButtonClick(button);
56+
onButtonClick(button, message);
5557
Iterable.embeddedManager.handleClick(message, button.id, button.action);
5658
},
5759
[onButtonClick, message]

src/embedded/types/IterableEmbeddedComponentProps.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export interface IterableEmbeddedComponentProps {
88
/** The config for the embedded view. */
99
config?: IterableEmbeddedViewConfig | null;
1010
/** The function to call when a button is clicked. */
11-
onButtonClick?: (button: IterableEmbeddedMessageElementsButton) => void;
11+
onButtonClick?: (
12+
button: IterableEmbeddedMessageElementsButton,
13+
message: IterableEmbeddedMessage
14+
) => void;
1215
/** The function to call when the message is clicked. */
1316
onMessageClick?: () => void;
1417
}

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export {
4242
type IterableEmbeddedMessageElementsButton,
4343
type IterableEmbeddedMessageElementsText,
4444
type IterableEmbeddedViewConfig,
45+
type IterableEmbeddedViewProps,
4546
} from './embedded';
4647
export {
4748
IterableHtmlInAppContent,

0 commit comments

Comments
 (0)