|
1 | 1 | import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" |
2 | 2 | import style from "./styles/drawer.scss" |
3 | 3 | // @ts-ignore |
| 4 | +import script from "./scripts/drawer.inline" |
| 5 | +import TableOfContents from "./TableOfContents" |
| 6 | +import { classNames } from "../util/lang" |
| 7 | +import { FileNode } from "./ExplorerNode" |
| 8 | +import { resolveRelative } from "../util/path" |
4 | 9 |
|
5 | 10 | interface Options { |
6 | 11 | links?: Record<string, string> |
7 | 12 | } |
8 | 13 |
|
9 | 14 | export default ((opts?: Options) => { |
10 | | - const Drawer: QuartzComponent = (props: QuartzComponentProps) => { |
| 15 | + const Drawer: QuartzComponent = ({ displayClass, fileData, allFiles }: QuartzComponentProps) => { |
11 | 16 | const links = opts?.links ?? [] |
| 17 | + const fileTree = new FileNode("") |
| 18 | + allFiles.forEach((file) => fileTree.add(file)) |
| 19 | + |
12 | 20 | return ( |
13 | 21 | <div class="drawer"> |
14 | 22 | <div class="drawer-wrapper"> |
| 23 | + <h3 class="drawer-title">MENU</h3> |
15 | 24 | <ul class="links"> |
16 | 25 | {Object.entries(links).map(([text, link]) => ( |
17 | 26 | <li> |
18 | 27 | <a href={link}>{text}</a> |
19 | 28 | </li> |
20 | 29 | ))} |
21 | 30 | </ul> |
| 31 | + <div class={classNames(displayClass, "toc")}> |
| 32 | + <button |
| 33 | + type="button" |
| 34 | + id="toc" |
| 35 | + class={fileData.collapseToc ? "collapsed" : ""} |
| 36 | + aria-controls="toc-content" |
| 37 | + aria-expanded={!fileData.collapseToc} |
| 38 | + > |
| 39 | + <h3>Patterns</h3> |
| 40 | + <svg |
| 41 | + xmlns="http://www.w3.org/2000/svg" |
| 42 | + width="24" |
| 43 | + height="24" |
| 44 | + viewBox="0 0 24 24" |
| 45 | + fill="none" |
| 46 | + stroke="currentColor" |
| 47 | + stroke-width="2" |
| 48 | + stroke-linecap="round" |
| 49 | + stroke-linejoin="round" |
| 50 | + class="fold" |
| 51 | + > |
| 52 | + <polyline points="6 9 12 15 18 9"></polyline> |
| 53 | + </svg> |
| 54 | + </button> |
| 55 | + <div id="toc-content" class={fileData.collapseToc ? "collapsed" : ""}> |
| 56 | + <ul class="overflow"> |
| 57 | + {allFiles.map((value) => { |
| 58 | + return ( |
| 59 | + <li key={value.slug}> |
| 60 | + <a href={resolveRelative(value.slug!, value.slug!)} data-for={value.slug}>{value.frontmatter?.title}</a> |
| 61 | + </li> |
| 62 | + ) |
| 63 | + })} |
| 64 | + </ul> |
| 65 | + </div> |
| 66 | + </div> |
22 | 67 | </div> |
23 | 68 | </div> |
24 | 69 | ) |
25 | 70 | } |
26 | 71 |
|
27 | 72 | Drawer.css = style |
| 73 | + Drawer.afterDOMLoaded = script |
28 | 74 |
|
29 | 75 | return Drawer |
30 | 76 | }) satisfies QuartzComponentConstructor |
0 commit comments