@tabnews/ui
Version:
TabNews UI
50 lines (49 loc) • 1.3 kB
JavaScript
"use client";
import { jsxs as u, Fragment as p, jsx as n } from "react/jsx-runtime";
import { ChevronUpIcon as a } from "@primer/octicons-react";
import { IconButton as f } from "@primer/react";
import { useState as m, useEffect as b } from "react";
function v({ target: o }) {
const [r, i] = m(!1);
b(() => {
let t = null;
if (typeof o == "string" ? t = document.querySelector(o) : t = o, !t) {
console.warn("GoToTopButton: Target element not found.");
return;
}
const e = new IntersectionObserver((l) => {
l.forEach((c) => {
i(!c.isIntersecting);
});
});
return e.observe(t), () => e.disconnect();
}, [o]);
function s() {
window.scrollTo({ top: 0, behavior: "smooth" });
}
return r ? /* @__PURE__ */ u(p, { children: [
/* @__PURE__ */ n(
f,
{
variant: "invisible",
"aria-label": "Retornar ao topo",
icon: a,
size: "large",
className: "go-to-top-button",
onClick: s,
tooltipDirection: "nw"
}
),
/* @__PURE__ */ n("style", { jsx: "true", children: `
.go-to-top-button {
position: fixed;
right: 0;
bottom: 0;
margin: 16px;
}
` })
] }) : null;
}
export {
v as GoToTopButton
};