1
1
mirror of https://github.com/primer/css.git synced 2024-11-27 09:45:45 +03:00
css/docs/Outline.js
2019-02-04 13:04:24 -08: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 is="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
}