1
1
mirror of https://github.com/primer/css.git synced 2024-11-28 04:43:05 +03:00
css/docs/Outline.js

31 lines
675 B
JavaScript
Raw Normal View History

2018-12-14 09:29:46 +03:00
import React from 'react'
import {Box} from '@primer/components'
export default function Outline({outline, ...rest}) {
if (outline && outline.length) {
return (
2019-04-03 08:59:01 +03:00
<Box as="details" mb={4}>
<summary>Table of contents</summary>
2018-12-14 09:29:46 +03:00
<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
}