@frak-labs/components 0.0.26-beta.b38eef2e → 0.0.26-beta.c7fe645d

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 (42) hide show
  1. package/cdn/Banner.BMHoJgnV.js +1 -0
  2. package/cdn/ButtonShare.C9bOZeuc.js +1 -0
  3. package/cdn/ButtonWallet.CABXtQ4V.js +40 -0
  4. package/cdn/OpenInAppButton.BmF8AXhC.js +1 -0
  5. package/cdn/PostPurchase.DRJyOBDO.js +2362 -0
  6. package/cdn/components.js +1 -1
  7. package/cdn/formatReward.DXMr8a-D.js +1 -0
  8. package/cdn/jsxRuntime.module.C6YjWAqO.js +138 -0
  9. package/cdn/loader.css +0 -14
  10. package/cdn/loader.js +66 -1
  11. package/cdn/useLightDomStyles.bAfmSfzH.js +1 -0
  12. package/cdn/useReward.DDCWUZkL.js +1 -0
  13. package/cdn/useShareModal.CeIpyobm.js +1 -0
  14. package/dist/banner.d.ts +115 -0
  15. package/dist/banner.js +195 -0
  16. package/dist/buttonShare.d.ts +8 -6
  17. package/dist/buttonShare.js +60 -101
  18. package/dist/buttonWallet.d.ts +10 -2
  19. package/dist/buttonWallet.js +79 -38
  20. package/dist/formatReward-_UYA3aHE.js +26 -0
  21. package/dist/openInApp.d.ts +4 -2
  22. package/dist/openInApp.js +23 -27
  23. package/dist/postPurchase.d.ts +122 -0
  24. package/dist/postPurchase.js +2995 -0
  25. package/dist/useLightDomStyles-utGwQ5Gs.js +41 -0
  26. package/dist/usePlacement-BKWDIvXP.js +329 -0
  27. package/dist/useReward-XF2hB_C_.js +65 -0
  28. package/dist/useShareModal-Bmlk3eBJ.js +53 -0
  29. package/package.json +27 -17
  30. package/cdn/ButtonShare.CSPl5Bi5.js +0 -1
  31. package/cdn/ButtonWallet.3Hp62hGr.js +0 -1
  32. package/cdn/OpenInAppButton.BTvukMkp.js +0 -1
  33. package/cdn/Spinner.DQogVqic.js +0 -1
  34. package/cdn/initFrakSdk.CMgrZQwQ.js +0 -14
  35. package/cdn/useClientReady.CKKC4IMk.js +0 -1
  36. package/dist/Spinner-Btnwk01x.js +0 -36
  37. package/dist/Spinner-CHZD3tMn.css +0 -1
  38. package/dist/buttonShare.css +0 -1
  39. package/dist/buttonWallet.css +0 -1
  40. package/dist/openInApp.css +0 -1
  41. package/dist/useClientReady-0vKBG0-p.js +0 -197
  42. package/dist/useReward-DAkT-7wT.js +0 -48
@@ -0,0 +1 @@
1
+ import{t as e}from"./loader.js";import{a as t,u as n}from"./jsxRuntime.module.C6YjWAqO.js";function r(r,i,a,o){n(()=>{e.injectBase(r,o??t)},[r]),n(()=>{!i||!a||e.injectPlacement(r,i,a)},[r,i,a])}export{r as t};
@@ -0,0 +1 @@
1
+ import{_ as e,b as t,l as n}from"./loader.js";import{c as r,u as i}from"./jsxRuntime.module.C6YjWAqO.js";import{t as a}from"./formatReward.DXMr8a-D.js";function o(e,t){switch(e.payoutType){case`fixed`:return e.amount[t];case`tiered`:return e.tiers.reduce((e,n)=>Math.max(e,n.amount[t]),0);case`percentage`:return 0}}function s({rewards:n},r,i){let s=(i?n.filter(e=>e.interactionTypeKey===i):n).map(e=>e.referrer).filter(e=>e!==void 0);if(s.length===0)return;let c=t(e(r)),l=s[0],u=o(l,c);for(let e=1;e<s.length;e++){let t=o(s[e],c);t>u&&(l=s[e],u=t)}if(u<=0){let e=s.find(e=>e.payoutType===`percentage`);if(!e)return;l=e}return a(l,r)}function c(e,t){let[a,o]=r(void 0);return i(()=>{if(!e)return;let r=window.FrakSetup?.client;r&&n(r).then(e=>{let n=r.config.metadata?.currency,i=s(e,n,t);i&&o(i)}).catch(()=>{})},[e,t]),{reward:a}}export{c as t};
@@ -0,0 +1 @@
1
+ import{C as e,S as t,u as n,v as r,w as i}from"./loader.js";import{c as a,l as o}from"./jsxRuntime.module.C6YjWAqO.js";function s(s,c,l){let[u,d]=a(void 0),[f,p]=a(!1);return{handleShare:o(async()=>{if(!window.FrakSetup?.client){console.error(`Frak client not found`),d(r.empty().formatDebugInfo(`Frak client not found`)),p(!0);return}let a=n(window.FrakSetup.client,{});try{await a.sharing(l?{link:l}:{}).display(e=>({...e,targetInteraction:s}),c)}catch(n){if(n instanceof i&&n.code===e.clientAborted){console.debug(`User aborted the modal`);return}let r=window.FrakSetup.client.debugInfo.formatDebugInfo(n);t(window.FrakSetup.client,`share_modal_error`,{error:n instanceof Object&&`message`in n?n.message:`Unknown error`,debugInfo:r}),d(r),p(!0),console.error(`Error while opening the modal`,n)}},[s,c,l]),isError:f,debugInfo:u}}export{s as t};
@@ -0,0 +1,115 @@
1
+ import { InteractionTypeKey } from "@frak-labs/core-sdk";
2
+ import * as _$preact from "preact";
3
+
4
+ //#region src/components/Banner/types.d.ts
5
+ /**
6
+ * The props type for {@link Banner}.
7
+ * @inline
8
+ */
9
+ type BannerProps = {
10
+ /**
11
+ * Placement ID for backend-driven CSS customization.
12
+ */
13
+ placement?: string;
14
+ /**
15
+ * CSS class names passed through to the root element (Light DOM).
16
+ */
17
+ classname?: string;
18
+ /**
19
+ * Filter rewards by interaction type (e.g. "purchase", "referral").
20
+ * When omitted, the best reward across all interaction types is shown.
21
+ */
22
+ interaction?: InteractionTypeKey;
23
+ /**
24
+ * Override the referral banner title.
25
+ */
26
+ referralTitle?: string;
27
+ /**
28
+ * Override the referral banner description.
29
+ */
30
+ referralDescription?: string;
31
+ /**
32
+ * Override the referral banner CTA button text.
33
+ */
34
+ referralCta?: string;
35
+ /**
36
+ * Override the in-app browser banner title.
37
+ */
38
+ inappTitle?: string;
39
+ /**
40
+ * Override the in-app browser banner description.
41
+ */
42
+ inappDescription?: string;
43
+ /**
44
+ * Override the in-app browser banner CTA button text.
45
+ */
46
+ inappCta?: string;
47
+ /**
48
+ * When set, forces the banner to render in preview mode (e.g. in Shopify theme editor).
49
+ * Bypasses normal event/browser detection and shows static content.
50
+ */
51
+ preview?: string;
52
+ /**
53
+ * Which banner variant to preview: "referral" or "inapp".
54
+ * Only used when {@link preview} is set. Defaults to "referral".
55
+ */
56
+ previewMode?: "referral" | "inapp";
57
+ };
58
+ //#endregion
59
+ //#region src/components/Banner/Banner.d.ts
60
+ /**
61
+ * Auto-detecting notification banner component.
62
+ *
63
+ * Renders an inline banner on the merchant page that auto-detects which
64
+ * message to display:
65
+ *
66
+ * - **Referral mode**: Shown after successful referral link processing.
67
+ * Displays reward info and a dismiss button ("Got it").
68
+ * - **In-app browser mode**: Shown when the page is opened inside a social
69
+ * media in-app browser (Instagram, Facebook). Offers a redirect to the
70
+ * default browser.
71
+ *
72
+ * In-app browser mode takes priority over referral mode.
73
+ * Uses Light DOM to inherit merchant page styles.
74
+ *
75
+ * @group components
76
+ *
77
+ * @example
78
+ * Basic usage (auto-detects mode):
79
+ * ```html
80
+ * <frak-banner></frak-banner>
81
+ * ```
82
+ *
83
+ * @example
84
+ * With a custom class:
85
+ * ```html
86
+ * <frak-banner classname="my-custom-banner"></frak-banner>
87
+ * ```
88
+ */
89
+ declare function Banner({
90
+ placement: placementId,
91
+ classname,
92
+ interaction,
93
+ referralTitle: propReferralTitle,
94
+ referralDescription: propReferralDescription,
95
+ referralCta: propReferralCta,
96
+ inappTitle: propInappTitle,
97
+ inappDescription: propInappDescription,
98
+ inappCta: propInappCta,
99
+ preview,
100
+ previewMode
101
+ }: BannerProps): _$preact.JSX.Element | null;
102
+ //#endregion
103
+ //#region src/components/Banner/index.d.ts
104
+ /**
105
+ * Custom element interface for `<frak-banner>`.
106
+ * Combines standard {@link HTMLElement} with {@link BannerProps}.
107
+ */
108
+ interface BannerElement extends HTMLElement, BannerProps {}
109
+ declare global {
110
+ interface HTMLElementTagNameMap {
111
+ "frak-banner": BannerElement;
112
+ }
113
+ }
114
+ //#endregion
115
+ export { Banner, BannerElement };
package/dist/banner.js ADDED
@@ -0,0 +1,195 @@
1
+ import { a as useClientReady, n as bannerBaseCss, o as registerWebComponent, t as usePlacement } from "./usePlacement-BKWDIvXP.js";
2
+ import { t as useLightDomStyles } from "./useLightDomStyles-utGwQ5Gs.js";
3
+ import { t as useReward } from "./useReward-XF2hB_C_.js";
4
+ import { isInAppBrowser, redirectToExternalBrowser } from "@frak-labs/core-sdk";
5
+ import { REFERRAL_SUCCESS_EVENT } from "@frak-labs/core-sdk/actions";
6
+ import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
7
+ import { jsx, jsxs } from "preact/jsx-runtime";
8
+ //#region src/components/Banner/Banner.tsx
9
+ /**
10
+ * Reward/gift icon for referral mode.
11
+ */
12
+ function RewardIcon() {
13
+ return /* @__PURE__ */ jsxs("svg", {
14
+ viewBox: "0 0 24 24",
15
+ fill: "none",
16
+ stroke: "currentColor",
17
+ "stroke-width": "1.5",
18
+ "stroke-linecap": "round",
19
+ "stroke-linejoin": "round",
20
+ "aria-hidden": "true",
21
+ children: [
22
+ /* @__PURE__ */ jsx("rect", {
23
+ x: "3",
24
+ y: "11",
25
+ width: "18",
26
+ height: "11",
27
+ rx: "1"
28
+ }),
29
+ /* @__PURE__ */ jsx("path", { d: "M12 11v11" }),
30
+ /* @__PURE__ */ jsx("rect", {
31
+ x: "5",
32
+ y: "7",
33
+ width: "14",
34
+ height: "4",
35
+ rx: "1"
36
+ }),
37
+ /* @__PURE__ */ jsx("path", { d: "M12 7c0 0-1.5-4-4.5-4S5 5 7.5 7" }),
38
+ /* @__PURE__ */ jsx("path", { d: "M12 7c0 0 1.5-4 4.5-4S19 5 16.5 7" })
39
+ ]
40
+ });
41
+ }
42
+ /**
43
+ * External link icon for in-app browser mode.
44
+ */
45
+ function BrowserIcon() {
46
+ return /* @__PURE__ */ jsxs("svg", {
47
+ viewBox: "0 0 24 24",
48
+ fill: "none",
49
+ stroke: "currentColor",
50
+ "stroke-width": "1.5",
51
+ "stroke-linecap": "round",
52
+ "stroke-linejoin": "round",
53
+ "aria-hidden": "true",
54
+ children: [
55
+ /* @__PURE__ */ jsx("path", { d: "M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6" }),
56
+ /* @__PURE__ */ jsx("polyline", { points: "15 3 21 3 21 9" }),
57
+ /* @__PURE__ */ jsx("line", {
58
+ x1: "10",
59
+ y1: "14",
60
+ x2: "21",
61
+ y2: "3"
62
+ })
63
+ ]
64
+ });
65
+ }
66
+ /**
67
+ * Auto-detecting notification banner component.
68
+ *
69
+ * Renders an inline banner on the merchant page that auto-detects which
70
+ * message to display:
71
+ *
72
+ * - **Referral mode**: Shown after successful referral link processing.
73
+ * Displays reward info and a dismiss button ("Got it").
74
+ * - **In-app browser mode**: Shown when the page is opened inside a social
75
+ * media in-app browser (Instagram, Facebook). Offers a redirect to the
76
+ * default browser.
77
+ *
78
+ * In-app browser mode takes priority over referral mode.
79
+ * Uses Light DOM to inherit merchant page styles.
80
+ *
81
+ * @group components
82
+ *
83
+ * @example
84
+ * Basic usage (auto-detects mode):
85
+ * ```html
86
+ * <frak-banner></frak-banner>
87
+ * ```
88
+ *
89
+ * @example
90
+ * With a custom class:
91
+ * ```html
92
+ * <frak-banner classname="my-custom-banner"></frak-banner>
93
+ * ```
94
+ */
95
+ function Banner({ placement: placementId, classname = "", interaction, referralTitle: propReferralTitle, referralDescription: propReferralDescription, referralCta: propReferralCta, inappTitle: propInappTitle, inappDescription: propInappDescription, inappCta: propInappCta, preview, previewMode }) {
96
+ const isPreview = !!preview;
97
+ const resolvedPreviewMode = previewMode === "inapp" ? "inapp" : "referral";
98
+ const placement = usePlacement(placementId);
99
+ const { shouldRender, isHidden, isClientReady } = useClientReady();
100
+ useLightDomStyles("frak-banner", placementId, placement?.components?.banner?.css, bannerBaseCss);
101
+ const [dismissed, setDismissed] = useState(false);
102
+ const [mode, setMode] = useState(() => {
103
+ if (isPreview) return resolvedPreviewMode;
104
+ return isInAppBrowser ? "inapp" : null;
105
+ });
106
+ useEffect(() => {
107
+ if (isPreview) setMode(resolvedPreviewMode);
108
+ }, [isPreview, resolvedPreviewMode]);
109
+ const { reward } = useReward(mode === "referral" && isClientReady, interaction);
110
+ useEffect(() => {
111
+ if (isPreview || mode === "inapp") return;
112
+ const handler = () => setMode("referral");
113
+ window.addEventListener(REFERRAL_SUCCESS_EVENT, handler);
114
+ return () => window.removeEventListener(REFERRAL_SUCCESS_EVENT, handler);
115
+ }, [isPreview, mode]);
116
+ const handleAction = useCallback(() => {
117
+ if (isPreview) return;
118
+ if (mode === "referral") setDismissed(true);
119
+ else redirectToExternalBrowser(window.location.href);
120
+ }, [isPreview, mode]);
121
+ const bannerConfig = placement?.components?.banner;
122
+ const texts = useMemo(() => {
123
+ if (mode === "referral") {
124
+ const defaultTitle = reward ? `Earn ${reward} on purchases on this site` : "You've been referred!";
125
+ return {
126
+ title: propReferralTitle ?? bannerConfig?.referralTitle ?? defaultTitle,
127
+ description: propReferralDescription ?? bannerConfig?.referralDescription ?? "Earn rewards after your purchase via the Frak partner app.",
128
+ cta: propReferralCta ?? bannerConfig?.referralCta ?? "Got it"
129
+ };
130
+ }
131
+ return {
132
+ title: propInappTitle ?? bannerConfig?.inappTitle ?? "Open in your browser",
133
+ description: propInappDescription ?? bannerConfig?.inappDescription ?? "For a better experience and to earn your rewards, open this page in your default browser.",
134
+ cta: propInappCta ?? bannerConfig?.inappCta ?? "Open browser"
135
+ };
136
+ }, [
137
+ mode,
138
+ reward,
139
+ bannerConfig,
140
+ propReferralTitle,
141
+ propReferralDescription,
142
+ propReferralCta,
143
+ propInappTitle,
144
+ propInappDescription,
145
+ propInappCta
146
+ ]);
147
+ if (!isPreview && (!shouldRender || isHidden || dismissed || !mode)) return null;
148
+ return /* @__PURE__ */ jsxs("div", {
149
+ class: [
150
+ "frak-banner",
151
+ "frak-banner__fadeIn",
152
+ classname
153
+ ].filter(Boolean).join(" "),
154
+ role: "alert",
155
+ children: [
156
+ /* @__PURE__ */ jsx("div", {
157
+ class: "frak-banner__icon",
158
+ children: mode === "referral" ? /* @__PURE__ */ jsx(RewardIcon, {}) : /* @__PURE__ */ jsx(BrowserIcon, {})
159
+ }),
160
+ /* @__PURE__ */ jsxs("div", {
161
+ class: "frak-banner__content",
162
+ children: [/* @__PURE__ */ jsx("p", {
163
+ class: "frak-banner__title",
164
+ children: texts.title
165
+ }), /* @__PURE__ */ jsx("p", {
166
+ class: "frak-banner__description",
167
+ children: texts.description
168
+ })]
169
+ }),
170
+ /* @__PURE__ */ jsx("button", {
171
+ type: "button",
172
+ class: "frak-banner__cta",
173
+ onClick: handleAction,
174
+ children: texts.cta
175
+ })
176
+ ]
177
+ });
178
+ }
179
+ //#endregion
180
+ //#region src/components/Banner/index.ts
181
+ registerWebComponent(Banner, "frak-banner", [
182
+ "placement",
183
+ "classname",
184
+ "interaction",
185
+ "referralTitle",
186
+ "referralDescription",
187
+ "referralCta",
188
+ "inappTitle",
189
+ "inappDescription",
190
+ "inappCta",
191
+ "preview",
192
+ "previewMode"
193
+ ], { shadow: false });
194
+ //#endregion
195
+ export { Banner };
@@ -1,5 +1,5 @@
1
1
  import { InteractionTypeKey } from "@frak-labs/core-sdk";
2
- import * as preact from "preact";
2
+ import * as _$preact from "preact";
3
3
 
4
4
  //#region src/components/ButtonShare/types.d.ts
5
5
  /**
@@ -7,6 +7,7 @@ import * as preact from "preact";
7
7
  * @inline
8
8
  */
9
9
  type ButtonShareProps = {
10
+ placement?: string;
10
11
  /**
11
12
  * Text to display on the button
12
13
  * - To specify where the reward should be displayed, use the placeholder `{REWARD}`, e.g. `Share and earn up to \{REWARD\}!`
@@ -31,10 +32,10 @@ type ButtonShareProps = {
31
32
  */
32
33
  targetInteraction?: InteractionTypeKey;
33
34
  /**
34
- * Do we display the wallet modal instead of the share modal?
35
- * @defaultValue `false`
35
+ * Which UI to open on click
36
+ * @defaultValue `"embedded-wallet"`
36
37
  */
37
- showWallet?: boolean;
38
+ clickAction?: "embedded-wallet" | "share-modal" | "sharing-page";
38
39
  };
39
40
  //#endregion
40
41
  //#region src/components/ButtonShare/ButtonShare.d.ts
@@ -80,13 +81,14 @@ type ButtonShareProps = {
80
81
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
81
82
  */
82
83
  declare function ButtonShare({
84
+ placement: placementId,
83
85
  text,
84
86
  classname,
85
87
  useReward: rawUseReward,
86
88
  noRewardText,
87
89
  targetInteraction,
88
- showWallet: rawShowWallet
89
- }: ButtonShareProps): preact.JSX.Element;
90
+ clickAction: rawClickAction
91
+ }: ButtonShareProps): _$preact.JSX.Element | null;
90
92
  //#endregion
91
93
  //#region src/components/ButtonShare/index.d.ts
92
94
  /**
@@ -1,17 +1,19 @@
1
- import { n as registerWebComponent, r as getModalBuilderSteps, t as useClientReady } from "./useClientReady-0vKBG0-p.js";
2
- import { t as Spinner } from "./Spinner-Btnwk01x.js";
3
- import { t as useReward } from "./useReward-DAkT-7wT.js";
4
- import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
5
- import { displayEmbeddedWallet } from "@frak-labs/core-sdk/actions";
6
- import { cx } from "class-variance-authority";
1
+ import { a as useClientReady, c as openEmbeddedWallet, o as registerWebComponent, t as usePlacement } from "./usePlacement-BKWDIvXP.js";
2
+ import { t as useLightDomStyles } from "./useLightDomStyles-utGwQ5Gs.js";
3
+ import { t as useReward } from "./useReward-XF2hB_C_.js";
4
+ import { t as useShareModal } from "./useShareModal-Bmlk3eBJ.js";
5
+ import { trackEvent } from "@frak-labs/core-sdk";
6
+ import { displaySharingPage } from "@frak-labs/core-sdk/actions";
7
7
  import { useCallback, useMemo, useState } from "preact/hooks";
8
8
  import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
9
- import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
10
-
11
- //#region src/components/ButtonShare/ButtonShare.module.css?css_module
12
- const classes = { "buttonShare": "nOB7Uq_buttonShare" };
13
- const _buttonShare0 = classes["buttonShare"];
14
-
9
+ //#region src/utils/sharingPage.ts
10
+ async function openSharingPage(targetInteraction, placement) {
11
+ if (!window.FrakSetup?.client) {
12
+ console.error("Frak client not found");
13
+ return;
14
+ }
15
+ await displaySharingPage(window.FrakSetup.client, { metadata: { ...targetInteraction && { targetInteraction } } }, placement);
16
+ }
15
17
  //#endregion
16
18
  //#region src/hooks/useCopyToClipboard.ts
17
19
  function useCopyToClipboard(options = {}) {
@@ -53,7 +55,6 @@ function useCopyToClipboard(options = {}) {
53
55
  copied
54
56
  };
55
57
  }
56
-
57
58
  //#endregion
58
59
  //#region src/components/ButtonShare/components/ErrorMessage.tsx
59
60
  const styles = {
@@ -164,66 +165,9 @@ function ErrorMessage({ debugInfo }) {
164
165
  ]
165
166
  });
166
167
  }
167
-
168
- //#endregion
169
- //#region src/components/ButtonShare/hooks/useShareModal.ts
170
- /**
171
- * Open the share modal
172
- *
173
- * @description
174
- * This function will open the share modal with the configuration provided in the `window.FrakSetup.modalShareConfig` object.
175
- */
176
- function useShareModal(targetInteraction) {
177
- const [debugInfo, setDebugInfo] = useState(void 0);
178
- const [isError, setIsError] = useState(false);
179
- return {
180
- handleShare: useCallback(async () => {
181
- if (!window.FrakSetup?.client) {
182
- console.error("Frak client not found");
183
- setDebugInfo(DebugInfoGatherer.empty().formatDebugInfo("Frak client not found"));
184
- setIsError(true);
185
- return;
186
- }
187
- const modalBuilderSteps = getModalBuilderSteps();
188
- if (!modalBuilderSteps) throw new Error("modalBuilderSteps not found");
189
- try {
190
- await modalBuilderSteps.sharing(window.FrakSetup?.modalShareConfig ?? {}).display((metadata) => ({
191
- ...metadata,
192
- targetInteraction
193
- }));
194
- } catch (e) {
195
- if (e instanceof FrakRpcError && e.code === RpcErrorCodes.clientAborted) {
196
- console.debug("User aborted the modal");
197
- return;
198
- }
199
- const debugInfo = window.FrakSetup.client.debugInfo.formatDebugInfo(e);
200
- trackEvent(window.FrakSetup.client, "share_modal_error", {
201
- error: e instanceof Object && "message" in e ? e.message : "Unknown error",
202
- debugInfo
203
- });
204
- setDebugInfo(debugInfo);
205
- setIsError(true);
206
- console.error("Error while opening the modal", e);
207
- }
208
- }, [targetInteraction]),
209
- isError,
210
- debugInfo
211
- };
212
- }
213
-
214
168
  //#endregion
215
169
  //#region src/components/ButtonShare/ButtonShare.tsx
216
170
  /**
217
- * Open the embedded wallet modal
218
- *
219
- * @description
220
- * This function will open the wallet modal with the configuration provided in the `window.FrakSetup.modalWalletConfig` object.
221
- */
222
- async function modalEmbeddedWallet() {
223
- if (!window.FrakSetup?.client) throw new Error("Frak client not found");
224
- await displayEmbeddedWallet(window.FrakSetup.client, window.FrakSetup?.modalWalletConfig ?? {});
225
- }
226
- /**
227
171
  * Button to share the current page
228
172
  *
229
173
  * @param args
@@ -264,48 +208,63 @@ async function modalEmbeddedWallet() {
264
208
  * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
265
209
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
266
210
  */
267
- function ButtonShare({ text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction, showWallet: rawShowWallet }) {
268
- const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
269
- const showWallet = useMemo(() => rawShowWallet !== void 0, [rawShowWallet]);
270
- const { isClientReady } = useClientReady();
271
- const { reward } = useReward(shouldUseReward && isClientReady, targetInteraction);
272
- const { handleShare, isError, debugInfo } = useShareModal(targetInteraction);
273
- /**
274
- * Compute the text we will display
275
- */
211
+ function ButtonShare({ placement: placementId, text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction, clickAction: rawClickAction }) {
212
+ const placement = usePlacement(placementId);
213
+ const componentConfig = placement?.components?.buttonShare;
214
+ useLightDomStyles("frak-button-share", placementId, componentConfig?.css);
215
+ const resolvedTargetInteraction = useMemo(() => placement?.targetInteraction !== void 0 ? placement.targetInteraction : targetInteraction, [placement?.targetInteraction, targetInteraction]);
216
+ const resolvedText = componentConfig?.text ?? text;
217
+ const resolvedNoRewardText = componentConfig?.noRewardText ?? noRewardText;
218
+ const shouldUseReward = useMemo(() => componentConfig?.useReward ?? rawUseReward === true, [componentConfig?.useReward, rawUseReward]);
219
+ const resolvedClickAction = useMemo(() => componentConfig?.clickAction ?? rawClickAction ?? "sharing-page", [componentConfig?.clickAction, rawClickAction]);
220
+ const { shouldRender, isHidden, isClientReady } = useClientReady();
221
+ const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
222
+ const { handleShare, isError, debugInfo } = useShareModal(resolvedTargetInteraction, placementId);
276
223
  const btnText = useMemo(() => {
277
- if (!shouldUseReward) return text;
278
- if (!reward) return noRewardText ?? text.replace("{REWARD}", "");
279
- return text.includes("{REWARD}") ? text.replace("{REWARD}", reward) : `${text} ${reward}`;
224
+ if (!shouldUseReward) return resolvedText;
225
+ if (!reward) return resolvedNoRewardText ?? resolvedText.replace("{REWARD}", "");
226
+ return resolvedText.includes("{REWARD}") ? resolvedText.replace("{REWARD}", reward) : `${resolvedText} ${reward}`;
280
227
  }, [
281
228
  shouldUseReward,
282
- text,
283
- noRewardText,
229
+ resolvedText,
230
+ resolvedNoRewardText,
284
231
  reward
285
232
  ]);
286
- /**
287
- * The action when the button is clicked
288
- */
289
233
  const onClick = useCallback(async () => {
290
234
  trackEvent(window.FrakSetup.client, "share_button_clicked");
291
- if (showWallet) await modalEmbeddedWallet();
292
- else await handleShare();
293
- }, [showWallet, handleShare]);
294
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
235
+ if (resolvedClickAction === "embedded-wallet") openEmbeddedWallet(resolvedTargetInteraction, placementId);
236
+ else if (resolvedClickAction === "share-modal") await handleShare();
237
+ else openSharingPage(resolvedTargetInteraction, placementId);
238
+ }, [
239
+ resolvedClickAction,
240
+ handleShare,
241
+ resolvedTargetInteraction,
242
+ placementId
243
+ ]);
244
+ if (!shouldRender || isHidden) return null;
245
+ const buttonClass = [
246
+ "button",
247
+ "button__fadeIn",
248
+ classname
249
+ ].filter(Boolean).join(" ");
250
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
295
251
  type: "button",
296
- className: cx(classes.buttonShare, classname, "override"),
252
+ disabled: !isClientReady,
253
+ class: buttonClass,
297
254
  onClick,
298
- children: [
299
- !isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
300
- " ",
301
- btnText
302
- ]
255
+ children: btnText
303
256
  }), isError && /* @__PURE__ */ jsx(ErrorMessage, { debugInfo })] });
304
257
  }
305
-
306
258
  //#endregion
307
259
  //#region src/components/ButtonShare/index.ts
308
- registerWebComponent(ButtonShare, "frak-button-share", ["text"], { shadow: false });
309
-
260
+ registerWebComponent(ButtonShare, "frak-button-share", [
261
+ "text",
262
+ "placement",
263
+ "classname",
264
+ "clickAction",
265
+ "useReward",
266
+ "noRewardText",
267
+ "targetInteraction"
268
+ ], { shadow: false });
310
269
  //#endregion
311
- export { ButtonShare };
270
+ export { ButtonShare };
@@ -1,5 +1,5 @@
1
1
  import { InteractionTypeKey } from "@frak-labs/core-sdk";
2
- import * as preact from "preact";
2
+ import * as _$preact from "preact";
3
3
 
4
4
  //#region src/components/ButtonWallet/types.d.ts
5
5
  /**
@@ -7,6 +7,7 @@ import * as preact from "preact";
7
7
  * @inline
8
8
  */
9
9
  type ButtonWalletProps = {
10
+ placement?: string;
10
11
  /**
11
12
  * Classname to apply to the button
12
13
  */
@@ -55,14 +56,21 @@ type ButtonWalletProps = {
55
56
  * <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
56
57
  * ```
57
58
  *
59
+ * @example
60
+ * Using placement:
61
+ * ```html
62
+ * <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
63
+ * ```
64
+ *
58
65
  * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
59
66
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
60
67
  */
61
68
  declare function ButtonWallet({
69
+ placement: placementId,
62
70
  classname,
63
71
  useReward: rawUseReward,
64
72
  targetInteraction
65
- }: ButtonWalletProps): preact.JSX.Element;
73
+ }: ButtonWalletProps): _$preact.JSX.Element | null;
66
74
  //#endregion
67
75
  //#region src/components/ButtonWallet/index.d.ts
68
76
  /**