@fanfare-io/fanfare-sdk-react 0.22.0 → 0.23.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/README.md +8 -0
- package/dist/components/checkout/card-brand.d.ts +2 -0
- package/dist/components/checkout/checkout-processing-panel.d.ts +2 -1
- package/dist/components/checkout/payment-collection-panel.d.ts +3 -3
- package/dist/components/checkout/payment-method-list.d.ts +18 -0
- package/dist/components/checkout/receipt-panel.d.ts +4 -3
- package/dist/components/primitives/spinner.d.ts +5 -0
- package/dist/index-DbLojDF1.js +8337 -0
- package/dist/index.js +4 -4
- package/dist/stripe-card-field-DIxqCt1r.js +186 -0
- package/dist/styles/base.css +1 -1
- package/dist/styles/theme.css +137 -3
- package/package.json +6 -6
- package/dist/index-DMy2IUi5.js +0 -8011
- package/dist/stripe-card-field-DaNEAuCE.js +0 -175
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsxs as E, Fragment as D, jsx as y } from "react/jsx-runtime";
|
|
3
|
-
import * as n from "react";
|
|
4
|
-
import { createPortal as _ } from "react-dom";
|
|
5
|
-
import { u as j, a as H, d as z, S as $, B as K, g as O } from "./index-DMy2IUi5.js";
|
|
6
|
-
const W = [
|
|
7
|
-
"--ff-color-foreground",
|
|
8
|
-
"--ff-font-sans",
|
|
9
|
-
"--ff-color-muted-foreground",
|
|
10
|
-
"--ff-color-danger"
|
|
11
|
-
], Y = [
|
|
12
|
-
"ar",
|
|
13
|
-
"bg",
|
|
14
|
-
"cs",
|
|
15
|
-
"da",
|
|
16
|
-
"de",
|
|
17
|
-
"el",
|
|
18
|
-
"en",
|
|
19
|
-
"en-AU",
|
|
20
|
-
"en-CA",
|
|
21
|
-
"en-NZ",
|
|
22
|
-
"en-GB",
|
|
23
|
-
"es",
|
|
24
|
-
"es-ES",
|
|
25
|
-
"es-419",
|
|
26
|
-
"et",
|
|
27
|
-
"fi",
|
|
28
|
-
"fil",
|
|
29
|
-
"fr",
|
|
30
|
-
"fr-CA",
|
|
31
|
-
"fr-FR",
|
|
32
|
-
"he",
|
|
33
|
-
"hu",
|
|
34
|
-
"hr",
|
|
35
|
-
"id",
|
|
36
|
-
"it",
|
|
37
|
-
"it-IT",
|
|
38
|
-
"ja",
|
|
39
|
-
"ko",
|
|
40
|
-
"lt",
|
|
41
|
-
"lv",
|
|
42
|
-
"ms",
|
|
43
|
-
"mt",
|
|
44
|
-
"nb",
|
|
45
|
-
"nl",
|
|
46
|
-
"no",
|
|
47
|
-
"pl",
|
|
48
|
-
"pt",
|
|
49
|
-
"pt-BR",
|
|
50
|
-
"ro",
|
|
51
|
-
"ru",
|
|
52
|
-
"sk",
|
|
53
|
-
"sl",
|
|
54
|
-
"sv",
|
|
55
|
-
"th",
|
|
56
|
-
"tr",
|
|
57
|
-
"vi",
|
|
58
|
-
"zh",
|
|
59
|
-
"zh-HK",
|
|
60
|
-
"zh-TW"
|
|
61
|
-
];
|
|
62
|
-
function q(a) {
|
|
63
|
-
return Y.find((f) => f === a) ?? "auto";
|
|
64
|
-
}
|
|
65
|
-
function G(a, f) {
|
|
66
|
-
let s = a;
|
|
67
|
-
for (; s; ) {
|
|
68
|
-
const c = getComputedStyle(s).getPropertyValue(f).trim();
|
|
69
|
-
if (c) return c;
|
|
70
|
-
if (s.parentElement) {
|
|
71
|
-
s = s.parentElement;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const p = s.getRootNode();
|
|
75
|
-
s = p instanceof ShadowRoot && p.host instanceof HTMLElement ? p.host : null;
|
|
76
|
-
}
|
|
77
|
-
return "";
|
|
78
|
-
}
|
|
79
|
-
function U(a) {
|
|
80
|
-
return a.isConnected ? a.ownerDocument.body : null;
|
|
81
|
-
}
|
|
82
|
-
function J({ config: a, onController: f, onChange: s }) {
|
|
83
|
-
const { t: c, locale: p } = j(), I = H(), g = n.useRef(null), R = n.useRef(null), x = n.useRef(null), [o, k] = n.useState(null), [C, h] = n.useState("loading"), [M, B] = n.useState(0), i = n.useRef(f), A = n.useRef(s), L = n.useRef(c);
|
|
84
|
-
n.useEffect(() => {
|
|
85
|
-
i.current = f, A.current = s, L.current = c;
|
|
86
|
-
});
|
|
87
|
-
const { publishableKey: S, stripeAccount: v } = a, F = q(p);
|
|
88
|
-
n.useEffect(() => {
|
|
89
|
-
const e = g.current, r = e ? U(e) : null;
|
|
90
|
-
if (!r) {
|
|
91
|
-
h("unsupported"), i.current(null);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const t = document.createElement("div");
|
|
95
|
-
return t.dataset.fanfareField = "stripe-card-portal", t.style.position = "absolute", t.style.zIndex = "1000", r.appendChild(t), k(t), () => {
|
|
96
|
-
t.remove(), k(null);
|
|
97
|
-
};
|
|
98
|
-
}, []);
|
|
99
|
-
const w = n.useCallback(() => {
|
|
100
|
-
const e = g.current, r = R.current;
|
|
101
|
-
if (!(!e || !r))
|
|
102
|
-
for (const t of W) {
|
|
103
|
-
const d = G(e, t);
|
|
104
|
-
d ? r.style.setProperty(t, d) : r.style.removeProperty(t);
|
|
105
|
-
}
|
|
106
|
-
}, []);
|
|
107
|
-
return n.useEffect(() => {
|
|
108
|
-
if (!o) return;
|
|
109
|
-
let e = !0, r = 0, t = "", d = "", m = "";
|
|
110
|
-
const P = () => {
|
|
111
|
-
if (!e) return;
|
|
112
|
-
const u = g.current;
|
|
113
|
-
if (u) {
|
|
114
|
-
const l = u.getBoundingClientRect(), N = `${l.left + window.scrollX}px`, T = `${l.top + window.scrollY}px`, b = `${l.width}px`;
|
|
115
|
-
(N !== t || T !== d || b !== m) && (o.style.setProperty("left", N), o.style.setProperty("top", T), o.style.setProperty("width", b), t = N, d = T, m = b);
|
|
116
|
-
}
|
|
117
|
-
r = requestAnimationFrame(P);
|
|
118
|
-
};
|
|
119
|
-
return P(), () => {
|
|
120
|
-
e = !1, cancelAnimationFrame(r);
|
|
121
|
-
};
|
|
122
|
-
}, [o]), n.useEffect(() => {
|
|
123
|
-
if (!o) return;
|
|
124
|
-
const e = R.current;
|
|
125
|
-
if (!e) return;
|
|
126
|
-
if (o.getRootNode() !== o.ownerDocument || e.getRootNode() !== e.ownerDocument) {
|
|
127
|
-
h("unsupported"), i.current(null);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
let r = !1, t = null;
|
|
131
|
-
return h("loading"), (async () => {
|
|
132
|
-
let m;
|
|
133
|
-
try {
|
|
134
|
-
m = await O(v ? { publishableKey: S, stripeAccount: v } : { publishableKey: S });
|
|
135
|
-
} catch {
|
|
136
|
-
if (r) return;
|
|
137
|
-
h("failed"), i.current(null);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (r) return;
|
|
141
|
-
w();
|
|
142
|
-
const u = m.elements({ locale: F }).create("card", { style: z(e) });
|
|
143
|
-
t = u, x.current = u, u.on("change", (l) => {
|
|
144
|
-
A.current?.({ complete: l.complete, errorMessage: l.error?.message ?? null });
|
|
145
|
-
}), u.mount(e), h("ready"), i.current({
|
|
146
|
-
createPaymentMethod: async () => {
|
|
147
|
-
const l = await m.createPaymentMethod({ type: "card", card: u });
|
|
148
|
-
if (l.error) throw new Error(l.error.message ?? L.current("checkout.error.generic"));
|
|
149
|
-
return l.paymentMethod.id;
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
})(), () => {
|
|
153
|
-
r = !0, t && (t.off("change"), t.unmount(), t.destroy()), x.current = null, i.current(null);
|
|
154
|
-
};
|
|
155
|
-
}, [o, S, v, F, M, w]), n.useEffect(() => {
|
|
156
|
-
const e = x.current, r = R.current;
|
|
157
|
-
!e || !r || (w(), e.update({ style: z(r) }));
|
|
158
|
-
}, [I, w]), /* @__PURE__ */ E(D, { children: [
|
|
159
|
-
/* @__PURE__ */ E("div", { ref: g, "data-fanfare-field": "stripe-card-anchor", className: "ff:min-h-10", children: [
|
|
160
|
-
C === "loading" ? /* @__PURE__ */ E("span", { className: "ff:flex ff:items-center ff:gap-2 ff:text-sm ff:text-muted", children: [
|
|
161
|
-
/* @__PURE__ */ y($, { size: "sm" }),
|
|
162
|
-
c("checkout.newCard.loading")
|
|
163
|
-
] }) : null,
|
|
164
|
-
C === "unsupported" ? /* @__PURE__ */ y("p", { role: "status", className: "ff:text-sm ff:text-muted", children: c("checkout.newCard.unavailable") }) : null,
|
|
165
|
-
C === "failed" ? /* @__PURE__ */ E("div", { role: "alert", className: "ff:flex ff:flex-col ff:items-start ff:gap-2", children: [
|
|
166
|
-
/* @__PURE__ */ y("p", { className: "ff:text-sm ff:text-danger", children: c("checkout.newCard.loadFailed") }),
|
|
167
|
-
/* @__PURE__ */ y(K, { type: "button", variant: "outline", size: "sm", onClick: () => B((e) => e + 1), children: c("checkout.newCard.reload") })
|
|
168
|
-
] }) : null
|
|
169
|
-
] }),
|
|
170
|
-
o ? _(/* @__PURE__ */ y("div", { ref: R, "data-fanfare-field": "stripe-card" }), o) : null
|
|
171
|
-
] });
|
|
172
|
-
}
|
|
173
|
-
export {
|
|
174
|
-
J as StripeCardField
|
|
175
|
-
};
|