@frak-labs/components 0.0.23-beta.6e0d8026 → 0.0.23-beta.9f335831
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/cdn/ButtonShare.CIGkGJ6p.js +1 -0
- package/cdn/ButtonWallet.DIJbfTAn.js +1 -0
- package/cdn/components.js +1 -1
- package/cdn/loader.css +7 -0
- package/cdn/loader.js +7 -21
- package/dist/buttonShare.css +2 -1
- package/dist/buttonShare.d.ts +100 -85
- package/dist/buttonShare.js +343 -1
- package/dist/buttonWallet.css +1 -1
- package/dist/buttonWallet.d.ts +76 -64
- package/dist/buttonWallet.js +109 -1
- package/dist/useReward-1io3tiHR.js +239 -0
- package/package.json +43 -14
- package/cdn/564.74bbd23d.js +0 -1
- package/cdn/button-share.4d8a18a0.js +0 -1
- package/cdn/button-share.823884d0.css +0 -1
- package/cdn/button-wallet.0a2b7d12.js +0 -1
- package/cdn/button-wallet.390d543a.css +0 -1
- package/cdn/loader.js.LICENSE.txt +0 -1
package/dist/buttonShare.d.ts
CHANGED
|
@@ -1,85 +1,100 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
import { FullInteractionTypesKey } from "@frak-labs/core-sdk";
|
|
2
|
+
import * as preact0 from "preact";
|
|
3
|
+
|
|
4
|
+
//#region src/components/ButtonShare/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The props type for {@link ButtonShare}.
|
|
8
|
+
* @inline
|
|
9
|
+
*/
|
|
10
|
+
type ButtonShareProps = {
|
|
11
|
+
/**
|
|
12
|
+
* Text to display on the button
|
|
13
|
+
* - To specify where the reward should be displayed, use the placeholder `{REWARD}`, e.g. `Share and earn up to \{REWARD\}!`
|
|
14
|
+
* @defaultValue `"Share and earn!"`
|
|
15
|
+
*/
|
|
16
|
+
text?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Classname to apply to the button
|
|
19
|
+
*/
|
|
20
|
+
classname?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Do we display the reward on the share modal?
|
|
23
|
+
* @defaultValue `false`
|
|
24
|
+
*/
|
|
25
|
+
useReward?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Fallback text if the reward isn't found
|
|
28
|
+
*/
|
|
29
|
+
noRewardText?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Target interaction behind this sharing action (will be used to get the right reward to display)
|
|
32
|
+
*/
|
|
33
|
+
targetInteraction?: FullInteractionTypesKey;
|
|
34
|
+
/**
|
|
35
|
+
* Do we display the wallet modal instead of the share modal?
|
|
36
|
+
* @defaultValue `false`
|
|
37
|
+
*/
|
|
38
|
+
showWallet?: boolean;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/components/ButtonShare/ButtonShare.d.ts
|
|
42
|
+
/**
|
|
43
|
+
* Button to share the current page
|
|
44
|
+
*
|
|
45
|
+
* @param args
|
|
46
|
+
* @returns The share button with `<button>` tag
|
|
47
|
+
*
|
|
48
|
+
* @group components
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* Basic usage:
|
|
52
|
+
* ```html
|
|
53
|
+
* <frak-button-share></frak-button-share>
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* Using a custom text:
|
|
58
|
+
* ```html
|
|
59
|
+
* <frak-button-share text="Share and earn!"></frak-button-share>
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* Using a custom class:
|
|
64
|
+
* ```html
|
|
65
|
+
* <frak-button-share classname="button button-primary"></frak-button-share>
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* Using reward information and fallback text:
|
|
70
|
+
* ```html
|
|
71
|
+
* <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!"></frak-button-share>
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* Using reward information for specific reward and fallback text:
|
|
76
|
+
* ```html
|
|
77
|
+
* <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="retail.customerMeeting"></frak-button-share>
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
81
|
+
* @see {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} for more info about the estimated reward fetching
|
|
82
|
+
*/
|
|
83
|
+
declare function ButtonShare({
|
|
84
|
+
text,
|
|
85
|
+
classname,
|
|
86
|
+
useReward: rawUseReward,
|
|
87
|
+
noRewardText,
|
|
88
|
+
targetInteraction,
|
|
89
|
+
showWallet: rawShowWallet
|
|
90
|
+
}: ButtonShareProps): preact0.JSX.Element;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/components/ButtonShare/index.d.ts
|
|
93
|
+
interface ButtonShareElement extends HTMLElement, ButtonShareProps {}
|
|
94
|
+
declare global {
|
|
95
|
+
interface HTMLElementTagNameMap {
|
|
96
|
+
"frak-button-share": ButtonShareElement;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { ButtonShare, ButtonShareElement };
|
package/dist/buttonShare.js
CHANGED
|
@@ -1 +1,343 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { i as getModalBuilderSteps, n as useClientReady, r as registerWebComponent, t as useReward } from "./useReward-1io3tiHR.js";
|
|
2
|
+
import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
|
|
3
|
+
import { displayEmbeddedWallet } from "@frak-labs/core-sdk/actions";
|
|
4
|
+
import { cx } from "class-variance-authority";
|
|
5
|
+
import { useCallback, useMemo, useState } from "preact/hooks";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
7
|
+
import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
|
|
8
|
+
|
|
9
|
+
//#region src/components/Spinner/index.module.css?css_module
|
|
10
|
+
const classes$1 = {
|
|
11
|
+
"spinner__leaf": "M4fSKa_spinner__leaf",
|
|
12
|
+
"rt-spinner-leaf-fade": "M4fSKa_rt-spinner-leaf-fade",
|
|
13
|
+
"spinner": "M4fSKa_spinner"
|
|
14
|
+
};
|
|
15
|
+
var index_module_default = classes$1;
|
|
16
|
+
const _spinner__leaf0 = classes$1["spinner__leaf"];
|
|
17
|
+
const _rt_spinner_leaf_fade0 = classes$1["rt-spinner-leaf-fade"];
|
|
18
|
+
const _spinner0 = classes$1["spinner"];
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/components/Spinner/index.tsx
|
|
22
|
+
const Spinner = ({ ref, className, ...props }) => {
|
|
23
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
24
|
+
...props,
|
|
25
|
+
ref,
|
|
26
|
+
className: cx(index_module_default.spinner),
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
29
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
30
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
31
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
32
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
33
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
34
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
35
|
+
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf })
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
Spinner.displayName = "Spinner";
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/components/ButtonShare/ButtonShare.module.css?css_module
|
|
43
|
+
const classes = { "buttonShare": "nOB7Uq_buttonShare" };
|
|
44
|
+
var ButtonShare_module_default = classes;
|
|
45
|
+
const _buttonShare0 = classes["buttonShare"];
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/hooks/useCopyToClipboard.ts
|
|
49
|
+
function useCopyToClipboard(options = {}) {
|
|
50
|
+
const { successDuration = 2e3 } = options;
|
|
51
|
+
const [copied, setCopied] = useState(false);
|
|
52
|
+
return {
|
|
53
|
+
copy: useCallback(async (text) => {
|
|
54
|
+
try {
|
|
55
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
56
|
+
await navigator.clipboard.writeText(text);
|
|
57
|
+
setCopied(true);
|
|
58
|
+
} else {
|
|
59
|
+
const textArea = document.createElement("textarea");
|
|
60
|
+
textArea.value = text;
|
|
61
|
+
textArea.style.position = "fixed";
|
|
62
|
+
textArea.style.opacity = "0";
|
|
63
|
+
document.body.appendChild(textArea);
|
|
64
|
+
textArea.focus();
|
|
65
|
+
textArea.select();
|
|
66
|
+
try {
|
|
67
|
+
document.execCommand("copy");
|
|
68
|
+
setCopied(true);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
console.error("Failed to copy text:", err);
|
|
71
|
+
return false;
|
|
72
|
+
} finally {
|
|
73
|
+
textArea.remove();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
setCopied(false);
|
|
78
|
+
}, successDuration);
|
|
79
|
+
return true;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error("Failed to copy text:", err);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}, [successDuration]),
|
|
85
|
+
copied
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/components/ButtonShare/components/ErrorMessage.tsx
|
|
91
|
+
const styles = {
|
|
92
|
+
errorContainer: {
|
|
93
|
+
marginTop: "16px",
|
|
94
|
+
padding: "16px",
|
|
95
|
+
backgroundColor: "#FEE2E2",
|
|
96
|
+
border: "1px solid #FCA5A5",
|
|
97
|
+
borderRadius: "4px",
|
|
98
|
+
color: "#991B1B"
|
|
99
|
+
},
|
|
100
|
+
header: {
|
|
101
|
+
display: "flex",
|
|
102
|
+
alignItems: "center",
|
|
103
|
+
gap: "8px",
|
|
104
|
+
marginBottom: "12px"
|
|
105
|
+
},
|
|
106
|
+
title: {
|
|
107
|
+
margin: 0,
|
|
108
|
+
fontSize: "16px",
|
|
109
|
+
fontWeight: 500
|
|
110
|
+
},
|
|
111
|
+
message: {
|
|
112
|
+
fontSize: "14px",
|
|
113
|
+
lineHeight: "1.5",
|
|
114
|
+
margin: "0 0 12px 0"
|
|
115
|
+
},
|
|
116
|
+
link: {
|
|
117
|
+
color: "#991B1B",
|
|
118
|
+
textDecoration: "underline",
|
|
119
|
+
textUnderlineOffset: "2px"
|
|
120
|
+
},
|
|
121
|
+
copyButton: {
|
|
122
|
+
display: "inline-flex",
|
|
123
|
+
alignItems: "center",
|
|
124
|
+
gap: "8px",
|
|
125
|
+
marginBottom: "10px",
|
|
126
|
+
padding: "8px 12px",
|
|
127
|
+
backgroundColor: "white",
|
|
128
|
+
border: "1px solid #D1D5DB",
|
|
129
|
+
borderRadius: "4px",
|
|
130
|
+
color: "black",
|
|
131
|
+
fontSize: "14px",
|
|
132
|
+
fontWeight: 500
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Renders a toggleable debug information section
|
|
137
|
+
* @param {Object} props - Component props
|
|
138
|
+
* @param {string} [props.debugInfo] - Debug information to display in textarea
|
|
139
|
+
*/
|
|
140
|
+
function ToggleMessage({ debugInfo }) {
|
|
141
|
+
const [showInfo, setShowInfo] = useState(false);
|
|
142
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("button", {
|
|
143
|
+
type: "button",
|
|
144
|
+
style: styles.copyButton,
|
|
145
|
+
onClick: () => setShowInfo(!showInfo),
|
|
146
|
+
children: "Ouvrir les informations"
|
|
147
|
+
}), showInfo && /* @__PURE__ */ jsx("textarea", {
|
|
148
|
+
style: {
|
|
149
|
+
display: "block",
|
|
150
|
+
width: "100%",
|
|
151
|
+
height: "200px",
|
|
152
|
+
fontSize: "12px"
|
|
153
|
+
},
|
|
154
|
+
children: debugInfo
|
|
155
|
+
})] });
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Displays an error message with debug information and copy functionality
|
|
159
|
+
* @param {Object} props - Component props
|
|
160
|
+
* @param {string} [props.debugInfo] - Debug information that can be copied or displayed
|
|
161
|
+
*/
|
|
162
|
+
function ErrorMessage({ debugInfo }) {
|
|
163
|
+
const { copied, copy } = useCopyToClipboard();
|
|
164
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
165
|
+
style: styles.errorContainer,
|
|
166
|
+
children: [
|
|
167
|
+
/* @__PURE__ */ jsx("div", {
|
|
168
|
+
style: styles.header,
|
|
169
|
+
children: /* @__PURE__ */ jsx("h3", {
|
|
170
|
+
style: styles.title,
|
|
171
|
+
children: "Oups ! Nous avons rencontré un petit problème"
|
|
172
|
+
})
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ jsxs("p", {
|
|
175
|
+
style: styles.message,
|
|
176
|
+
children: [
|
|
177
|
+
"Impossible d'ouvrir le menu de partage pour le moment. Si le problème persiste, copiez les informations ci-dessous et collez-les dans votre mail à",
|
|
178
|
+
" ",
|
|
179
|
+
/* @__PURE__ */ jsx("a", {
|
|
180
|
+
href: "mailto:help@frak-labs.com?subject=Debug",
|
|
181
|
+
style: styles.link,
|
|
182
|
+
children: "help@frak-labs.com"
|
|
183
|
+
}),
|
|
184
|
+
" ",
|
|
185
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
186
|
+
"Merci pour votre retour, nous traitons votre demande dans les plus brefs délais."
|
|
187
|
+
]
|
|
188
|
+
}),
|
|
189
|
+
/* @__PURE__ */ jsx("button", {
|
|
190
|
+
type: "button",
|
|
191
|
+
onClick: () => copy(debugInfo ?? ""),
|
|
192
|
+
style: styles.copyButton,
|
|
193
|
+
children: copied ? "Informations copiées !" : "Copier les informations de débogage"
|
|
194
|
+
}),
|
|
195
|
+
/* @__PURE__ */ jsx(ToggleMessage, { debugInfo })
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/components/ButtonShare/hooks/useShareModal.ts
|
|
202
|
+
/**
|
|
203
|
+
* Open the share modal
|
|
204
|
+
*
|
|
205
|
+
* @description
|
|
206
|
+
* This function will open the share modal with the configuration provided in the `window.FrakSetup.modalShareConfig` object.
|
|
207
|
+
*/
|
|
208
|
+
function useShareModal(targetInteraction) {
|
|
209
|
+
const [debugInfo, setDebugInfo] = useState(void 0);
|
|
210
|
+
const [isError, setIsError] = useState(false);
|
|
211
|
+
return {
|
|
212
|
+
handleShare: useCallback(async () => {
|
|
213
|
+
if (!window.FrakSetup?.client) {
|
|
214
|
+
console.error("Frak client not found");
|
|
215
|
+
setDebugInfo(DebugInfoGatherer.empty().formatDebugInfo("Frak client not found"));
|
|
216
|
+
setIsError(true);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const modalBuilderSteps = getModalBuilderSteps();
|
|
220
|
+
if (!modalBuilderSteps) throw new Error("modalBuilderSteps not found");
|
|
221
|
+
try {
|
|
222
|
+
await modalBuilderSteps.sharing(window.FrakSetup?.modalShareConfig ?? {}).display((metadata) => ({
|
|
223
|
+
...metadata,
|
|
224
|
+
targetInteraction
|
|
225
|
+
}));
|
|
226
|
+
} catch (e) {
|
|
227
|
+
if (e instanceof FrakRpcError && e.code === RpcErrorCodes.clientAborted) {
|
|
228
|
+
console.debug("User aborted the modal");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const debugInfo$1 = window.FrakSetup.client.debugInfo.formatDebugInfo(e);
|
|
232
|
+
trackEvent(window.FrakSetup.client, "share_modal_error", {
|
|
233
|
+
error: e instanceof Object && "message" in e ? e.message : "Unknown error",
|
|
234
|
+
debugInfo: debugInfo$1
|
|
235
|
+
});
|
|
236
|
+
setDebugInfo(debugInfo$1);
|
|
237
|
+
setIsError(true);
|
|
238
|
+
console.error("Error while opening the modal", e);
|
|
239
|
+
}
|
|
240
|
+
}, [targetInteraction]),
|
|
241
|
+
isError,
|
|
242
|
+
debugInfo
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/components/ButtonShare/ButtonShare.tsx
|
|
248
|
+
/**
|
|
249
|
+
* Open the embedded wallet modal
|
|
250
|
+
*
|
|
251
|
+
* @description
|
|
252
|
+
* This function will open the wallet modal with the configuration provided in the `window.FrakSetup.modalWalletConfig` object.
|
|
253
|
+
*/
|
|
254
|
+
async function modalEmbeddedWallet() {
|
|
255
|
+
if (!window.FrakSetup?.client) throw new Error("Frak client not found");
|
|
256
|
+
await displayEmbeddedWallet(window.FrakSetup.client, window.FrakSetup?.modalWalletConfig ?? {});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Button to share the current page
|
|
260
|
+
*
|
|
261
|
+
* @param args
|
|
262
|
+
* @returns The share button with `<button>` tag
|
|
263
|
+
*
|
|
264
|
+
* @group components
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* Basic usage:
|
|
268
|
+
* ```html
|
|
269
|
+
* <frak-button-share></frak-button-share>
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* Using a custom text:
|
|
274
|
+
* ```html
|
|
275
|
+
* <frak-button-share text="Share and earn!"></frak-button-share>
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* Using a custom class:
|
|
280
|
+
* ```html
|
|
281
|
+
* <frak-button-share classname="button button-primary"></frak-button-share>
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* Using reward information and fallback text:
|
|
286
|
+
* ```html
|
|
287
|
+
* <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!"></frak-button-share>
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* Using reward information for specific reward and fallback text:
|
|
292
|
+
* ```html
|
|
293
|
+
* <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="retail.customerMeeting"></frak-button-share>
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
297
|
+
* @see {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} for more info about the estimated reward fetching
|
|
298
|
+
*/
|
|
299
|
+
function ButtonShare({ text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction, showWallet: rawShowWallet }) {
|
|
300
|
+
const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
|
|
301
|
+
const showWallet = useMemo(() => rawShowWallet !== void 0, [rawShowWallet]);
|
|
302
|
+
const { isClientReady } = useClientReady();
|
|
303
|
+
const { reward } = useReward(shouldUseReward && isClientReady, targetInteraction);
|
|
304
|
+
const { handleShare, isError, debugInfo } = useShareModal(targetInteraction);
|
|
305
|
+
/**
|
|
306
|
+
* Compute the text we will display
|
|
307
|
+
*/
|
|
308
|
+
const btnText = useMemo(() => {
|
|
309
|
+
if (!shouldUseReward) return text;
|
|
310
|
+
if (!reward) return noRewardText ?? text.replace("{REWARD}", "");
|
|
311
|
+
return text.includes("{REWARD}") ? text.replace("{REWARD}", reward) : `${text} ${reward}`;
|
|
312
|
+
}, [
|
|
313
|
+
shouldUseReward,
|
|
314
|
+
text,
|
|
315
|
+
noRewardText,
|
|
316
|
+
reward
|
|
317
|
+
]);
|
|
318
|
+
/**
|
|
319
|
+
* The action when the button is clicked
|
|
320
|
+
*/
|
|
321
|
+
const onClick = useCallback(async () => {
|
|
322
|
+
trackEvent(window.FrakSetup.client, "share_button_clicked");
|
|
323
|
+
if (showWallet) await modalEmbeddedWallet();
|
|
324
|
+
else await handleShare();
|
|
325
|
+
}, [showWallet, handleShare]);
|
|
326
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
|
|
327
|
+
type: "button",
|
|
328
|
+
className: cx(ButtonShare_module_default.buttonShare, classname, "override"),
|
|
329
|
+
onClick,
|
|
330
|
+
children: [
|
|
331
|
+
!isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
|
|
332
|
+
" ",
|
|
333
|
+
btnText
|
|
334
|
+
]
|
|
335
|
+
}), isError && /* @__PURE__ */ jsx(ErrorMessage, { debugInfo })] });
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/components/ButtonShare/index.ts
|
|
340
|
+
registerWebComponent(ButtonShare, "frak-button-share", ["text"], { shadow: false });
|
|
341
|
+
|
|
342
|
+
//#endregion
|
|
343
|
+
export { ButtonShare };
|
package/dist/buttonWallet.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
.Kl62ia_button{all:unset;z-index:2000000;cursor:pointer;text-align:center;background-color:#3e557e;border-radius:50%;justify-content:center;align-items:center;width:45px;height:45px;font-size:24px;display:flex;position:fixed;bottom:20px}.Kl62ia_button__left{left:20px}.Kl62ia_button__right{right:20px}.Kl62ia_reward{color:#fff;white-space:nowrap;background:#ff3f3f;border-radius:5px;padding:2px 3px;font-size:9px;font-weight:600;line-height:9px;position:absolute;top:-4px;right:27px}
|