react-dpay-modal
Version:
A React modal package for DPay payments with Stellar blockchain integration
370 lines (369 loc) • 11.1 kB
JavaScript
import oe, { useEffect as D, useState as ae, useCallback as O, createContext as se, useContext as ue } from "react";
var _ = { exports: {} }, b = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var L;
function le() {
if (L) return b;
L = 1;
var n = Symbol.for("react.transitional.element"), i = Symbol.for("react.fragment");
function l(m, s, u) {
var c = null;
if (u !== void 0 && (c = "" + u), s.key !== void 0 && (c = "" + s.key), "key" in s) {
u = {};
for (var f in s)
f !== "key" && (u[f] = s[f]);
} else u = s;
return s = u.ref, {
$$typeof: n,
type: m,
key: c,
ref: s !== void 0 ? s : null,
props: u
};
}
return b.Fragment = i, b.jsx = l, b.jsxs = l, b;
}
var R = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var W;
function ce() {
return W || (W = 1, process.env.NODE_ENV !== "production" && function() {
function n(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === re ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case k:
return "Fragment";
case G:
return "Profiler";
case V:
return "StrictMode";
case Z:
return "Suspense";
case Q:
return "SuspenseList";
case ee:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case J:
return "Portal";
case H:
return (e.displayName || "Context") + ".Provider";
case X:
return (e._context.displayName || "Context") + ".Consumer";
case B:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case K:
return r = e.displayName || null, r !== null ? r : n(e.type) || "Memo";
case C:
r = e._payload, e = e._init;
try {
return n(e(r));
} catch {
}
}
return null;
}
function i(e) {
return "" + e;
}
function l(e) {
try {
i(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
o
), i(e);
}
}
function m(e) {
if (e === k) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === C)
return "<...>";
try {
var r = n(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function s() {
var e = x.A;
return e === null ? null : e.getOwner();
}
function u() {
return Error("react-stack-top-frame");
}
function c(e) {
if (N.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function f(e, r) {
function t() {
Y || (Y = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
r
));
}
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
function T() {
var e = n(this.type);
return I[e] || (I[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function z(e, r, t, o, v, d, y, g) {
return t = d.ref, e = {
$$typeof: j,
type: e,
key: r,
props: d,
_owner: v
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: T
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: y
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: g
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function S(e, r, t, o, v, d, y, g) {
var a = r.children;
if (a !== void 0)
if (o)
if (te(a)) {
for (o = 0; o < a.length; o++)
A(a[o]);
Object.freeze && Object.freeze(a);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else A(a);
if (N.call(r, "key")) {
a = n(e);
var E = Object.keys(r).filter(function(ne) {
return ne !== "key";
});
o = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", F[a + o] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
o,
a,
E,
a
), F[a + o] = !0);
}
if (a = null, t !== void 0 && (l(t), a = "" + t), c(r) && (l(r.key), a = "" + r.key), "key" in r) {
t = {};
for (var h in r)
h !== "key" && (t[h] = r[h]);
} else t = r;
return a && f(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), z(
e,
a,
d,
v,
s(),
t,
y,
g
);
}
function A(e) {
typeof e == "object" && e !== null && e.$$typeof === j && e._store && (e._store.validated = 1);
}
var p = oe, j = Symbol.for("react.transitional.element"), J = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), V = Symbol.for("react.strict_mode"), G = Symbol.for("react.profiler"), X = Symbol.for("react.consumer"), H = Symbol.for("react.context"), B = Symbol.for("react.forward_ref"), Z = Symbol.for("react.suspense"), Q = Symbol.for("react.suspense_list"), K = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), ee = Symbol.for("react.activity"), re = Symbol.for("react.client.reference"), x = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, N = Object.prototype.hasOwnProperty, te = Array.isArray, w = console.createTask ? console.createTask : function() {
return null;
};
p = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var Y, I = {}, M = p["react-stack-bottom-frame"].bind(
p,
u
)(), $ = w(m(u)), F = {};
R.Fragment = k, R.jsx = function(e, r, t, o, v) {
var d = 1e4 > x.recentlyCreatedOwnerStacks++;
return S(
e,
r,
t,
!1,
o,
v,
d ? Error("react-stack-top-frame") : M,
d ? w(m(e)) : $
);
}, R.jsxs = function(e, r, t, o, v) {
var d = 1e4 > x.recentlyCreatedOwnerStacks++;
return S(
e,
r,
t,
!0,
o,
v,
d ? Error("react-stack-top-frame") : M,
d ? w(m(e)) : $
);
};
}()), R;
}
var U;
function ie() {
return U || (U = 1, process.env.NODE_ENV === "production" ? _.exports = le() : _.exports = ce()), _.exports;
}
var P = ie();
const me = ({
isOpen: n,
onClose: i,
children: l,
className: m = "",
overlayClassName: s = "",
closeOnOverlayClick: u = !0,
closeOnEscape: c = !0
}) => (D(() => {
if (!c) return;
const f = (T) => {
T.key === "Escape" && n && i();
};
return document.addEventListener("keydown", f), () => document.removeEventListener("keydown", f);
}, [n, i, c]), D(() => (n ? document.body.style.overflow = "hidden" : document.body.style.overflow = "unset", () => {
document.body.style.overflow = "unset";
}), [n]), n ? /* @__PURE__ */ P.jsx(
"div",
{
className: `modal-overlay ${s}`,
onClick: u ? i : void 0,
style: {
position: "fixed",
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: "rgba(0, 0, 0, 0.5)",
display: "flex",
alignItems: "center",
justifyContent: "center",
zIndex: 1e3
},
children: /* @__PURE__ */ P.jsx(
"div",
{
className: `modal-content ${m}`,
onClick: (f) => f.stopPropagation(),
style: {
backgroundColor: "white",
borderRadius: "8px",
padding: "24px",
maxWidth: "90vw",
maxHeight: "90vh",
overflow: "auto"
},
children: l
}
)
}
) : null), fe = (n = !1) => {
const [i, l] = ae({
isOpen: n,
modalId: void 0
}), m = O((c) => {
l({ isOpen: !0, modalId: c });
}, []), s = O(() => {
l({ isOpen: !1, modalId: void 0 });
}, []), u = O(() => {
l((c) => ({
...c,
isOpen: !c.isOpen
}));
}, []);
return {
...i,
open: m,
close: s,
toggle: u
};
}, q = se(void 0), ve = ({
children: n,
initialState: i = !1
}) => {
const l = fe(i);
return /* @__PURE__ */ P.jsx(q.Provider, { value: l, children: n });
}, Ee = () => {
const n = ue(q);
if (n === void 0)
throw new Error("useModalContext must be used within a ModalProvider");
return n;
};
export {
me as Modal,
ve as ModalProvider,
fe as useModal,
Ee as useModalContext
};