|
| 1 | +import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" |
| 2 | +import style from "./styles/drawer.scss" |
| 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" |
| 9 | + |
| 10 | +interface Options { |
| 11 | + links?: Record<string, string> |
| 12 | +} |
| 13 | + |
| 14 | +export default ((opts?: Options) => { |
| 15 | + const Drawer: QuartzComponent = ({ displayClass, fileData, allFiles }: QuartzComponentProps) => { |
| 16 | + const links = opts?.links ?? [] |
| 17 | + const fileTree = new FileNode("") |
| 18 | + allFiles.forEach((file) => fileTree.add(file)) |
| 19 | + |
| 20 | + return ( |
| 21 | + <div class="drawer"> |
| 22 | + <div class="drawer-wrapper"> |
| 23 | + <h3 class="drawer-title">MENU</h3> |
| 24 | + <ul class="links"> |
| 25 | + {Object.entries(links).map(([text, link]) => ( |
| 26 | + <li> |
| 27 | + <a href={link}>{text}</a> |
| 28 | + </li> |
| 29 | + ))} |
| 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> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + Drawer.css = style |
| 73 | + Drawer.afterDOMLoaded = script |
| 74 | + |
| 75 | + return Drawer |
| 76 | +}) satisfies QuartzComponentConstructor |
0 commit comments