@anoki/fse-ui
Version:
FSE UI components library
3 lines (2 loc) • 2.91 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./components/ui/TableOfContents/TableOfContents.css');const s=require("./index.cjs278.js"),r=require("react");;/* empty css */const T=require("./index.cjs320.js"),h=require("./index.cjs280.js"),y=require("./index.cjs219.js"),N=require("./index.cjs19.js"),q=require("./index.cjs500.js"),C=({title:f="Indice",headings:i,titleTag:j="h1",modeAuthenticated:b=!1,isOpen:d,onToggle:x=()=>{}})=>{const[g,m]=r.useState(""),[v,w]=r.useState(0),p=T.useMediaQueryV2("(min-width: 768px)",!1),E=p||d,l=r.useRef(!1),a=r.useRef(null);r.useEffect(()=>{const t=()=>{const o=window.scrollY,e=document.documentElement.scrollHeight-window.innerHeight,c=e>0?Math.min(o/e*100,100):0;w(c)};return window.addEventListener("scroll",t),t(),()=>window.removeEventListener("scroll",t)},[]);const u=r.useCallback(t=>{if(window.innerWidth<768)return;const o=document.querySelector(`a[href="#${t}"]`),e=document.querySelector(".toc-scroll");if(o&&e){const c=e.getBoundingClientRect(),n=o.getBoundingClientRect();if(!(n.top>=c.top&&n.bottom<=c.bottom)){const R=n.top-c.top,S=e.scrollTop+R-c.height/2+n.height/2;e.scrollTo({top:S,behavior:"smooth"})}}},[p]);return r.useEffect(()=>{const t=new IntersectionObserver(o=>{l.current||o.forEach(e=>{e.isIntersecting&&(m(e.target.id),u(e.target.id))})},{rootMargin:"-90px 0px -70% 0px",threshold:0});return i.forEach(({id:o})=>{const e=document.getElementById(o);e&&t.observe(e)}),()=>t.disconnect()},[i,u]),s.jsxRuntimeExports.jsxs("div",{className:h.clsx("toc-container",{"toc-container-authenticated":b}),children:[s.jsxRuntimeExports.jsx("button",{className:"ui-button-accordion-toc",onClick:x,type:"button",children:s.jsxRuntimeExports.jsxs(y.Row,{className:"ui-header-table-of-contents",children:[s.jsxRuntimeExports.jsx(j,{className:"text-slate-20 fw-semibold fs-7",children:f}),s.jsxRuntimeExports.jsx(N.ArrowDown,{color:"primary",className:h.clsx("ui-arrow-toc",{"ui-expanded-toc":d})})]})}),s.jsxRuntimeExports.jsx("div",{className:"scroll-progress-bar",children:s.jsxRuntimeExports.jsx("div",{className:"scroll-progress",style:{width:`${v}%`}})}),E&&s.jsxRuntimeExports.jsx(q.ScrollArea,{type:"always",scrollbars:"vertical",className:"toc-scroll fw-semibold fs-6",children:s.jsxRuntimeExports.jsx("div",{className:"toc-list base-col",children:i.map(t=>s.jsxRuntimeExports.jsx("div",{className:"toc-item",children:s.jsxRuntimeExports.jsx("a",{href:`#${t.id}`,className:`toc-link ${g===t.id?"active text-primary":"text-slate-28"}`,onClick:o=>{var e;o.preventDefault(),m(t.id),l.current=!0,a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{l.current=!1},1e3),setTimeout(()=>{u(t.id)},100),(e=document.getElementById(t.id))==null||e.scrollIntoView({behavior:"smooth"}),x()},children:t.text})},t.id))})})]})};exports.TableOfContents=C;
//# sourceMappingURL=index.cjs253.js.map