UNPKG

@tabnews/ui

Version:
10 lines (9 loc) 1.01 kB
"use client"; "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("@primer/octicons-react"),p=require("@primer/react"),r=require("react");function f({target:o}){const[i,s]=r.useState(!1);r.useEffect(()=>{let t=null;if(typeof o=="string"?t=document.querySelector(o):t=o,!t){console.warn("GoToTopButton: Target element not found.");return}const n=new IntersectionObserver(u=>{u.forEach(l=>{s(!l.isIntersecting)})});return n.observe(t),()=>n.disconnect()},[o]);function c(){window.scrollTo({top:0,behavior:"smooth"})}return i?e.jsxs(e.Fragment,{children:[e.jsx(p.IconButton,{variant:"invisible","aria-label":"Retornar ao topo",icon:a.ChevronUpIcon,size:"large",className:"go-to-top-button",onClick:c,tooltipDirection:"nw"}),e.jsx("style",{jsx:"true",children:` .go-to-top-button { position: fixed; right: 0; bottom: 0; margin: 16px; } `})]}):null}exports.GoToTopButton=f;