-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathContentTree.tsx
More file actions
50 lines (45 loc) · 1.23 KB
/
ContentTree.tsx
File metadata and controls
50 lines (45 loc) · 1.23 KB
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
import Link from 'next/link';
import { FC } from 'react';
import { Badge } from 'react-bootstrap';
import { XContent } from '../../models/Wiki';
export interface ContentTreeProps {
nodes: XContent[];
basePath: string;
level?: number;
metaKey?: string;
}
export const ContentTree: FC<ContentTreeProps> = ({
nodes,
basePath,
level = 0,
metaKey = 'category',
}) => (
<ol className={level === 0 ? 'list-unstyled' : ''}>
{nodes.map(({ path, name, type, meta, children }) => (
<li key={path} className={level > 0 ? 'ms-3' : ''}>
{type !== 'dir' ? (
<Link className="h4 d-flex align-items-center py-1" href={`${basePath}/${path}`}>
{name}
{meta?.[metaKey] && (
<Badge bg="secondary" className="ms-2 small">
{meta[metaKey]}
</Badge>
)}
</Link>
) : (
children?.[0] && (
<details>
<summary className="h4">{name}</summary>
<ContentTree
nodes={children}
basePath={basePath}
level={level + 1}
metaKey={metaKey}
/>
</details>
)
)}
</li>
))}
</ol>
);