@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
@@ -1,10 +1,8 @@
1
- import { i as openWalletModal, n as registerWebComponent, t as useClientReady } from "./useClientReady-0vKBG0-p.js";
2
- import { t as useReward } from "./useReward-DAkT-7wT.js";
1
+ import { a as useClientReady, o as registerWebComponent, r as buildStyleContent, s as openWalletModal, t as usePlacement } from "./usePlacement-BKWDIvXP.js";
2
+ import { t as useReward } from "./useReward-XF2hB_C_.js";
3
3
  import { trackEvent } from "@frak-labs/core-sdk";
4
- import { cx } from "class-variance-authority";
5
4
  import { useEffect, useMemo, useState } from "preact/hooks";
6
- import { jsx, jsxs } from "preact/jsx-runtime";
7
-
5
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
8
6
  //#region src/components/ButtonWallet/assets/GiftIcon.tsx
9
7
  function GiftIcon(props) {
10
8
  return /* @__PURE__ */ jsxs("svg", {
@@ -22,22 +20,48 @@ function GiftIcon(props) {
22
20
  })]
23
21
  });
24
22
  }
25
-
26
- //#endregion
27
- //#region src/components/ButtonWallet/ButtonWallet.module.css?css_module
28
- const classes = {
29
- "button__left": "Kl62ia_button__left",
30
- "button__right": "Kl62ia_button__right",
31
- "button": "Kl62ia_button",
32
- "reward": "Kl62ia_reward"
33
- };
34
- const _button__left0 = classes["button__left"];
35
- const _button__right0 = classes["button__right"];
36
- const _button0 = classes["button"];
37
- const _reward0 = classes["reward"];
38
-
39
23
  //#endregion
40
24
  //#region src/components/ButtonWallet/ButtonWallet.tsx
25
+ const componentCss = `
26
+ .button {
27
+ all: unset;
28
+ position: fixed;
29
+ bottom: 20px;
30
+ z-index: 2000000;
31
+ display: flex;
32
+ justify-content: center;
33
+ align-items: center;
34
+ background-color: #3e557e;
35
+ width: 45px;
36
+ height: 45px;
37
+ border-radius: 50%;
38
+ cursor: pointer;
39
+ text-align: center;
40
+ font-size: 24px;
41
+ }
42
+
43
+ .button__left {
44
+ left: 20px;
45
+ }
46
+
47
+ .button__right {
48
+ right: 20px;
49
+ }
50
+
51
+ .reward {
52
+ position: absolute;
53
+ top: -4px;
54
+ right: 27px;
55
+ padding: 2px 3px;
56
+ border-radius: 5px;
57
+ background: #ff3f3f;
58
+ font-size: 9px;
59
+ color: #fff;
60
+ font-weight: 600;
61
+ white-space: nowrap;
62
+ line-height: 9px;
63
+ }
64
+ `;
41
65
  /**
42
66
  * Button to open wallet modal
43
67
  *
@@ -70,40 +94,57 @@ const _reward0 = classes["reward"];
70
94
  * <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
71
95
  * ```
72
96
  *
97
+ * @example
98
+ * Using placement:
99
+ * ```html
100
+ * <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
101
+ * ```
102
+ *
73
103
  * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
74
104
  * @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
75
105
  */
76
- function ButtonWallet({ classname = "", useReward: rawUseReward, targetInteraction }) {
77
- const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
78
- const { isClientReady } = useClientReady();
79
- const { reward } = useReward(shouldUseReward && isClientReady, targetInteraction);
106
+ function ButtonWallet({ placement: placementId, classname = "", useReward: rawUseReward, targetInteraction }) {
107
+ const placement = usePlacement(placementId);
108
+ const resolvedTargetInteraction = useMemo(() => placement?.targetInteraction !== void 0 ? placement.targetInteraction : targetInteraction, [placement?.targetInteraction, targetInteraction]);
109
+ const shouldUseReward = useMemo(() => rawUseReward === true, [rawUseReward]);
110
+ const { shouldRender, isHidden, isClientReady } = useClientReady();
111
+ const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
80
112
  const [position, setPosition] = useState("right");
81
- /**
82
- * Setup the position of the button
83
- */
84
113
  useEffect(() => {
85
- const position = window.FrakSetup?.modalWalletConfig?.metadata?.position;
86
- setPosition(position ?? "right");
87
- }, []);
88
- return /* @__PURE__ */ jsxs("button", {
114
+ const placementPosition = placement?.components?.buttonWallet?.position;
115
+ const configPosition = window.FrakSetup?.modalWalletConfig?.metadata?.position;
116
+ setPosition(placementPosition ?? configPosition ?? "right");
117
+ }, [placement?.components?.buttonWallet?.position]);
118
+ if (!shouldRender || isHidden) return null;
119
+ const buttonClass = [
120
+ "button",
121
+ "button__fadeIn",
122
+ position === "left" ? "button__left" : "button__right",
123
+ classname
124
+ ].filter(Boolean).join(" ");
125
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("style", { children: buildStyleContent(componentCss, placement?.components?.buttonWallet?.css) }), /* @__PURE__ */ jsxs("button", {
89
126
  type: "button",
90
127
  "aria-label": "Open wallet",
91
- class: cx(classes.button, position === "left" ? classes.button__left : classes.button__right, classname, "override"),
128
+ part: "button",
92
129
  disabled: !isClientReady,
130
+ class: buttonClass,
93
131
  onClick: () => {
94
132
  trackEvent(window.FrakSetup.client, "wallet_button_clicked");
95
- openWalletModal();
133
+ openWalletModal(resolvedTargetInteraction, placementId);
96
134
  },
97
135
  children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
98
- className: classes.reward,
136
+ class: "reward",
99
137
  children: reward
100
138
  })]
101
- });
139
+ })] });
102
140
  }
103
-
104
141
  //#endregion
105
142
  //#region src/components/ButtonWallet/index.ts
106
- registerWebComponent(ButtonWallet, "frak-button-wallet", [], { shadow: false });
107
-
143
+ registerWebComponent(ButtonWallet, "frak-button-wallet", [
144
+ "placement",
145
+ "classname",
146
+ "useReward",
147
+ "targetInteraction"
148
+ ], { shadow: true });
108
149
  //#endregion
109
- export { ButtonWallet };
150
+ export { ButtonWallet };
@@ -0,0 +1,26 @@
1
+ import { formatAmount, getCurrencyAmountKey, getSupportedCurrency } from "@frak-labs/core-sdk";
2
+ //#region src/utils/formatReward.ts
3
+ /**
4
+ * Format an {@link EstimatedReward} into a human-readable string.
5
+ *
6
+ * - `fixed` → e.g. `"5 €"`
7
+ * - `percentage` → if `basketAmount` is provided, computes the actual value
8
+ * (e.g. `"10 €"`), otherwise returns `"10 %"`
9
+ * - `tiered` → max tier value, e.g. `"50 €"`
10
+ */
11
+ function formatEstimatedReward(reward, currency, basketAmount) {
12
+ const supportedCurrency = getSupportedCurrency(currency);
13
+ const key = getCurrencyAmountKey(supportedCurrency);
14
+ switch (reward.payoutType) {
15
+ case "fixed": return formatAmount(Math.round(reward.amount[key]), supportedCurrency);
16
+ case "percentage":
17
+ if (basketAmount !== void 0) return formatAmount(Math.round(reward.percent * basketAmount / 100), supportedCurrency);
18
+ return `${reward.percent} %`;
19
+ case "tiered": {
20
+ const max = reward.tiers.reduce((acc, tier) => Math.max(acc, tier.amount[key]), 0);
21
+ return formatAmount(Math.round(max), supportedCurrency);
22
+ }
23
+ }
24
+ }
25
+ //#endregion
26
+ export { formatEstimatedReward as t };
@@ -1,4 +1,4 @@
1
- import * as preact from "preact";
1
+ import * as _$preact from "preact";
2
2
 
3
3
  //#region src/components/OpenInAppButton/types.d.ts
4
4
  /**
@@ -6,6 +6,7 @@ import * as preact from "preact";
6
6
  * @inline
7
7
  */
8
8
  type OpenInAppButtonProps = {
9
+ placement?: string;
9
10
  /**
10
11
  * Text to display on the button
11
12
  * @defaultValue `"Open in App"`
@@ -45,9 +46,10 @@ type OpenInAppButtonProps = {
45
46
  * ```
46
47
  */
47
48
  declare function OpenInAppButton({
49
+ placement: placementId,
48
50
  text,
49
51
  classname
50
- }: OpenInAppButtonProps): preact.JSX.Element | null;
52
+ }: OpenInAppButtonProps): _$preact.JSX.Element | null;
51
53
  //#endregion
52
54
  //#region src/components/OpenInAppButton/index.d.ts
53
55
  /**
package/dist/openInApp.js CHANGED
@@ -1,10 +1,8 @@
1
- import { n as registerWebComponent, t as useClientReady } from "./useClientReady-0vKBG0-p.js";
2
- import { t as Spinner } from "./Spinner-Btnwk01x.js";
1
+ import { a as useClientReady, o as registerWebComponent, t as usePlacement } from "./usePlacement-BKWDIvXP.js";
2
+ import { t as useLightDomStyles } from "./useLightDomStyles-utGwQ5Gs.js";
3
3
  import { DEEP_LINK_SCHEME, trackEvent, triggerDeepLinkWithFallback } from "@frak-labs/core-sdk";
4
- import { cx } from "class-variance-authority";
5
4
  import { useMemo } from "preact/hooks";
6
- import { jsx, jsxs } from "preact/jsx-runtime";
7
-
5
+ import { jsx } from "preact/jsx-runtime";
8
6
  //#region src/utils/isMobile.ts
9
7
  /**
10
8
  * Check if the current device is a mobile device
@@ -21,13 +19,11 @@ function isMobile() {
21
19
  if (/Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints > 1) return true;
22
20
  return false;
23
21
  }
24
-
25
22
  //#endregion
26
23
  //#region src/hooks/useIsMobile.ts
27
24
  function useIsMobile() {
28
25
  return { isMobile: useMemo(() => isMobile(), []) };
29
26
  }
30
-
31
27
  //#endregion
32
28
  //#region src/utils/openInApp.ts
33
29
  const DEFAULT_PATH = "wallet";
@@ -47,12 +43,6 @@ function openFrakWalletApp(path = DEFAULT_PATH) {
47
43
  if (client) trackEvent(client, "app_not_installed");
48
44
  } });
49
45
  }
50
-
51
- //#endregion
52
- //#region src/components/OpenInAppButton/OpenInAppButton.module.css?css_module
53
- const classes = { "button": "XYfqGq_button" };
54
- const _button0 = classes["button"];
55
-
56
46
  //#endregion
57
47
  //#region src/components/OpenInAppButton/OpenInAppButton.tsx
58
48
  /**
@@ -81,30 +71,36 @@ const _button0 = classes["button"];
81
71
  * <frak-open-in-app classname="button button-primary"></frak-open-in-app>
82
72
  * ```
83
73
  */
84
- function OpenInAppButton({ text = "Open in App", classname = "" }) {
85
- const { isClientReady } = useClientReady();
74
+ function OpenInAppButton({ placement: placementId, text = "Open in App", classname = "" }) {
75
+ const placement = usePlacement(placementId);
76
+ const { shouldRender, isHidden, isClientReady } = useClientReady();
86
77
  const { isMobile } = useIsMobile();
87
- if (!isMobile) return null;
78
+ useLightDomStyles("frak-open-in-app", placementId, placement?.components?.openInApp?.css);
79
+ const resolvedText = placement?.components?.openInApp?.text ?? text;
80
+ if (!isMobile || !shouldRender || isHidden) return null;
88
81
  const handleClick = () => {
89
82
  openFrakWalletApp();
90
83
  };
91
- return /* @__PURE__ */ jsxs("button", {
84
+ const buttonClass = [
85
+ "button",
86
+ "button__fadeIn",
87
+ classname
88
+ ].filter(Boolean).join(" ");
89
+ return /* @__PURE__ */ jsx("button", {
92
90
  type: "button",
93
91
  "aria-label": "Open in Frak Wallet app",
94
- className: cx(classes.button, classname, "override"),
95
92
  disabled: !isClientReady,
93
+ class: buttonClass,
96
94
  onClick: handleClick,
97
- children: [
98
- !isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
99
- " ",
100
- text
101
- ]
95
+ children: resolvedText
102
96
  });
103
97
  }
104
-
105
98
  //#endregion
106
99
  //#region src/components/OpenInAppButton/index.ts
107
- registerWebComponent(OpenInAppButton, "frak-open-in-app", ["text"], { shadow: false });
108
-
100
+ registerWebComponent(OpenInAppButton, "frak-open-in-app", [
101
+ "text",
102
+ "placement",
103
+ "classname"
104
+ ], { shadow: false });
109
105
  //#endregion
110
- export { OpenInAppButton };
106
+ export { OpenInAppButton };
@@ -0,0 +1,122 @@
1
+ import * as _$preact from "preact";
2
+
3
+ //#region src/components/PostPurchase/types.d.ts
4
+ /**
5
+ * Props for the {@link PostPurchase} component.
6
+ * @inline
7
+ */
8
+ type PostPurchaseProps = {
9
+ /**
10
+ * Merchant customer ID for purchase tracking fallback.
11
+ * All three tracking props (`customerId`, `orderId`, `token`) must be
12
+ * present for tracking to fire.
13
+ */
14
+ customerId?: string;
15
+ /**
16
+ * Merchant order ID for purchase tracking fallback.
17
+ */
18
+ orderId?: string;
19
+ /**
20
+ * Checkout token for purchase tracking fallback.
21
+ */
22
+ token?: string;
23
+ /**
24
+ * Base URL to share. Falls back to the merchant domain returned by
25
+ * the backend when omitted.
26
+ */
27
+ sharingUrl?: string;
28
+ /**
29
+ * Override the merchant ID resolved from the SDK config.
30
+ */
31
+ merchantId?: string;
32
+ /**
33
+ * Placement ID for backend-driven CSS customization.
34
+ */
35
+ placement?: string;
36
+ /**
37
+ * CSS class names passed through to the root element (Light DOM).
38
+ */
39
+ classname?: string;
40
+ /**
41
+ * Force a display variant instead of relying on the backend evaluation.
42
+ */
43
+ variant?: "referrer" | "referee";
44
+ /**
45
+ * Label for the pill badge displayed above the message.
46
+ * When omitted (and no placement config provides one), the badge is hidden.
47
+ */
48
+ badgeText?: string;
49
+ /**
50
+ * Override the message shown to referrers.
51
+ * Use `{REWARD}` as placeholder for the reward amount.
52
+ */
53
+ referrerText?: string;
54
+ /**
55
+ * Override the message shown to referees.
56
+ * Use `{REWARD}` as placeholder for the reward amount.
57
+ */
58
+ refereeText?: string;
59
+ /**
60
+ * Override the CTA button text.
61
+ * Use `{REWARD}` as placeholder for the reward amount.
62
+ */
63
+ ctaText?: string;
64
+ };
65
+ //#endregion
66
+ //#region src/components/PostPurchase/PostPurchase.d.ts
67
+ /**
68
+ * Post-purchase card component.
69
+ *
70
+ * Renders an inline card on the merchant's thank-you / order-status page
71
+ * that either congratulates a referee or invites a referrer to share.
72
+ *
73
+ * Fetches referral status and merchant information via two independent
74
+ * RPC calls, then computes the display variant locally.
75
+ *
76
+ * @group components
77
+ *
78
+ * @example
79
+ * Minimal — just show the card:
80
+ * ```html
81
+ * <frak-post-purchase></frak-post-purchase>
82
+ * ```
83
+ *
84
+ * @example
85
+ * With purchase tracking fallback and custom sharing URL:
86
+ * ```html
87
+ * <frak-post-purchase
88
+ * customer-id="cust_123"
89
+ * order-id="ord_456"
90
+ * token="checkout_abc"
91
+ * sharing-url="https://merchant.com/product/shoes"
92
+ * ></frak-post-purchase>
93
+ * ```
94
+ */
95
+ declare function PostPurchase({
96
+ customerId,
97
+ orderId,
98
+ token,
99
+ sharingUrl,
100
+ merchantId,
101
+ placement: placementId,
102
+ classname,
103
+ variant: forcedVariant,
104
+ badgeText: propBadgeText,
105
+ referrerText: propReferrerText,
106
+ refereeText: propRefereeText,
107
+ ctaText: propCtaText
108
+ }: PostPurchaseProps): _$preact.JSX.Element | null;
109
+ //#endregion
110
+ //#region src/components/PostPurchase/index.d.ts
111
+ /**
112
+ * Custom element interface for `<frak-post-purchase>`.
113
+ * Combines standard {@link HTMLElement} with {@link PostPurchaseProps}.
114
+ */
115
+ interface PostPurchaseElement extends HTMLElement, PostPurchaseProps {}
116
+ declare global {
117
+ interface HTMLElementTagNameMap {
118
+ "frak-post-purchase": PostPurchaseElement;
119
+ }
120
+ }
121
+ //#endregion
122
+ export { PostPurchase, PostPurchaseElement };