react-flyup-button
Version:
React component to scroll to the top of the page
361 lines (360 loc) • 10.7 kB
JavaScript
import re, { memo as te, useState as ne, useEffect as oe } from "react";
var g = { exports: {} }, T = {};
/**
* @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 q;
function ae() {
if (q) return T;
q = 1;
var c = Symbol.for("react.transitional.element"), u = Symbol.for("react.fragment");
function f(d, a, s) {
var m = null;
if (s !== void 0 && (m = "" + s), a.key !== void 0 && (m = "" + a.key), "key" in a) {
s = {};
for (var E in a)
E !== "key" && (s[E] = a[E]);
} else s = a;
return a = s.ref, {
$$typeof: c,
type: d,
key: m,
ref: a !== void 0 ? a : null,
props: s
};
}
return T.Fragment = u, T.jsx = f, T.jsxs = f, T;
}
var p = {};
/**
* @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 z;
function se() {
return z || (z = 1, process.env.NODE_ENV !== "production" && function() {
function c(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === Q ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case R:
return "Fragment";
case h:
return "Profiler";
case x:
return "StrictMode";
case X:
return "Suspense";
case B:
return "SuspenseList";
case Z:
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 S:
return "Portal";
case V:
return (e.displayName || "Context") + ".Provider";
case O:
return (e._context.displayName || "Context") + ".Consumer";
case G:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case H:
return r = e.displayName || null, r !== null ? r : c(e.type) || "Memo";
case $:
r = e._payload, e = e._init;
try {
return c(e(r));
} catch {
}
}
return null;
}
function u(e) {
return "" + e;
}
function f(e) {
try {
u(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, n = 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.",
n
), u(e);
}
}
function d(e) {
if (e === R) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === $)
return "<...>";
try {
var r = c(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function a() {
var e = P.A;
return e === null ? null : e.getOwner();
}
function s() {
return Error("react-stack-top-frame");
}
function m(e) {
if (F.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function E(e, r) {
function t() {
D || (D = !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 j() {
var e = c(this.type);
return L[e] || (L[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 A(e, r, t, n, i, l, N, C) {
return t = l.ref, e = {
$$typeof: w,
type: e,
key: r,
props: l,
_owner: i
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: j
}) : 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: N
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: C
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function k(e, r, t, n, i, l, N, C) {
var o = r.children;
if (o !== void 0)
if (n)
if (K(o)) {
for (n = 0; n < o.length; n++)
_(o[n]);
Object.freeze && Object.freeze(o);
} 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 _(o);
if (F.call(r, "key")) {
o = c(e);
var v = Object.keys(r).filter(function(ee) {
return ee !== "key";
});
n = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", U[o + n] || (v = 0 < v.length ? "{" + v.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} />`,
n,
o,
v,
o
), U[o + n] = !0);
}
if (o = null, t !== void 0 && (f(t), o = "" + t), m(r) && (f(r.key), o = "" + r.key), "key" in r) {
t = {};
for (var Y in r)
Y !== "key" && (t[Y] = r[Y]);
} else t = r;
return o && E(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), A(
e,
o,
l,
i,
a(),
t,
N,
C
);
}
function _(e) {
typeof e == "object" && e !== null && e.$$typeof === w && e._store && (e._store.validated = 1);
}
var b = re, w = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), R = Symbol.for("react.fragment"), x = Symbol.for("react.strict_mode"), h = Symbol.for("react.profiler"), O = Symbol.for("react.consumer"), V = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), P = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, K = Array.isArray, y = console.createTask ? console.createTask : function() {
return null;
};
b = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var D, L = {}, M = b["react-stack-bottom-frame"].bind(
b,
s
)(), W = y(d(s)), U = {};
p.Fragment = R, p.jsx = function(e, r, t, n, i) {
var l = 1e4 > P.recentlyCreatedOwnerStacks++;
return k(
e,
r,
t,
!1,
n,
i,
l ? Error("react-stack-top-frame") : M,
l ? y(d(e)) : W
);
}, p.jsxs = function(e, r, t, n, i) {
var l = 1e4 > P.recentlyCreatedOwnerStacks++;
return k(
e,
r,
t,
!0,
n,
i,
l ? Error("react-stack-top-frame") : M,
l ? y(d(e)) : W
);
};
}()), p;
}
var J;
function le() {
return J || (J = 1, process.env.NODE_ENV === "production" ? g.exports = ae() : g.exports = se()), g.exports;
}
var I = le();
function ce({
className: c = "",
position: u = "right",
bottom: f = 20,
left: d = 20,
width: a = 50,
height: s = 50,
borderRadius: m = 50,
backgroundColor: E = "#fff",
borderColor: j = "#fff",
borderWidth: A = 3,
cursor: k = "pointer",
displayAt: _ = 0,
animationDuration: b = 0.5,
smoothScroll: w = !0,
children: S
}) {
const [R, x] = ne(!1), h = {
position: "fixed",
bottom: f,
left: u === "left" ? d : u === "center" ? "50%" : void 0,
right: u === "right" ? 20 : void 0,
transform: u === "center" ? "translateX(-50%)" : void 0,
width: a,
height: s,
borderRadius: `${m}%`,
backgroundColor: E,
borderColor: j,
borderWidth: A,
borderStyle: "solid",
cursor: k,
zIndex: 1e3,
display: "flex",
alignItems: "center",
justifyContent: "center",
scale: R ? 1 : 0,
opacity: R ? 1 : 0,
transition: `all ${b}s ease`
};
return oe(() => {
function O() {
window.scrollY > _ ? x(!0) : x(!1);
}
return window.addEventListener("scroll", O), () => {
window.removeEventListener("scroll", O);
};
}, [_]), /* @__PURE__ */ I.jsx(
"button",
{
className: c,
style: h,
onClick: () => {
window.scrollTo({
top: 0,
behavior: w ? "smooth" : "auto"
});
},
children: S ? /* @__PURE__ */ I.jsx(
"span",
{
style: {
color: "#000"
},
children: S
}
) : /* @__PURE__ */ I.jsx(
"img",
{
src: "https://img.icons8.com/ios/25/collapse-arrow.png",
alt: "collapse-arrow"
}
)
}
);
}
const ie = te(ce);
export {
ie as default
};