forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniTocs.tsx
56 lines (49 loc) · 1.48 KB
/
MiniTocs.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Heading, NavList } from '@primer/react'
import cx from 'classnames'
import type { MiniTocItem } from 'components/context/ArticleContext'
import { useTranslation } from 'components/hooks/useTranslation'
import styles from './Minitocs.module.scss'
export type MiniTocsPropsT = {
miniTocItems: MiniTocItem[]
}
function RenderTocItem(item: MiniTocItem) {
return (
<div className={cx(styles.nested, item.platform)}>
<NavList.Item href={item.contents.href}>{item.contents.title}</NavList.Item>
{item.items && item.items.length > 0 && (
<ul className={cx(styles.indentNested)}>
{item.items.map((toc) => (
<RenderTocItem
key={toc.contents.href}
contents={toc.contents}
items={toc.items}
platform={toc.platform}
/>
))}
</ul>
)}
</div>
)
}
export function MiniTocs({ miniTocItems }: MiniTocsPropsT) {
const { t } = useTranslation('pages')
return (
<>
<Heading as="h2" id="in-this-article" className="mb-1 ml-3" sx={{ fontSize: 1 }}>
{t('miniToc')}
</Heading>
<NavList className={cx(styles.miniToc, 'my-2')}>
{miniTocItems.map((items, i) => {
return (
<RenderTocItem
key={items.contents.href + i}
contents={items.contents}
items={items.items}
platform={items.platform}
/>
)
})}
</NavList>
</>
)
}