1
1
mirror of https://github.com/primer/css.git synced 2024-12-22 13:41:34 +03:00
css/docs/Outline.js
2019-04-02 22:59:01 -07:00

31 lines
675 B
JavaScript

import React from 'react'
import {Box} from '@primer/components'
export default function Outline({outline, ...rest}) {
if (outline && outline.length) {
return (
<Box as="details" mb={4}>
<summary>Table of contents</summary>
<OutlineList items={outline} {...rest} />
</Box>
)
}
return null
}
export function OutlineList({items, ...rest}) {
if (items && items.length) {
return (
<ul {...rest}>
{items.map(item => (
<li key={item.id}>
<a href={`#${item.id}`}>{item.title}</a>
<OutlineList items={item.children} />
</li>
))}
</ul>
)
}
return null
}