-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocsieTemplate.js
70 lines (66 loc) · 2.04 KB
/
DocsieTemplate.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from "react"
import { Link } from "gatsby"
const DocsieNav = (props) => {
let navItems = props.nav.nodes.map((n) => {
return (
<ul className="docise-nav-items">
{n.items.map((doc) => {
return (
<li key={doc.id} className="docise-nav-item">
<Link to={doc.slug} onClick={(e) => props.setMenu((_) => doc.id)}>
{doc.name}
</Link>
{!!doc.items.length && props.selectedMenu === doc.id && (
<ul className="docsie-nav-items">
{doc.items.map((book) => {
return (
<li
className="docsie-nav-item"
onClick={(e) => props.setMenu((_) => doc.id)}
key={book.id}>
<Link to={book.slugAsAnchor}>{book.name}</Link>
</li>
)
})}
</ul>
)}
</li>
)
})}
</ul>
)
})
return <div>{navItems.map((item) => item)}</div>
}
function Docsie(props) {
const { childrenDocsieBook, id, nav } = props.pageContext
const [selectedMenu, setMenu] = React.useState("nav_item_" + id)
return (
<div className="docsie-main-container">
<div className="docsie-nav-container">
<DocsieNav nav={nav} selectedMenu={selectedMenu} setMenu={setMenu} />
</div>
<div className="docsie-page-container">
{childrenDocsieBook.map((book) => {
return (
<>
<h2 id={book.anchor} key={book.id}>
{book.name}
</h2>
{book.childrenDocsieArticle.map((article) => {
return (
<span
dangerouslySetInnerHTML={{ __html: article.html }}
id={article.anchor}
key={article.id}
/>
)
})}
</>
)
})}
</div>
</div>
)
}
export default Docsie