MCPcopy Create free account
hub / github.com/arktypeio/arktype / Toc

Function Toc

ark/docs/components/shell/Toc.tsx:47–94  ·  view source on GitHub ↗
({ entries, markdownUrl, editUrl }: TocProps)

Source from the content-addressed store, hash-verified

45
46/** the desktop "On this page" column, with a rail on the heading being read */
47export const Toc = ({ entries, markdownUrl, editUrl }: TocProps) => {
48 const active = useActiveEntry(entries)
49 const list = useRef<HTMLOListElement>(null)
50 const rail = useRef<HTMLSpanElement>(null)
51 const { result, copy } = useCopyMarkdown(markdownUrl)
52
53 useLayoutEffect(() => {
54 const link = list.current?.querySelectorAll("a")[active]
55 if (!link || !rail.current) return
56 rail.current.style.setProperty("--y", `${link.offsetTop + 4}px`)
57 rail.current.style.setProperty("--h", `${link.offsetHeight - 8}px`)
58 const container = link.closest<HTMLElement>(".docs-toc")
59 if (!container) return
60 const top =
61 link.getBoundingClientRect().top - container.getBoundingClientRect().top
62 if (top < 72 || top > container.clientHeight - link.offsetHeight - 24)
63 container.scrollTop += top - container.clientHeight / 3
64 }, [active])
65
66 return (
67 <nav className="toc" aria-labelledby="toc-label">
68 {entries.length > 0 && (
69 <>
70 <p className="toc-label" id="toc-label">
71 On this page
72 </p>
73 <div className="toc-track">
74 <ol className="toc-list" ref={list}>
75 <TocLinks entries={entries} active={active} />
76 </ol>
77 <span className="toc-rail" ref={rail} aria-hidden />
78 </div>
79 </>
80 )}
81 <div className="toc-foot">
82 <button type="button" onClick={copy}>
83 <CopyFace result={result} />
84 </button>
85 <a href={markdownUrl}>View as Markdown</a>
86 <a className="ext" href={editUrl} target="_blank" rel="noreferrer">
87 Edit on GitHub
88 </a>
89 <a href="#main">Back to top ↑</a>
90 <CopyStatus result={result} />
91 </div>
92 </nav>
93 )
94}
95
96/** the "On this page" bar above the article below the desktop breakpoint */
97export const MobileToc = ({ entries }: { entries: TocEntry[] }) => {

Callers

nothing calls this directly

Calls 2

useCopyMarkdownFunction · 0.90
useActiveEntryFunction · 0.85

Tested by

no test coverage detected