({
toc,
className,
linkClassName,
isChild,
}: Props)
| 3 | |
| 4 | // Recursive component rendering the toc tree |
| 5 | function TOCItemTree({ |
| 6 | toc, |
| 7 | className, |
| 8 | linkClassName, |
| 9 | isChild, |
| 10 | }: Props): JSX.Element | null { |
| 11 | if (!toc.length) { |
| 12 | return null; |
| 13 | } |
| 14 | return ( |
| 15 | <ul className={isChild ? undefined : className}> |
| 16 | {toc.map((heading) => ( |
| 17 | <li key={heading.id}> |
| 18 | <a |
| 19 | href={`#${heading.id}`} |
| 20 | className={linkClassName ?? undefined} |
| 21 | dangerouslySetInnerHTML={{ |
| 22 | __html: `<span class="type-theta border-underline-link">${heading.value}</span>`, |
| 23 | }} |
| 24 | /> |
| 25 | <TOCItemTree |
| 26 | isChild |
| 27 | toc={heading.children} |
| 28 | className={className} |
| 29 | linkClassName={linkClassName} |
| 30 | /> |
| 31 | </li> |
| 32 | ))} |
| 33 | </ul> |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | // Memo only the tree root is enough |
| 38 | export default React.memo(TOCItemTree); |
nothing calls this directly
no outgoing calls
no test coverage detected