1
1
mirror of https://github.com/primer/css.git synced 2024-11-30 11:17: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 (
<Box is="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
}