@knocklabs/react 0.2.33 → 0.3.0-rc-2.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 +8 -25
- package/dist/cjs/index.css +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/modules/feed/components/NotificationCell/NotificationCell.js.map +1 -1
- package/dist/cjs/modules/in-app-messages/components/Banner/Banner.js +2 -0
- package/dist/cjs/modules/in-app-messages/components/Banner/Banner.js.map +1 -0
- package/dist/cjs/modules/in-app-messages/components/Card/Card.js +2 -0
- package/dist/cjs/modules/in-app-messages/components/Card/Card.js.map +1 -0
- package/dist/cjs/modules/in-app-messages/components/Modal/Modal.js +2 -0
- package/dist/cjs/modules/in-app-messages/components/Modal/Modal.js.map +1 -0
- package/dist/cjs/modules/slack/components/SlackAuthButton/SlackAuthButton.js +1 -1
- package/dist/cjs/modules/slack/components/SlackAuthButton/SlackAuthButton.js.map +1 -1
- package/dist/esm/index.mjs +45 -36
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/modules/feed/components/NotificationCell/NotificationCell.mjs.map +1 -1
- package/dist/esm/modules/in-app-messages/components/Banner/Banner.mjs +99 -0
- package/dist/esm/modules/in-app-messages/components/Banner/Banner.mjs.map +1 -0
- package/dist/esm/modules/in-app-messages/components/Card/Card.mjs +111 -0
- package/dist/esm/modules/in-app-messages/components/Card/Card.mjs.map +1 -0
- package/dist/esm/modules/in-app-messages/components/Modal/Modal.mjs +115 -0
- package/dist/esm/modules/in-app-messages/components/Modal/Modal.mjs.map +1 -0
- package/dist/esm/modules/slack/components/SlackAuthButton/SlackAuthButton.mjs +3 -3
- package/dist/esm/modules/slack/components/SlackAuthButton/SlackAuthButton.mjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/types/App.d.ts +1 -0
- package/dist/types/App.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/main.d.ts +1 -0
- package/dist/types/modules/core/components/Button/Button.d.ts +1 -0
- package/dist/types/modules/core/components/Button/ButtonGroup.d.ts +1 -0
- package/dist/types/modules/core/components/Button/ButtonSpinner.d.ts +1 -0
- package/dist/types/modules/core/components/Icons/Bell.d.ts +1 -0
- package/dist/types/modules/core/components/Icons/CheckmarkCircle.d.ts +1 -0
- package/dist/types/modules/core/components/Icons/ChevronDown.d.ts +1 -0
- package/dist/types/modules/core/components/Icons/CloseCircle.d.ts +1 -0
- package/dist/types/modules/core/components/Spinner/Spinner.d.ts +1 -0
- package/dist/types/modules/core/hooks/useOnBottomScroll.d.ts +1 -0
- package/dist/types/modules/core/hooks/useOutsideClick.d.ts +1 -0
- package/dist/types/modules/feed/components/EmptyFeed/EmptyFeed.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationCell/ArchiveButton.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationCell/Avatar.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationCell/NotificationCell.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationFeed/Dropdown.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationFeed/MarkAsRead.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationFeed/NotificationFeed.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationFeed/NotificationFeedHeader.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationFeedContainer/NotificationFeedContainer.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationFeedPopover/NotificationFeedPopover.d.ts +1 -0
- package/dist/types/modules/feed/components/NotificationIconButton/NotificationIconButton.d.ts +1 -0
- package/dist/types/modules/feed/components/UnseenBadge/UnseenBadge.d.ts +1 -0
- package/dist/types/modules/in-app-messages/components/Banner/Banner.d.ts +52 -0
- package/dist/types/modules/in-app-messages/components/Banner/Banner.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/Banner/index.d.ts +2 -0
- package/dist/types/modules/in-app-messages/components/Banner/index.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/Card/Card.d.ts +57 -0
- package/dist/types/modules/in-app-messages/components/Card/Card.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/Card/index.d.ts +2 -0
- package/dist/types/modules/in-app-messages/components/Card/index.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/Modal/Modal.d.ts +70 -0
- package/dist/types/modules/in-app-messages/components/Modal/Modal.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/Modal/index.d.ts +2 -0
- package/dist/types/modules/in-app-messages/components/Modal/index.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/index.d.ts +4 -0
- package/dist/types/modules/in-app-messages/components/index.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/components/types.d.ts +5 -0
- package/dist/types/modules/in-app-messages/components/types.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/index.d.ts +2 -0
- package/dist/types/modules/in-app-messages/index.d.ts.map +1 -0
- package/dist/types/modules/slack/components/SlackAddChannelInput/SlackAddChannelInput.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackAuthButton/SlackAuthButton.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackAuthContainer/SlackAuthContainer.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/SlackChannelCombobox.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/SlackChannelListBox.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/SlackChannelOption.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/SlackConnectedChannelTag.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/SlackConnectedChannelTagList.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/SlackConnectionError.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/icons/CheckmarkIcon.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/icons/CloseIcon.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/icons/HashtagIcon.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/icons/InfoIcon.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/icons/LockIcon.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackChannelCombobox/icons/SearchIcon.d.ts +1 -0
- package/dist/types/modules/slack/components/SlackIcon/SlackIcon.d.ts +1 -0
- package/package.json +15 -11
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"NotificationCell.mjs","sources":["../../../../../../src/modules/feed/components/NotificationCell/NotificationCell.tsx"],"sourcesContent":["import {\n ActionButton,\n ButtonSetContentBlock,\n ContentBlock,\n FeedItem,\n MarkdownContentBlock,\n TextContentBlock,\n} from \"@knocklabs/client\";\nimport {\n formatTimestamp,\n renderNodeOrFallback,\n useKnockFeed,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport React, { ReactNode, useMemo } from \"react\";\n\nimport { Button, ButtonGroup } from \"../../../core\";\n\nimport { ArchiveButton } from \"./ArchiveButton\";\nimport { Avatar } from \"./Avatar\";\nimport \"./styles.css\";\n\nexport interface NotificationCellProps {\n item: FeedItem;\n // Invoked when the outer container is clicked\n onItemClick?: (item: FeedItem) => void;\n // Invoked when a button in the notification cell is clicked\n onButtonClick?: (item: FeedItem, action: ActionButton) => void;\n avatar?: ReactNode;\n children?: ReactNode;\n archiveButton?: ReactNode;\n}\n\ntype BlockByName = {\n [name: string]: ContentBlock;\n};\n\nfunction maybeNavigateToUrlWithDelay(url?: string) {\n if (url && url !== \"\") {\n setTimeout(() => window.location.assign(url), 200);\n }\n}\n\nexport const NotificationCell = React.forwardRef<\n HTMLDivElement,\n NotificationCellProps\n>(\n (\n { item, onItemClick, onButtonClick, avatar, children, archiveButton },\n ref,\n ) => {\n const { feedClient, colorMode } = useKnockFeed();\n const { locale } = useTranslations();\n\n const blocksByName: BlockByName = useMemo(() => {\n return item.blocks.reduce((acc, block) => {\n return { ...acc, [block.name]: block };\n }, {});\n }, [item]);\n\n const actionUrl = (blocksByName.action_url as TextContentBlock)?.rendered;\n const buttonSet = blocksByName.actions as ButtonSetContentBlock;\n\n const onContainerClickHandler = React.useCallback(() => {\n // Mark as interacted + read once we click the item\n feedClient.markAsInteracted(item, {\n type: \"cell_click\",\n action: actionUrl,\n });\n\n if (onItemClick) return onItemClick(item);\n\n return maybeNavigateToUrlWithDelay(actionUrl);\n }, [item, actionUrl, onItemClick, feedClient]);\n\n const onButtonClickHandler = React.useCallback(\n (
|
1
|
+
{"version":3,"file":"NotificationCell.mjs","sources":["../../../../../../src/modules/feed/components/NotificationCell/NotificationCell.tsx"],"sourcesContent":["import {\n ActionButton,\n ButtonSetContentBlock,\n ContentBlock,\n FeedItem,\n MarkdownContentBlock,\n TextContentBlock,\n} from \"@knocklabs/client\";\nimport {\n formatTimestamp,\n renderNodeOrFallback,\n useKnockFeed,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport React, { ReactNode, useMemo } from \"react\";\n\nimport { Button, ButtonGroup } from \"../../../core\";\n\nimport { ArchiveButton } from \"./ArchiveButton\";\nimport { Avatar } from \"./Avatar\";\nimport \"./styles.css\";\n\nexport interface NotificationCellProps {\n item: FeedItem;\n // Invoked when the outer container is clicked\n onItemClick?: (item: FeedItem) => void;\n // Invoked when a button in the notification cell is clicked\n onButtonClick?: (item: FeedItem, action: ActionButton) => void;\n avatar?: ReactNode;\n children?: ReactNode;\n archiveButton?: ReactNode;\n}\n\ntype BlockByName = {\n [name: string]: ContentBlock;\n};\n\nfunction maybeNavigateToUrlWithDelay(url?: string) {\n if (url && url !== \"\") {\n setTimeout(() => window.location.assign(url), 200);\n }\n}\n\nexport const NotificationCell = React.forwardRef<\n HTMLDivElement,\n NotificationCellProps\n>(\n (\n { item, onItemClick, onButtonClick, avatar, children, archiveButton },\n ref,\n ) => {\n const { feedClient, colorMode } = useKnockFeed();\n const { locale } = useTranslations();\n\n const blocksByName: BlockByName = useMemo(() => {\n return item.blocks.reduce((acc, block) => {\n return { ...acc, [block.name]: block };\n }, {});\n }, [item]);\n\n const actionUrl = (blocksByName.action_url as TextContentBlock)?.rendered;\n const buttonSet = blocksByName.actions as ButtonSetContentBlock;\n\n const onContainerClickHandler = React.useCallback(() => {\n // Mark as interacted + read once we click the item\n feedClient.markAsInteracted(item, {\n type: \"cell_click\",\n action: actionUrl,\n });\n\n if (onItemClick) return onItemClick(item);\n\n return maybeNavigateToUrlWithDelay(actionUrl);\n }, [item, actionUrl, onItemClick, feedClient]);\n\n const onButtonClickHandler = React.useCallback(\n (e: React.MouseEvent, button: ActionButton) => {\n // Record the interaction with the metadata for the button that was clicked\n feedClient.markAsInteracted(item, {\n type: \"button_click\",\n name: button.name,\n label: button.label,\n action: button.action,\n });\n\n if (onButtonClick) return onButtonClick(item, button);\n\n return maybeNavigateToUrlWithDelay(button.action);\n },\n [onButtonClick, feedClient, item],\n );\n\n const onKeyDown = React.useCallback(\n (ev: React.KeyboardEvent<HTMLDivElement>) => {\n switch (ev.key) {\n case \"Enter\": {\n ev.stopPropagation();\n onContainerClickHandler();\n break;\n }\n default:\n break;\n }\n },\n [onContainerClickHandler],\n );\n\n const actor = item.actors[0];\n\n return (\n <div\n ref={ref}\n className={`rnf-notification-cell rnf-notification-cell--${colorMode}`}\n onClick={onContainerClickHandler}\n onKeyDown={onKeyDown}\n tabIndex={0}\n >\n <div className=\"rnf-notification-cell__inner\">\n {!item.read_at && (\n <div className=\"rnf-notification-cell__unread-dot\" />\n )}\n\n {renderNodeOrFallback(\n avatar,\n actor && \"name\" in actor && actor.name && (\n <Avatar name={actor.name} src={actor.avatar} />\n ),\n )}\n\n <div className=\"rnf-notification-cell__content-outer\">\n {blocksByName.body && (\n <div\n className=\"rnf-notification-cell__content\"\n dangerouslySetInnerHTML={{\n __html: (blocksByName.body as MarkdownContentBlock).rendered,\n }}\n />\n )}\n\n {buttonSet && (\n <div className=\"rnf-notification-cell__button-group\">\n <ButtonGroup>\n {buttonSet.buttons.map((button, i) => (\n <Button\n variant={i === 0 ? \"primary\" : \"secondary\"}\n key={button.name}\n onClick={(e) => onButtonClickHandler(e, button)}\n >\n {button.label}\n </Button>\n ))}\n </ButtonGroup>\n </div>\n )}\n\n {children && (\n <div className=\"rnf-notification-cell__child-content\">\n {children}\n </div>\n )}\n\n <span className=\"rnf-notification-cell__timestamp\">\n {formatTimestamp(item.inserted_at, { locale })}\n </span>\n </div>\n\n {renderNodeOrFallback(archiveButton, <ArchiveButton item={item} />)}\n </div>\n </div>\n );\n },\n);\n"],"names":["maybeNavigateToUrlWithDelay","url","setTimeout","window","location","assign","NotificationCell","React","forwardRef","item","onItemClick","onButtonClick","avatar","children","archiveButton","ref","feedClient","colorMode","useKnockFeed","locale","useTranslations","blocksByName","useMemo","blocks","reduce","acc","block","name","actionUrl","action_url","rendered","buttonSet","actions","onContainerClickHandler","useCallback","markAsInteracted","type","action","onButtonClickHandler","e","button","label","onKeyDown","ev","key","stopPropagation","actor","actors","read_at","renderNodeOrFallback","Avatar","body","__html","ButtonGroup","buttons","map","i","Button","formatTimestamp","inserted_at","ArchiveButton"],"mappings":";;;;;;;;AAqCA,SAASA,EAA4BC,GAAc;AAC7CA,EAAAA,KAAOA,MAAQ,MACjBC,WAAW,MAAMC,OAAOC,SAASC,OAAOJ,CAAG,GAAG,GAAG;AAErD;AAEaK,MAAAA,IAAmBC,EAAMC,WAIpC,CACE;AAAA,EAAEC,MAAAA;AAAAA,EAAMC,aAAAA;AAAAA,EAAaC,eAAAA;AAAAA,EAAeC,QAAAA;AAAAA,EAAQC,UAAAA;AAAAA,EAAUC,eAAAA;AAAc,GACpEC,MACG;;AACG,QAAA;AAAA,IAAEC,YAAAA;AAAAA,IAAYC,WAAAA;AAAAA,MAAcC,EAAa,GACzC;AAAA,IAAEC,QAAAA;AAAAA,MAAWC,EAAgB,GAE7BC,IAA4BC,EAAQ,MACjCb,EAAKc,OAAOC,OAAO,CAACC,GAAKC,OACvB;AAAA,IAAE,GAAGD;AAAAA,I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A,KAASA,EAAMnB,QAChCpB,gBAAAA,EAAA,cAAC2C,KAAO,MAAMJ,EAAMnB,MAAM,KAAKmB,EAAMlC,SAEzC,GAEAL,gBAAAA,EAAA,cAAC,OAAI,EAAA,WAAU,uCACZc,GAAAA,EAAa8B,QACX5C,gBAAAA,EAAA,cAAA,OAAA,EACC,WAAU,kCACV,yBAAyB;AAAA,IACvB6C,QAAS/B,EAAa8B,KAA8BrB;AAAAA,EACtD,EAAA,CAEH,GAEAC,KACCxB,gBAAAA,EAAA,cAAC,SAAI,WAAU,sCAAA,GACZA,gBAAAA,EAAA,cAAA8C,GAAA,MACEtB,EAAUuB,QAAQC,IAAI,CAACf,GAAQgB,MAC9BjD,gBAAAA,EAAA,cAACkD,GACC,EAAA,SAASD,MAAM,IAAI,YAAY,aAC/B,KAAKhB,EAAOb,MACZ,SAAUY,CAAMD,MAAAA,EAAqBC,GAAGC,CAAM,EAAA,GAE7CA,EAAOC,KACV,CACD,CACH,CACF,GAGD5B,qCACE,OAAI,EAAA,WAAU,uCACZA,GAAAA,CACH,GAGFN,gBAAAA,EAAA,cAAC,UAAK,WAAU,mCAAA,GACbmD,EAAgBjD,EAAKkD,aAAa;AAAA,IAAExC,QAAAA;AAAAA,EAAQ,CAAA,CAC/C,CACF,GAEC8B,EAAqBnC,GAAeP,gBAAAA,EAAA,cAACqD,GAAc,EAAA,MAAAnD,IAAc,CACpE,CACF;AAEJ,CACF;"}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import { useInAppMessagesChannel as E, useInAppMessage as b } from "@knocklabs/react-core";
|
2
|
+
import i from "clsx";
|
3
|
+
import t, { useEffect as N } from "react";
|
4
|
+
/* empty css */
|
5
|
+
const f = "banner", s = ({
|
6
|
+
children: e,
|
7
|
+
className: a,
|
8
|
+
...n
|
9
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: i("knock-iam-banner", a), ...n }, e);
|
10
|
+
s.displayName = "BannerView.Root";
|
11
|
+
const o = ({
|
12
|
+
children: e,
|
13
|
+
className: a,
|
14
|
+
...n
|
15
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: i("knock-iam-banner__message", a), ...n }, e);
|
16
|
+
o.displayName = "BannerView.Content";
|
17
|
+
const c = ({
|
18
|
+
title: e,
|
19
|
+
className: a,
|
20
|
+
...n
|
21
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: i("knock-iam-banner__title", a), ...n }, e);
|
22
|
+
c.displayName = "BannerView.Title";
|
23
|
+
const l = ({
|
24
|
+
body: e,
|
25
|
+
className: a,
|
26
|
+
...n
|
27
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: i("knock-iam-banner__body", a), dangerouslySetInnerHTML: {
|
28
|
+
__html: e
|
29
|
+
}, ...n });
|
30
|
+
l.displayName = "BannerView.Body";
|
31
|
+
const m = ({
|
32
|
+
children: e,
|
33
|
+
className: a,
|
34
|
+
...n
|
35
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: i("knock-iam-banner__actions", a), ...n }, e);
|
36
|
+
m.displayName = "BannerView.Actions";
|
37
|
+
const d = ({
|
38
|
+
text: e,
|
39
|
+
action: a,
|
40
|
+
className: n,
|
41
|
+
...r
|
42
|
+
}) => /* @__PURE__ */ t.createElement("a", { href: a, className: i("knock-iam-banner__action", n), ...r }, e);
|
43
|
+
d.displayName = "BannerView.PrimaryAction";
|
44
|
+
const u = ({
|
45
|
+
text: e,
|
46
|
+
action: a,
|
47
|
+
className: n,
|
48
|
+
...r
|
49
|
+
}) => /* @__PURE__ */ t.createElement("a", { href: a, className: i("knock-iam-banner__action knock-iam-banner__action--secondary", n), ...r }, e);
|
50
|
+
u.displayName = "BannerView.SecondaryAction";
|
51
|
+
const _ = ({
|
52
|
+
className: e,
|
53
|
+
...a
|
54
|
+
}) => /* @__PURE__ */ t.createElement("button", { className: i("knock-iam-banner__close", e), ...a }, /* @__PURE__ */ t.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "18", height: "18", fill: "none" }, /* @__PURE__ */ t.createElement("g", { fill: "#60646C", fillRule: "evenodd", clipRule: "evenodd" }, /* @__PURE__ */ t.createElement("path", { d: "M14.03 3.97a.75.75 0 0 1 0 1.06l-9 9a.75.75 0 0 1-1.06-1.06l9-9a.75.75 0 0 1 1.06 0Z" }), /* @__PURE__ */ t.createElement("path", { d: "M3.97 3.97a.75.75 0 0 1 1.06 0l9 9a.75.75 0 1 1-1.06 1.06l-9-9a.75.75 0 0 1 0-1.06Z" }))));
|
55
|
+
_.displayName = "BannerView.DismissButton";
|
56
|
+
const p = ({
|
57
|
+
content: e,
|
58
|
+
colorMode: a = "light",
|
59
|
+
onInteract: n,
|
60
|
+
onDismiss: r
|
61
|
+
}) => /* @__PURE__ */ t.createElement(s, { "data-knock-color-mode": a, onClick: n }, /* @__PURE__ */ t.createElement(o, null, /* @__PURE__ */ t.createElement(c, { title: e.title }), /* @__PURE__ */ t.createElement(l, { body: e.body })), /* @__PURE__ */ t.createElement(m, null, e.secondary_button && /* @__PURE__ */ t.createElement(u, { text: e.secondary_button.text, action: e.secondary_button.action }), e.primary_button && /* @__PURE__ */ t.createElement(d, { text: e.primary_button.text, action: e.primary_button.action }), e.dismissible && /* @__PURE__ */ t.createElement(_, { onClick: r })));
|
62
|
+
p.displayName = "BannerView.Default";
|
63
|
+
const w = ({
|
64
|
+
filters: e
|
65
|
+
}) => {
|
66
|
+
const {
|
67
|
+
colorMode: a
|
68
|
+
} = E(), {
|
69
|
+
message: n,
|
70
|
+
inAppMessagesClient: r
|
71
|
+
} = b(f, e);
|
72
|
+
if (N(() => {
|
73
|
+
!n || n.seen_at !== null || r.markAsSeen(n);
|
74
|
+
}, [n, r]), !n || n.archived_at) return null;
|
75
|
+
const y = () => {
|
76
|
+
r.markAsArchived(n);
|
77
|
+
}, k = () => {
|
78
|
+
r.markAsInteracted(n);
|
79
|
+
};
|
80
|
+
return /* @__PURE__ */ t.createElement(p, { content: n.content, colorMode: a, onDismiss: y, onInteract: k });
|
81
|
+
};
|
82
|
+
w.displayName = "Banner";
|
83
|
+
const B = {};
|
84
|
+
Object.assign(B, {
|
85
|
+
Default: p,
|
86
|
+
Root: s,
|
87
|
+
Content: o,
|
88
|
+
Title: c,
|
89
|
+
Body: l,
|
90
|
+
Actions: m,
|
91
|
+
PrimaryAction: d,
|
92
|
+
SecondaryAction: u,
|
93
|
+
DismissButton: _
|
94
|
+
});
|
95
|
+
export {
|
96
|
+
w as Banner,
|
97
|
+
B as BannerView
|
98
|
+
};
|
99
|
+
//# sourceMappingURL=Banner.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Banner.mjs","sources":["../../../../../../src/modules/in-app-messages/components/Banner/Banner.tsx"],"sourcesContent":["import {\n ColorMode,\n UseInAppMessageOptions,\n useInAppMessage,\n useInAppMessagesChannel,\n} from \"@knocklabs/react-core\";\nimport clsx from \"clsx\";\nimport React, { useEffect } from \"react\";\n\nimport { ActionContent } from \"../types\";\n\nimport \"./styles.css\";\n\nconst MESSAGE_TYPE = \"banner\";\n\nexport interface BannerProps {\n filters?: UseInAppMessageOptions;\n}\n\nexport interface BannerContent {\n title: string;\n body: string;\n primary_button?: {\n text: string;\n action: string;\n };\n secondary_button?: {\n text: string;\n action: string;\n };\n dismissible?: boolean;\n}\n\nconst Root: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-banner\", className)} {...props}>\n {children}\n </div>\n );\n};\nRoot.displayName = \"BannerView.Root\";\n\nconst Content: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-banner__message\", className)} {...props}>\n {children}\n </div>\n );\n};\nContent.displayName = \"BannerView.Content\";\n\nconst Title: React.FC<\n { title: string } & React.ComponentPropsWithRef<\"div\">\n> = ({ title, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-banner__title\", className)} {...props}>\n {title}\n </div>\n );\n};\nTitle.displayName = \"BannerView.Title\";\n\nconst Body: React.FC<{ body: string } & React.ComponentPropsWithRef<\"div\">> = ({\n body,\n className,\n ...props\n}) => {\n return (\n <div\n className={clsx(\"knock-iam-banner__body\", className)}\n dangerouslySetInnerHTML={{ __html: body }}\n {...props}\n />\n );\n};\nBody.displayName = \"BannerView.Body\";\n\nconst Actions: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-banner__actions\", className)} {...props}>\n {children}\n </div>\n );\n};\nActions.displayName = \"BannerView.Actions\";\n\nconst PrimaryAction: React.FC<\n ActionContent & React.ComponentPropsWithRef<\"a\">\n> = ({ text, action, className, ...props }) => {\n return (\n <a\n href={action}\n className={clsx(\"knock-iam-banner__action\", className)}\n {...props}\n >\n {text}\n </a>\n );\n};\nPrimaryAction.displayName = \"BannerView.PrimaryAction\";\n\nconst SecondaryAction: React.FC<\n ActionContent & React.ComponentPropsWithRef<\"a\">\n> = ({ text, action, className, ...props }) => {\n return (\n <a\n href={action}\n className={clsx(\n \"knock-iam-banner__action knock-iam-banner__action--secondary\",\n className,\n )}\n {...props}\n >\n {text}\n </a>\n );\n};\nSecondaryAction.displayName = \"BannerView.SecondaryAction\";\n\nconst DismissButton: React.FC<React.ComponentPropsWithRef<\"button\">> = ({\n className,\n ...props\n}) => {\n return (\n <button className={clsx(\"knock-iam-banner__close\", className)} {...props}>\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"18\"\n height=\"18\"\n fill=\"none\"\n >\n <g fill=\"#60646C\" fillRule=\"evenodd\" clipRule=\"evenodd\">\n <path d=\"M14.03 3.97a.75.75 0 0 1 0 1.06l-9 9a.75.75 0 0 1-1.06-1.06l9-9a.75.75 0 0 1 1.06 0Z\" />\n <path d=\"M3.97 3.97a.75.75 0 0 1 1.06 0l9 9a.75.75 0 1 1-1.06 1.06l-9-9a.75.75 0 0 1 0-1.06Z\" />\n </g>\n </svg>\n </button>\n );\n};\nDismissButton.displayName = \"BannerView.DismissButton\";\n\nconst DefaultView: React.FC<{\n content: BannerContent;\n colorMode?: ColorMode;\n onInteract?: () => void;\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n}> = ({ content, colorMode = \"light\", onInteract, onDismiss }) => {\n return (\n <Root data-knock-color-mode={colorMode} onClick={onInteract}>\n <Content>\n <Title title={content.title} />\n <Body body={content.body} />\n </Content>\n <Actions>\n {content.secondary_button && (\n <SecondaryAction\n text={content.secondary_button.text}\n action={content.secondary_button.action}\n />\n )}\n\n {content.primary_button && (\n <PrimaryAction\n text={content.primary_button.text}\n action={content.primary_button.action}\n />\n )}\n\n {content.dismissible && <DismissButton onClick={onDismiss} />}\n </Actions>\n </Root>\n );\n};\nDefaultView.displayName = \"BannerView.Default\";\n\nconst Banner: React.FC<BannerProps> = ({ filters }) => {\n const { colorMode } = useInAppMessagesChannel();\n\n const { message, inAppMessagesClient } = useInAppMessage<BannerContent>(\n MESSAGE_TYPE,\n filters,\n );\n\n // Mark the message as seen on render\n useEffect(() => {\n if (!message || message.seen_at !== null) return;\n\n inAppMessagesClient.markAsSeen(message);\n }, [message, inAppMessagesClient]);\n\n // Exclude archived messages\n if (!message || message.archived_at) return null;\n\n const onDismiss = () => {\n inAppMessagesClient.markAsArchived(message);\n };\n\n const onInteract = () => {\n inAppMessagesClient.markAsInteracted(message);\n };\n\n return (\n <DefaultView\n content={message.content}\n colorMode={colorMode}\n onDismiss={onDismiss}\n onInteract={onInteract}\n />\n );\n};\nBanner.displayName = \"Banner\";\n\nconst BannerView = {} as {\n Default: typeof DefaultView;\n Root: typeof Root;\n Content: typeof Content;\n Title: typeof Title;\n Body: typeof Body;\n Actions: typeof Actions;\n PrimaryAction: typeof PrimaryAction;\n SecondaryAction: typeof SecondaryAction;\n DismissButton: typeof DismissButton;\n};\n\nObject.assign(BannerView, {\n Default: DefaultView,\n Root,\n Content,\n Title,\n Body,\n Actions,\n PrimaryAction,\n SecondaryAction,\n DismissButton,\n});\n\nexport { Banner, BannerView };\n"],"names":["MESSAGE_TYPE","Root","children","className","props","React","clsx","displayName","Content","Title","title","Body","body","__html","Actions","PrimaryAction","text","action","SecondaryAction","DismissButton","DefaultView","content","colorMode","onInteract","onDismiss","secondary_button","primary_button","dismissible","Banner","filters","useInAppMessagesChannel","message","inAppMessagesClient","useInAppMessage","useEffect","seen_at","markAsSeen","archived_at","markAsArchived","markAsInteracted","BannerView","Object","assign","Default"],"mappings":";;;;AAaA,MAAMA,IAAe,UAoBfC,IAEFA,CAAC;AAAA,EAAEC,UAAAA;AAAAA,EAAUC,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAEjCC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,oBAAoBH,CAAS,GAAG,GAAIC,EAAAA,GACtDF,CACH;AAGJD,EAAKM,cAAc;AAEnB,MAAMC,IAEFA,CAAC;AAAA,EAAEN,UAAAA;AAAAA,EAAUC,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAEjCC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,6BAA6BH,CAAS,GAAG,GAAIC,EAAAA,GAC/DF,CACH;AAGJM,EAAQD,cAAc;AAEtB,MAAME,IAEFA,CAAC;AAAA,EAAEC,OAAAA;AAAAA,EAAOP,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAE9BC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,2BAA2BH,CAAS,GAAG,GAAIC,EAAAA,GAC7DM,CACH;AAGJD,EAAMF,cAAc;AAEpB,MAAMI,IAAwEA,CAAC;AAAA,EAC7EC,MAAAA;AAAAA,EACAT,WAAAA;AAAAA,EACA,GAAGC;AACL,sCAEK,OACC,EAAA,WAAWE,EAAK,0BAA0BH,CAAS,GACnD,yBAAyB;AAAA,EAAEU,QAAQD;AAAAA,GAC/BR,GAAAA,EACJ,CAAA;AAGNO,EAAKJ,cAAc;AAEnB,MAAMO,IAEFA,CAAC;AAAA,EAAE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YAAAD,EACA,CAAA;AAEN;AACAK,EAAOrB,cAAc;AAErB,MAAMiC,IAAa,CAAC;AAYpBC,OAAOC,OAAOF,GAAY;AAAA,EACxBG,SAASvB;AAAAA,EACTnB,MAAAA;AAAAA,EACAO,SAAAA;AAAAA,EACAC,OAAAA;AAAAA,EACAE,MAAAA;AAAAA,EACAG,SAAAA;AAAAA,EACAC,eAAAA;AAAAA,EACAG,iBAAAA;AAAAA,EACAC,eAAAA;AACF,CAAC;"}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import { useInAppMessagesChannel as C, useInAppMessage as w } from "@knocklabs/react-core";
|
2
|
+
import c from "clsx";
|
3
|
+
import t, { useEffect as h } from "react";
|
4
|
+
/* empty css */
|
5
|
+
const f = "card", i = ({
|
6
|
+
children: e,
|
7
|
+
className: n,
|
8
|
+
...a
|
9
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card", n), ...a }, e);
|
10
|
+
i.displayName = "CardView.Root";
|
11
|
+
const l = ({
|
12
|
+
children: e,
|
13
|
+
className: n,
|
14
|
+
...a
|
15
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card__message", n), ...a }, e);
|
16
|
+
l.displayName = "CardView.Content";
|
17
|
+
const k = ({
|
18
|
+
children: e,
|
19
|
+
className: n,
|
20
|
+
...a
|
21
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card__header", n), ...a }, e);
|
22
|
+
k.displayName = "CardView.Header";
|
23
|
+
const y = ({
|
24
|
+
headline: e,
|
25
|
+
className: n,
|
26
|
+
...a
|
27
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card__headline", n), ...a }, e);
|
28
|
+
y.displayName = "CardView.Headline";
|
29
|
+
const s = ({
|
30
|
+
title: e,
|
31
|
+
className: n,
|
32
|
+
...a
|
33
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card__title", n), ...a }, e);
|
34
|
+
s.displayName = "CardView.Title";
|
35
|
+
const o = ({
|
36
|
+
body: e,
|
37
|
+
className: n,
|
38
|
+
...a
|
39
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card__body", n), dangerouslySetInnerHTML: {
|
40
|
+
__html: e
|
41
|
+
}, ...a });
|
42
|
+
o.displayName = "CardView.Body";
|
43
|
+
const m = ({
|
44
|
+
children: e,
|
45
|
+
className: n,
|
46
|
+
...a
|
47
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: c("knock-iam-card__actions", n), ...a }, e);
|
48
|
+
m.displayName = "CardView.Actions";
|
49
|
+
const d = ({
|
50
|
+
text: e,
|
51
|
+
action: n,
|
52
|
+
className: a,
|
53
|
+
...r
|
54
|
+
}) => /* @__PURE__ */ t.createElement("a", { href: n, className: c("knock-iam-card__action", a), ...r }, e);
|
55
|
+
d.displayName = "CardView.PrimaryAction";
|
56
|
+
const u = ({
|
57
|
+
text: e,
|
58
|
+
action: n,
|
59
|
+
className: a,
|
60
|
+
...r
|
61
|
+
}) => /* @__PURE__ */ t.createElement("a", { href: n, className: c("knock-iam-card__action knock-iam-card__action--secondary", a), ...r }, e);
|
62
|
+
u.displayName = "CardView.SecondaryAction";
|
63
|
+
const _ = ({
|
64
|
+
className: e,
|
65
|
+
...n
|
66
|
+
}) => /* @__PURE__ */ t.createElement("button", { className: c("knock-iam-card__close", e), ...n }, /* @__PURE__ */ t.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "18", height: "18", fill: "none" }, /* @__PURE__ */ t.createElement("g", { fill: "#60646C", fillRule: "evenodd", clipRule: "evenodd" }, /* @__PURE__ */ t.createElement("path", { d: "M14.03 3.97a.75.75 0 0 1 0 1.06l-9 9a.75.75 0 0 1-1.06-1.06l9-9a.75.75 0 0 1 1.06 0Z" }), /* @__PURE__ */ t.createElement("path", { d: "M3.97 3.97a.75.75 0 0 1 1.06 0l9 9a.75.75 0 1 1-1.06 1.06l-9-9a.75.75 0 0 1 0-1.06Z" }))));
|
67
|
+
_.displayName = "CardView.DismissButton";
|
68
|
+
const p = ({
|
69
|
+
content: e,
|
70
|
+
colorMode: n = "light",
|
71
|
+
onInteract: a,
|
72
|
+
onDismiss: r
|
73
|
+
}) => /* @__PURE__ */ t.createElement(i, { "data-knock-color-mode": n, onClick: a }, /* @__PURE__ */ t.createElement(l, null, /* @__PURE__ */ t.createElement(k, null, /* @__PURE__ */ t.createElement(y, { headline: e.headline }), e.dismissible && /* @__PURE__ */ t.createElement(_, { onClick: r })), /* @__PURE__ */ t.createElement(s, { title: e.title }), /* @__PURE__ */ t.createElement(o, { body: e.body })), /* @__PURE__ */ t.createElement(m, null, e.primary_button && /* @__PURE__ */ t.createElement(d, { text: e.primary_button.text, action: e.primary_button.action }), e.secondary_button && /* @__PURE__ */ t.createElement(u, { text: e.secondary_button.text, action: e.secondary_button.action })));
|
74
|
+
p.displayName = "CardView.Default";
|
75
|
+
const A = ({
|
76
|
+
filters: e
|
77
|
+
}) => {
|
78
|
+
const {
|
79
|
+
colorMode: n
|
80
|
+
} = C(), {
|
81
|
+
message: a,
|
82
|
+
inAppMessagesClient: r
|
83
|
+
} = w(f, e);
|
84
|
+
if (h(() => {
|
85
|
+
!a || a.seen_at !== null || r.markAsSeen(a);
|
86
|
+
}, [a, r]), !a || a.archived_at) return null;
|
87
|
+
const E = () => {
|
88
|
+
r.markAsArchived(a);
|
89
|
+
}, N = () => {
|
90
|
+
r.markAsInteracted(a);
|
91
|
+
};
|
92
|
+
return /* @__PURE__ */ t.createElement(p, { content: a.content, colorMode: n, onDismiss: E, onInteract: N });
|
93
|
+
};
|
94
|
+
A.displayName = "Card";
|
95
|
+
const g = {};
|
96
|
+
Object.assign(g, {
|
97
|
+
Default: p,
|
98
|
+
Root: i,
|
99
|
+
Content: l,
|
100
|
+
Title: s,
|
101
|
+
Body: o,
|
102
|
+
Actions: m,
|
103
|
+
PrimaryAction: d,
|
104
|
+
SecondaryAction: u,
|
105
|
+
DismissButton: _
|
106
|
+
});
|
107
|
+
export {
|
108
|
+
A as Card,
|
109
|
+
g as CardView
|
110
|
+
};
|
111
|
+
//# sourceMappingURL=Card.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Card.mjs","sources":["../../../../../../src/modules/in-app-messages/components/Card/Card.tsx"],"sourcesContent":["import {\n ColorMode,\n UseInAppMessageOptions,\n useInAppMessage,\n useInAppMessagesChannel,\n} from \"@knocklabs/react-core\";\nimport clsx from \"clsx\";\nimport React, { useEffect } from \"react\";\n\nimport { ActionContent } from \"../types\";\n\nimport \"./styles.css\";\n\nconst MESSAGE_TYPE = \"card\";\n\nexport interface CardProps {\n filters?: UseInAppMessageOptions;\n}\n\nexport interface CardContent {\n headline: string;\n title: string;\n body: string;\n primary_button?: {\n text: string;\n action: string;\n };\n secondary_button?: {\n text: string;\n action: string;\n };\n dismissible?: boolean;\n}\n\nconst Root: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-card\", className)} {...props}>\n {children}\n </div>\n );\n};\nRoot.displayName = \"CardView.Root\";\n\nconst Content: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-card__message\", className)} {...props}>\n {children}\n </div>\n );\n};\nContent.displayName = \"CardView.Content\";\n\nconst Header: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-card__header\", className)} {...props}>\n {children}\n </div>\n );\n};\nHeader.displayName = \"CardView.Header\";\n\nconst Headline: React.FC<\n { headline: string } & React.ComponentPropsWithRef<\"div\">\n> = ({ headline, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-card__headline\", className)} {...props}>\n {headline}\n </div>\n );\n};\nHeadline.displayName = \"CardView.Headline\";\n\nconst Title: React.FC<\n { title: string } & React.ComponentPropsWithRef<\"div\">\n> = ({ title, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-card__title\", className)} {...props}>\n {title}\n </div>\n );\n};\nTitle.displayName = \"CardView.Title\";\n\nconst Body: React.FC<{ body: string } & React.ComponentPropsWithRef<\"div\">> = ({\n body,\n className,\n ...props\n}) => {\n return (\n <div\n className={clsx(\"knock-iam-card__body\", className)}\n dangerouslySetInnerHTML={{ __html: body }}\n {...props}\n />\n );\n};\nBody.displayName = \"CardView.Body\";\n\nconst Actions: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-card__actions\", className)} {...props}>\n {children}\n </div>\n );\n};\nActions.displayName = \"CardView.Actions\";\n\nconst PrimaryAction: React.FC<\n ActionContent & React.ComponentPropsWithRef<\"a\">\n> = ({ text, action, className, ...props }) => {\n return (\n <a\n href={action}\n className={clsx(\"knock-iam-card__action\", className)}\n {...props}\n >\n {text}\n </a>\n );\n};\nPrimaryAction.displayName = \"CardView.PrimaryAction\";\n\nconst SecondaryAction: React.FC<\n ActionContent & React.ComponentPropsWithRef<\"a\">\n> = ({ text, action, className, ...props }) => {\n return (\n <a\n href={action}\n className={clsx(\n \"knock-iam-card__action knock-iam-card__action--secondary\",\n className,\n )}\n {...props}\n >\n {text}\n </a>\n );\n};\nSecondaryAction.displayName = \"CardView.SecondaryAction\";\n\nconst DismissButton: React.FC<React.ComponentPropsWithRef<\"button\">> = ({\n className,\n ...props\n}) => {\n return (\n <button className={clsx(\"knock-iam-card__close\", className)} {...props}>\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"18\"\n height=\"18\"\n fill=\"none\"\n >\n <g fill=\"#60646C\" fillRule=\"evenodd\" clipRule=\"evenodd\">\n <path d=\"M14.03 3.97a.75.75 0 0 1 0 1.06l-9 9a.75.75 0 0 1-1.06-1.06l9-9a.75.75 0 0 1 1.06 0Z\" />\n <path d=\"M3.97 3.97a.75.75 0 0 1 1.06 0l9 9a.75.75 0 1 1-1.06 1.06l-9-9a.75.75 0 0 1 0-1.06Z\" />\n </g>\n </svg>\n </button>\n );\n};\nDismissButton.displayName = \"CardView.DismissButton\";\n\nconst DefaultView: React.FC<{\n content: CardContent;\n colorMode?: ColorMode;\n onInteract?: () => void;\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n}> = ({ content, colorMode = \"light\", onInteract, onDismiss }) => {\n return (\n <Root data-knock-color-mode={colorMode} onClick={onInteract}>\n <Content>\n <Header>\n <Headline headline={content.headline} />\n {content.dismissible && <DismissButton onClick={onDismiss} />}\n </Header>\n\n <Title title={content.title} />\n <Body body={content.body} />\n </Content>\n <Actions>\n {content.primary_button && (\n <PrimaryAction\n text={content.primary_button.text}\n action={content.primary_button.action}\n />\n )}\n\n {content.secondary_button && (\n <SecondaryAction\n text={content.secondary_button.text}\n action={content.secondary_button.action}\n />\n )}\n </Actions>\n </Root>\n );\n};\nDefaultView.displayName = \"CardView.Default\";\n\nconst Card: React.FC<CardProps> = ({ filters }) => {\n const { colorMode } = useInAppMessagesChannel();\n const { message, inAppMessagesClient } = useInAppMessage<CardContent>(\n MESSAGE_TYPE,\n filters,\n );\n\n // Mark the message as seen on render\n useEffect(() => {\n if (!message || message.seen_at !== null) return;\n\n inAppMessagesClient.markAsSeen(message);\n }, [message, inAppMessagesClient]);\n\n // Exclude archived messages\n if (!message || message.archived_at) return null;\n\n const onDismiss = () => {\n inAppMessagesClient.markAsArchived(message);\n };\n\n const onInteract = () => {\n inAppMessagesClient.markAsInteracted(message);\n };\n\n return (\n <DefaultView\n content={message.content}\n colorMode={colorMode}\n onDismiss={onDismiss}\n onInteract={onInteract}\n />\n );\n};\nCard.displayName = \"Card\";\n\nconst CardView = {} as {\n Default: typeof DefaultView;\n Root: typeof Root;\n Content: typeof Content;\n Headline: typeof Headline;\n Title: typeof Title;\n Body: typeof Body;\n Actions: typeof Actions;\n PrimaryAction: typeof PrimaryAction;\n SecondaryAction: typeof SecondaryAction;\n DismissButton: typeof DismissButton;\n};\n\nObject.assign(CardView, {\n Default: DefaultView,\n Root,\n Content,\n Title,\n Body,\n Actions,\n PrimaryAction,\n SecondaryAction,\n DismissButton,\n});\n\nexport { Card, CardView };\n"],"names":["MESSAGE_TYPE","Root","children","className","props","React","clsx","displayName","Content","Header","Headline","headline","Title","title","Body","body","__html","Actions","PrimaryAction","text","action","SecondaryAction","DismissButton","DefaultView","content","colorMode","onInteract","onDismiss","dismissible","primary_button","secondary_button","Card","filters","useInAppMessagesChannel","message","inAppMessagesClient","useInAppMessage","useEffect","seen_at","markAsSeen","archived_at","markAsArchived","markAsInteracted","CardView","Object","assign","Default"],"mappings":";;;;AAaA,MAAMA,IAAe,QAqBfC,IAEFA,CAAC;AAAA,EAAEC,UAAAA;AAAAA,EAAUC,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAEjCC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,kBAAkBH,CAAS,GAAG,GAAIC,EAAAA,GACpDF,CACH;AAGJD,EAAKM,cAAc;AAEnB,MAAMC,IAEFA,CAAC;AAAA,EAAEN,UAAAA;AAAAA,EAAUC,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAEjCC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,2BAA2BH,CAAS,GAAG,GAAIC,EAAAA,GAC7DF,CACH;AAGJM,EAAQD,cAAc;AAEtB,MAAME,IAEFA,CAAC;AAAA,EAAEP,UAAAA;AAAAA,EAAUC,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAEjCC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,0BAA0BH,CAAS,GAAG,GAAIC,EAAAA,GAC5DF,CACH;AAGJO,EAAOF,cAAc;AAErB,MAAMG,IAEFA,CAAC;AAAA,EAAEC,UAAAA;AAAAA,EAAUR,WAAAA;AAAAA,EAAW,GAAGC;AAAM,MAEjCC,gBAAAA,EAAA,cAAC,SAAI,WAAWC,EAAK,4BAA4BH,CAAS,GAA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H,CACF;AAGJG,EAAYhB,cAAc;AAE1B,MAAMwB,IAA4BA,CAAC;AAAA,EAAEC,SAAAA;AAAQ,MAAM;AAC3C,QAAA;AAAA,IAAEP,WAAAA;AAAAA,MAAcQ,EAAwB,GACxC;AAAA,IAAEC,SAAAA;AAAAA,IAASC,qBAAAA;AAAAA,EAAAA,IAAwBC,EACvCpC,GACAgC,CACF;AAUA,MAPAK,EAAU,MAAM;AACd,IAAI,CAACH,KAAWA,EAAQI,YAAY,QAEpCH,EAAoBI,WAAWL,CAAO;AAAA,EAAA,GACrC,CAACA,GAASC,CAAmB,CAAC,GAG7B,CAACD,KAAWA,EAAQM,YAAoB,QAAA;AAE5C,QAAMb,IAAYA,MAAM;AACtBQ,IAAAA,EAAoBM,eAAeP,CAAO;AAAA,EAAA,GAGtCR,IAAaA,MAAM;AACvBS,IAAAA,EAAoBO,iBAAiBR,CAAO;AAAA,EAAA;AAG9C,yCACGX,GACC,EAAA,SAASW,EAAQV,SACjB,WAAAC,GACA,WAAAE,GACA,YAAAD,EACA,CAAA;AAEN;AACAK,EAAKxB,cAAc;AAEnB,MAAMoC,IAAW,CAAC;AAalBC,OAAOC,OAAOF,GAAU;AAAA,EACtBG,SAASvB;AAAAA,EACTtB,MAAAA;AAAAA,EACAO,SAAAA;AAAAA,EACAI,OAAAA;AAAAA,EACAE,MAAAA;AAAAA,EACAG,SAAAA;AAAAA,EACAC,eAAAA;AAAAA,EACAG,iBAAAA;AAAAA,EACAC,eAAAA;AACF,CAAC;"}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
import { useInAppMessagesChannel as h, useInAppMessage as A } from "@knocklabs/react-core";
|
2
|
+
import * as r from "@radix-ui/react-dialog";
|
3
|
+
import n from "clsx";
|
4
|
+
import t, { useEffect as g } from "react";
|
5
|
+
/* empty css */
|
6
|
+
const v = "modal", i = ({
|
7
|
+
children: e,
|
8
|
+
onOpenChange: l,
|
9
|
+
...a
|
10
|
+
}) => /* @__PURE__ */ t.createElement(r.Root, { defaultOpen: !0, onOpenChange: l, ...a }, /* @__PURE__ */ t.createElement(r.Portal, null, e));
|
11
|
+
i.displayName = "ModalView.Root";
|
12
|
+
const s = t.forwardRef(({
|
13
|
+
className: e,
|
14
|
+
...l
|
15
|
+
}, a) => /* @__PURE__ */ t.createElement(r.Overlay, { className: n("knock-iam-modal__overlay", e), ref: a, ...l }));
|
16
|
+
s.displayName = "ModalView.Overlay";
|
17
|
+
const m = t.forwardRef(({
|
18
|
+
children: e,
|
19
|
+
className: l,
|
20
|
+
...a
|
21
|
+
}, o) => /* @__PURE__ */ t.createElement(r.Content, { className: n("knock-iam-modal", l), ref: o, ...a }, e));
|
22
|
+
m.displayName = "ModalView.Content";
|
23
|
+
const f = ({
|
24
|
+
children: e,
|
25
|
+
className: l,
|
26
|
+
...a
|
27
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: n("knock-iam-modal__header", l), ...a }, e);
|
28
|
+
f.displayName = "ModalView.Header";
|
29
|
+
const d = ({
|
30
|
+
title: e,
|
31
|
+
className: l,
|
32
|
+
...a
|
33
|
+
}) => /* @__PURE__ */ t.createElement(r.Title, { className: n("knock-iam-modal__title", l), ...a }, e);
|
34
|
+
d.displayName = "ModalView.Title";
|
35
|
+
const u = ({
|
36
|
+
body: e,
|
37
|
+
className: l,
|
38
|
+
...a
|
39
|
+
}) => /* @__PURE__ */ t.createElement(r.Description, { className: n("knock-iam-modal__body", l), dangerouslySetInnerHTML: {
|
40
|
+
__html: e
|
41
|
+
}, ...a });
|
42
|
+
u.displayName = "ModalView.Body";
|
43
|
+
const p = ({
|
44
|
+
children: e,
|
45
|
+
className: l,
|
46
|
+
...a
|
47
|
+
}) => /* @__PURE__ */ t.createElement("div", { className: n("knock-iam-modal__actions", l), ...a }, e);
|
48
|
+
p.displayName = "ModalView.Actions";
|
49
|
+
const y = ({
|
50
|
+
text: e,
|
51
|
+
action: l,
|
52
|
+
className: a,
|
53
|
+
...o
|
54
|
+
}) => /* @__PURE__ */ t.createElement("a", { href: l, className: n("knock-iam-modal__action", a), ...o }, e);
|
55
|
+
y.displayName = "ModalView.PrimaryAction";
|
56
|
+
const _ = ({
|
57
|
+
text: e,
|
58
|
+
action: l,
|
59
|
+
className: a,
|
60
|
+
...o
|
61
|
+
}) => /* @__PURE__ */ t.createElement("a", { href: l, className: n("knock-iam-modal__action knock-iam-modal__action--secondary", a), ...o }, e);
|
62
|
+
_.displayName = "ModalView.SecondaryAction";
|
63
|
+
const E = ({
|
64
|
+
className: e,
|
65
|
+
...l
|
66
|
+
}) => /* @__PURE__ */ t.createElement(r.Close, { className: n("knock-iam-modal__close", e), ...l }, /* @__PURE__ */ t.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "18", height: "18", fill: "none" }, /* @__PURE__ */ t.createElement("g", { fill: "#60646C", fillRule: "evenodd", clipRule: "evenodd" }, /* @__PURE__ */ t.createElement("path", { d: "M14.03 3.97a.75.75 0 0 1 0 1.06l-9 9a.75.75 0 0 1-1.06-1.06l9-9a.75.75 0 0 1 1.06 0Z" }), /* @__PURE__ */ t.createElement("path", { d: "M3.97 3.97a.75.75 0 0 1 1.06 0l9 9a.75.75 0 1 1-1.06 1.06l-9-9a.75.75 0 0 1 0-1.06Z" }))));
|
67
|
+
E.displayName = "ModalView.Close";
|
68
|
+
const k = ({
|
69
|
+
content: e,
|
70
|
+
colorMode: l = "light",
|
71
|
+
onOpenChange: a,
|
72
|
+
onInteract: o,
|
73
|
+
onDismiss: c
|
74
|
+
}) => /* @__PURE__ */ t.createElement(i, { onOpenChange: a, onClick: o }, /* @__PURE__ */ t.createElement(s, null), /* @__PURE__ */ t.createElement(m, { "data-knock-color-mode": l }, /* @__PURE__ */ t.createElement(f, null, /* @__PURE__ */ t.createElement(d, { title: e.title }), e.dismissible && /* @__PURE__ */ t.createElement(E, { onClick: c })), /* @__PURE__ */ t.createElement(u, { body: e.body }), /* @__PURE__ */ t.createElement(p, null, e.secondary_button && /* @__PURE__ */ t.createElement(_, { text: e.secondary_button.text, action: e.secondary_button.action }), e.primary_button && /* @__PURE__ */ t.createElement(y, { text: e.primary_button.text, action: e.primary_button.action }))));
|
75
|
+
k.displayName = "ModalView.Default";
|
76
|
+
const V = ({
|
77
|
+
filters: e
|
78
|
+
}) => {
|
79
|
+
const {
|
80
|
+
colorMode: l
|
81
|
+
} = h(), {
|
82
|
+
message: a,
|
83
|
+
inAppMessagesClient: o
|
84
|
+
} = A(v, e);
|
85
|
+
if (g(() => {
|
86
|
+
!a || a.seen_at !== null || o.markAsSeen(a);
|
87
|
+
}, [a, o]), !a || a.archived_at) return null;
|
88
|
+
const c = (w) => {
|
89
|
+
w || o.markAsArchived(a);
|
90
|
+
}, M = () => {
|
91
|
+
o.markAsArchived(a);
|
92
|
+
}, N = () => {
|
93
|
+
o.markAsInteracted(a);
|
94
|
+
};
|
95
|
+
return /* @__PURE__ */ t.createElement(k, { content: a.content, colorMode: l, onOpenChange: c, onDismiss: M, onInteract: N });
|
96
|
+
};
|
97
|
+
V.displayName = "Modal";
|
98
|
+
const C = {};
|
99
|
+
Object.assign(C, {
|
100
|
+
Default: k,
|
101
|
+
Root: i,
|
102
|
+
Overlay: s,
|
103
|
+
Content: m,
|
104
|
+
Title: d,
|
105
|
+
Body: u,
|
106
|
+
Actions: p,
|
107
|
+
PrimaryAction: y,
|
108
|
+
SecondaryAction: _,
|
109
|
+
Close: E
|
110
|
+
});
|
111
|
+
export {
|
112
|
+
V as Modal,
|
113
|
+
C as ModalView
|
114
|
+
};
|
115
|
+
//# sourceMappingURL=Modal.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Modal.mjs","sources":["../../../../../../src/modules/in-app-messages/components/Modal/Modal.tsx"],"sourcesContent":["import {\n ColorMode,\n UseInAppMessageOptions,\n useInAppMessage,\n useInAppMessagesChannel,\n} from \"@knocklabs/react-core\";\nimport * as Dialog from \"@radix-ui/react-dialog\";\nimport clsx from \"clsx\";\nimport React, { useEffect } from \"react\";\n\nimport { ActionContent } from \"../types\";\n\nimport \"./styles.css\";\n\nconst MESSAGE_TYPE = \"modal\";\n\nexport interface ModalProps {\n filters?: UseInAppMessageOptions;\n}\n\nexport interface ModalContent {\n title: string;\n body: string;\n primary_button?: {\n text: string;\n action: string;\n };\n secondary_button?: {\n text: string;\n action: string;\n };\n dismissible?: boolean;\n}\n\ntype RootProps = Omit<\n React.ComponentPropsWithoutRef<typeof Dialog.Root>,\n \"modal\"\n> &\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>;\n\nconst Root = ({ children, onOpenChange, ...props }: RootProps) => {\n return (\n <Dialog.Root defaultOpen onOpenChange={onOpenChange} {...props}>\n <Dialog.Portal>{children}</Dialog.Portal>\n </Dialog.Root>\n );\n};\nRoot.displayName = \"ModalView.Root\";\n\ntype OverlayProps = React.ComponentPropsWithoutRef<typeof Dialog.Overlay> &\n React.ComponentPropsWithRef<\"div\">;\ntype OverlayRef = React.ElementRef<\"div\">;\n\n// TODO: Causes layout shift...\nconst Overlay = React.forwardRef<OverlayRef, OverlayProps>(\n ({ className, ...props }, forwardedRef) => {\n return (\n <Dialog.Overlay\n className={clsx(\"knock-iam-modal__overlay\", className)}\n ref={forwardedRef}\n {...props}\n />\n );\n },\n);\nOverlay.displayName = \"ModalView.Overlay\";\n\ntype ContentProps = React.ComponentPropsWithoutRef<typeof Dialog.Content> &\n React.ComponentPropsWithRef<\"div\">;\ntype ContentRef = React.ElementRef<\"div\">;\n\nconst Content = React.forwardRef<ContentRef, ContentProps>(\n ({ children, className, ...props }, forwardedRef) => {\n return (\n <Dialog.Content\n className={clsx(\"knock-iam-modal\", className)}\n ref={forwardedRef}\n {...props}\n >\n {children}\n </Dialog.Content>\n );\n },\n);\nContent.displayName = \"ModalView.Content\";\n\nconst Header: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-modal__header\", className)} {...props}>\n {children}\n </div>\n );\n};\nHeader.displayName = \"ModalView.Header\";\n\ntype TitleProps = React.ComponentPropsWithoutRef<typeof Dialog.Title> &\n React.ComponentPropsWithRef<\"div\"> & {\n title: string;\n };\n\nconst Title = ({ title, className, ...props }: TitleProps) => {\n return (\n <Dialog.Title\n className={clsx(\"knock-iam-modal__title\", className)}\n {...props}\n >\n {title}\n </Dialog.Title>\n );\n};\nTitle.displayName = \"ModalView.Title\";\n\nconst Body: React.FC<{ body: string } & React.ComponentPropsWithRef<\"div\">> = ({\n body,\n className,\n ...props\n}) => {\n return (\n <Dialog.Description\n className={clsx(\"knock-iam-modal__body\", className)}\n dangerouslySetInnerHTML={{ __html: body }}\n {...props}\n />\n );\n};\nBody.displayName = \"ModalView.Body\";\n\nconst Actions: React.FC<\n React.PropsWithChildren<React.ComponentPropsWithRef<\"div\">>\n> = ({ children, className, ...props }) => {\n return (\n <div className={clsx(\"knock-iam-modal__actions\", className)} {...props}>\n {children}\n </div>\n );\n};\nActions.displayName = \"ModalView.Actions\";\n\nconst PrimaryAction: React.FC<\n ActionContent & React.ComponentPropsWithRef<\"a\">\n> = ({ text, action, className, ...props }) => {\n return (\n <a\n href={action}\n className={clsx(\"knock-iam-modal__action\", className)}\n {...props}\n >\n {text}\n </a>\n );\n};\nPrimaryAction.displayName = \"ModalView.PrimaryAction\";\n\nconst SecondaryAction: React.FC<\n ActionContent & React.ComponentPropsWithRef<\"a\">\n> = ({ text, action, className, ...props }) => {\n return (\n <a\n href={action}\n className={clsx(\n \"knock-iam-modal__action knock-iam-modal__action--secondary\",\n className,\n )}\n {...props}\n >\n {text}\n </a>\n );\n};\nSecondaryAction.displayName = \"ModalView.SecondaryAction\";\n\ntype CloseProps = React.ComponentPropsWithoutRef<typeof Dialog.Close> &\n React.ComponentPropsWithRef<\"button\">;\n\nconst Close = ({ className, ...props }: CloseProps) => {\n return (\n <Dialog.Close\n className={clsx(\"knock-iam-modal__close\", className)}\n {...props}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"18\"\n height=\"18\"\n fill=\"none\"\n >\n <g fill=\"#60646C\" fillRule=\"evenodd\" clipRule=\"evenodd\">\n <path d=\"M14.03 3.97a.75.75 0 0 1 0 1.06l-9 9a.75.75 0 0 1-1.06-1.06l9-9a.75.75 0 0 1 1.06 0Z\" />\n <path d=\"M3.97 3.97a.75.75 0 0 1 1.06 0l9 9a.75.75 0 1 1-1.06 1.06l-9-9a.75.75 0 0 1 0-1.06Z\" />\n </g>\n </svg>\n </Dialog.Close>\n );\n};\nClose.displayName = \"ModalView.Close\";\n\nconst DefaultView: React.FC<{\n content: ModalContent;\n colorMode?: ColorMode;\n onOpenChange?: (open: boolean) => void;\n onInteract?: () => void;\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n}> = ({\n content,\n colorMode = \"light\",\n onOpenChange,\n onInteract,\n onDismiss,\n}) => {\n return (\n <Root onOpenChange={onOpenChange} onClick={onInteract}>\n <Overlay />\n {/* Must pass color mode to content for css variables to be set properly */}\n <Content data-knock-color-mode={colorMode}>\n <Header>\n <Title title={content.title} />\n {content.dismissible && <Close onClick={onDismiss} />}\n </Header>\n\n <Body body={content.body} />\n\n <Actions>\n {content.secondary_button && (\n <SecondaryAction\n text={content.secondary_button.text}\n action={content.secondary_button.action}\n />\n )}\n {content.primary_button && (\n <PrimaryAction\n text={content.primary_button.text}\n action={content.primary_button.action}\n />\n )}\n </Actions>\n </Content>\n </Root>\n );\n};\nDefaultView.displayName = \"ModalView.Default\";\n\nconst Modal: React.FC<ModalProps> = ({ filters }) => {\n const { colorMode } = useInAppMessagesChannel();\n const { message, inAppMessagesClient } = useInAppMessage<ModalContent>(\n MESSAGE_TYPE,\n filters,\n );\n\n // Mark the message as seen on render\n useEffect(() => {\n if (!message || message.seen_at !== null) return;\n\n inAppMessagesClient.markAsSeen(message);\n }, [message, inAppMessagesClient]);\n\n // Exclude archived messages\n if (!message || message.archived_at) return null;\n\n const onOpenChange = (open: boolean) => {\n if (!open) {\n inAppMessagesClient.markAsArchived(message);\n }\n };\n\n const onDismiss = () => {\n inAppMessagesClient.markAsArchived(message);\n };\n\n const onInteract = () => {\n inAppMessagesClient.markAsInteracted(message);\n };\n\n return (\n <DefaultView\n content={message.content}\n colorMode={colorMode}\n onOpenChange={onOpenChange}\n onDismiss={onDismiss}\n onInteract={onInteract}\n />\n );\n};\nModal.displayName = \"Modal\";\n\nconst ModalView = {} as {\n Default: typeof DefaultView;\n Root: typeof Root;\n Overlay: typeof Overlay;\n Content: typeof Content;\n Title: typeof Title;\n Body: typeof Body;\n Actions: typeof Actions;\n PrimaryAction: typeof PrimaryAction;\n SecondaryAction: typeof SecondaryAction;\n Close: typeof Close;\n};\n\nObject.assign(ModalView, {\n Default: DefaultView,\n Root,\n Overlay,\n Content,\n Title,\n Body,\n Actions,\n PrimaryAction,\n SecondaryAction,\n Close,\n});\n\nexport { Modal, ModalView };\n"],"names":["MESSAGE_TYPE","Root","children","onOpenChange","props","React","Dialog","displayName","Overlay","forwardRef","className","forwardedRef","clsx","Content","Header","Title","title","Body","body","__html","Actions","PrimaryAction","text","action","SecondaryAction","Close","DefaultView","content","colorMode","onInteract","onDismiss","dismissible","secondary_button","primary_button","Modal","filters","useInAppMessagesChannel","message","inAppMessagesClient","useInAppMessage","useEffect","seen_at","markAsSeen","archived_at","open","markAsArchived","markAsInteracted","ModalView","Object","assign","Default"],"mappings":";;;;;AAcA,MAAMA,IAAe,SA0BfC,IAAOA,CAAC;AAAA,EAAEC,UAAAA;AAAAA,EAAUC,cAAAA;AAAAA,EAAc,GAAGC;AAAiB,MAEvDC,gBAAAA,EAAA,cAAAC,EAAO,MAAP,EAAY,aAAW,IAAC,cAAAH,GAA4B,GAAIC,EAAAA,GACtDC,gBAAAA,EAAA,cAAAC,EAAO,QAAP,MAAeJ,CAAS,CAC3B;AAGJD,EAAKM,cAAc;AAOnB,MAAMC,IAAUH,EAAMI,WACpB,CAAC;AAAA,EAAEC,WAAAA;AAAAA,EAAW,GAAGN;AAAM,GAAGO,MAErBN,gBAAAA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AiBT,CAAO;AAAA,EAAA;AAI5C,SAAAhC,gBAAAA,EAAA,cAACqB,KACC,SAASW,EAAQV,SACjB,WAAAC,GACA,cAAAzB,GACA,WAAA2B,GACA,YAAAD,EACA,CAAA;AAEN;AACAK,EAAM3B,cAAc;AAEpB,MAAMwC,IAAY,CAAC;AAanBC,OAAOC,OAAOF,GAAW;AAAA,EACvBG,SAASxB;AAAAA,EACTzB,MAAAA;AAAAA,EACAO,SAAAA;AAAAA,EACAK,SAAAA;AAAAA,EACAE,OAAAA;AAAAA,EACAE,MAAAA;AAAAA,EACAG,SAAAA;AAAAA,EACAC,eAAAA;AAAAA,EACAG,iBAAAA;AAAAA,EACAC,OAAAA;AACF,CAAC;"}
|
@@ -19,10 +19,10 @@ const w = (u) => {
|
|
19
19
|
connectionStatus: n,
|
20
20
|
setActionLabel: o,
|
21
21
|
actionLabel: i,
|
22
|
-
errorLabel:
|
22
|
+
errorLabel: p
|
23
23
|
} = L(), {
|
24
24
|
buildSlackAuthUrl: m,
|
25
|
-
disconnectFromSlack:
|
25
|
+
disconnectFromSlack: _
|
26
26
|
} = S(u, h, d);
|
27
27
|
b(() => {
|
28
28
|
const k = (a) => {
|
@@ -38,7 +38,7 @@ const w = (u) => {
|
|
38
38
|
};
|
39
39
|
}, [r.host, s, c]);
|
40
40
|
const g = t("slackDisconnect") || null, E = t("slackReconnect") || null;
|
41
|
-
return n === "connecting" || n === "disconnecting" ? /* @__PURE__ */ e.createElement("div", { className: "rsk-connect__button rsk-connect__button--loading" }, /* @__PURE__ */ e.createElement(l, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t(n === "connecting" ? "slackConnecting" : "slackDisconnecting"))) : n === "error" ? /* @__PURE__ */ e.createElement("button", { onClick: () => w(m()), className: "rsk-connect__button rsk-connect__button--error", onMouseEnter: () => o(E), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(l, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rsk-connect__button__text--error" }, i ||
|
41
|
+
return n === "connecting" || n === "disconnecting" ? /* @__PURE__ */ e.createElement("div", { className: "rsk-connect__button rsk-connect__button--loading" }, /* @__PURE__ */ e.createElement(l, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t(n === "connecting" ? "slackConnecting" : "slackDisconnecting"))) : n === "error" ? /* @__PURE__ */ e.createElement("button", { onClick: () => w(m()), className: "rsk-connect__button rsk-connect__button--error", onMouseEnter: () => o(E), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(l, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rsk-connect__button__text--error" }, i || p || t("slackError"))) : n === "disconnected" ? /* @__PURE__ */ e.createElement("button", { onClick: () => w(m()), className: "rsk-connect__button rsk-connect__button--disconnected" }, /* @__PURE__ */ e.createElement(l, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t("slackConnect"))) : /* @__PURE__ */ e.createElement("button", { onClick: _, className: "rsk-connect__button rsk-connect__button--connected", onMouseEnter: () => o(g), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(l, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rsk-connect__button__text--connected" }, i || t("slackConnected")));
|
42
42
|
};
|
43
43
|
export {
|
44
44
|
H as SlackAuthButton
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SlackAuthButton.mjs","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"sourcesContent":["import {\n useKnockClient,\n useKnockSlackClient,\n useSlackAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent } from \"react\";\nimport { useEffect } from \"react\";\n\nimport \"../../theme.css\";\nimport { SlackIcon } from \"../SlackIcon\";\n\nimport \"./styles.css\";\n\nexport interface SlackAuthButtonProps {\n slackClientId: string;\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n additionalScopes?: string[];\n}\n\nconst openSlackOauthPopup = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"Slack OAuth\", features);\n};\n\nexport const SlackAuthButton: FunctionComponent<SlackAuthButtonProps> = ({\n slackClientId,\n redirectUrl,\n onAuthenticationComplete,\n additionalScopes,\n}) => {\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n } = useKnockSlackClient();\n\n const { buildSlackAuthUrl, disconnectFromSlack } = useSlackAuth(\n slackClientId,\n redirectUrl,\n additionalScopes,\n );\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n if (event.origin !== knock.host) {\n return;\n }\n\n try {\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n }\n\n if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n }\n\n if (onAuthenticationComplete) {\n onAuthenticationComplete(event.data);\n }\n } catch (
|
1
|
+
{"version":3,"file":"SlackAuthButton.mjs","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"sourcesContent":["import {\n useKnockClient,\n useKnockSlackClient,\n useSlackAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent } from \"react\";\nimport { useEffect } from \"react\";\n\nimport \"../../theme.css\";\nimport { SlackIcon } from \"../SlackIcon\";\n\nimport \"./styles.css\";\n\nexport interface SlackAuthButtonProps {\n slackClientId: string;\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n additionalScopes?: string[];\n}\n\nconst openSlackOauthPopup = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"Slack OAuth\", features);\n};\n\nexport const SlackAuthButton: FunctionComponent<SlackAuthButtonProps> = ({\n slackClientId,\n redirectUrl,\n onAuthenticationComplete,\n additionalScopes,\n}) => {\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n } = useKnockSlackClient();\n\n const { buildSlackAuthUrl, disconnectFromSlack } = useSlackAuth(\n slackClientId,\n redirectUrl,\n additionalScopes,\n );\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n if (event.origin !== knock.host) {\n return;\n }\n\n try {\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n }\n\n if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n }\n\n if (onAuthenticationComplete) {\n onAuthenticationComplete(event.data);\n }\n } catch (error) {\n setConnectionStatus(\"error\");\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n\n // Cleanup the event listener when the component unmounts\n return () => {\n window.removeEventListener(\"message\", receiveMessage);\n };\n }, [knock.host, onAuthenticationComplete, setConnectionStatus]);\n\n const disconnectLabel = t(\"slackDisconnect\") || null;\n const reconnectLabel = t(\"slackReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rsk-connect__button rsk-connect__button--loading\">\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"slackConnecting\")\n : t(\"slackDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => openSlackOauthPopup(buildSlackAuthUrl())}\n className=\"rsk-connect__button rsk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"slackError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => openSlackOauthPopup(buildSlackAuthUrl())}\n className=\"rsk-connect__button rsk-connect__button--disconnected\"\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"slackConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromSlack}\n className=\"rsk-connect__button rsk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--connected\">\n {actionLabel || t(\"slackConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["openSlackOauthPopup","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","SlackAuthButton","slackClientId","redirectUrl","onAuthenticationComplete","additionalScopes","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","useKnockSlackClient","buildSlackAuthUrl","disconnectFromSlack","useSlackAuth","useEffect","receiveMessage","event","origin","host","data","addEventListener","removeEventListener","disconnectLabel","reconnectLabel","React","SlackIcon"],"mappings":";;;;;AAqBA,MAAMA,IAAsBA,CAACC,MAAgB;AAIrCC,QAAAA,IAAaC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