MCPcopy Create free account
hub / github.com/github/docs / TableOfContents

Function TableOfContents

components/landing/TableOfContents.tsx:12–85  ·  view source on GitHub ↗
(props: Props)

Source from the content-addressed store, hash-verified

10 variant?: 'compact' | 'expanded'
11}
12export const TableOfContents = (props: Props) => {
13 const { items, variant = 'expanded' } = props
14
15 return (
16 <ul
17 data-testid="table-of-contents"
18 className={cx(variant === 'compact' ? 'list-style-outside pl-2' : '')}
19 >
20 {variant === 'expanded' &&
21 items.map((item) => {
22 const { fullPath: href, title, intro } = item
23
24 return (
25 <li
26 key={href}
27 data-testid="expanded-item"
28 className="pt-4 pb-3 f4 d-list-item width-full list-style-none border-bottom"
29 >
30 <h2 className="py-1 h4">
31 <Link href={href} className="color-fg-accent">
32 {title}
33 </Link>
34 </h2>
35 {intro && (
36 <div className="f4 color-fg-muted" dangerouslySetInnerHTML={{ __html: intro }} />
37 )}
38 </li>
39 )
40 })}
41
42 {variant === 'compact' && (
43 <ActionList>
44 {items.map((item) => {
45 const { fullPath: href, title, childTocItems } = item
46 return (
47 <React.Fragment key={href}>
48 <ActionList.LinkItem
49 key={href}
50 href={href}
51 className="f4 color-fg-accent d-list-item d-block width-full text-underline"
52 >
53 {title}
54 </ActionList.LinkItem>
55 {(childTocItems || []).length > 0 && (
56 <ul
57 className={cx(
58 variant === 'compact' ? 'list-style-circle pl-5' : 'list-style-none'
59 )}
60 >
61 {(childTocItems || []).map((childItem) => {
62 if (!childItem) {
63 return null
64 }
65 return (
66 <ActionList.LinkItem
67 key={childItem.fullPath}
68 href={childItem.fullPath}
69 className="f4 color-fg-accent d-list-item d-block width-full text-underline"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected