Skip to content

Commit 56cc344

Browse files
Drawer Component with All Patterns links in the Drawer
1 parent d7b2037 commit 56cc344

File tree

6 files changed

+99
-34
lines changed

6 files changed

+99
-34
lines changed

quartz.layout.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ export const sharedPageComponents: SharedLayout = {
1616
Component.Darkmode()
1717
],
1818
head: Component.Head(),
19-
header: [],
19+
header: [Component.MobileOnly(
20+
Component.Drawer({
21+
links: {
22+
Blogs: "/blogs",
23+
Github: "https://github.com/PrathameshDhande22/Java-Tutorial",
24+
"About Me": "https://github.com/PrathameshDhande22"
25+
}
26+
})
27+
)],
2028
afterBody: [],
2129
footer: Component.Footer({
2230
links: {
@@ -35,15 +43,6 @@ export const defaultContentPageLayout: PageLayout = {
3543
Component.TagList(),
3644
],
3745
left: [
38-
Component.MobileOnly(
39-
Component.Drawer({
40-
links: {
41-
Blogs: "/blogs",
42-
Github: "https://github.com/PrathameshDhande22/Java-Tutorial",
43-
"About Me": "https://github.com/PrathameshDhande22"
44-
}
45-
})
46-
),
4746
Component.Search(),
4847
Component.DesktopOnly(
4948
Component.Explorer({

quartz/components/Drawer.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,76 @@
11
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
22
import style from "./styles/drawer.scss"
33
// @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"
49

510
interface Options {
611
links?: Record<string, string>
712
}
813

914
export default ((opts?: Options) => {
10-
const Drawer: QuartzComponent = (props: QuartzComponentProps) => {
15+
const Drawer: QuartzComponent = ({ displayClass, fileData, allFiles }: QuartzComponentProps) => {
1116
const links = opts?.links ?? []
17+
const fileTree = new FileNode("")
18+
allFiles.forEach((file) => fileTree.add(file))
19+
1220
return (
1321
<div class="drawer">
1422
<div class="drawer-wrapper">
23+
<h3 class="drawer-title">MENU</h3>
1524
<ul class="links">
1625
{Object.entries(links).map(([text, link]) => (
1726
<li>
1827
<a href={link}>{text}</a>
1928
</li>
2029
))}
2130
</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>
2267
</div>
2368
</div>
2469
)
2570
}
2671

2772
Drawer.css = style
73+
Drawer.afterDOMLoaded = script
2874

2975
return Drawer
3076
}) satisfies QuartzComponentConstructor
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { assignActiveClassToDrawerButton } from "./util"
2+
3+
const drawerele = document.querySelector(".drawer")
4+
drawerele?.addEventListener("click", () => {
5+
drawerele.classList.remove("active")
6+
7+
const isdrawerActive: boolean = drawerele.classList.contains("active")
8+
assignActiveClassToDrawerButton(isdrawerActive)
9+
})
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1+
import { assignActiveClassToDrawerButton } from "./util"
2+
13
let drawer = document.getElementsByClassName("drawer")[0]
24

35
document.getElementsByClassName("menu-btn")[0].addEventListener("click", () => {
4-
drawer.classList.toggle("active")
6+
drawer.classList.add("active")
57

68
const isdrawerActive: boolean = drawer.classList.contains("active")
79
assignActiveClassToDrawerButton(isdrawerActive)
810
})
911

10-
function assignActiveClassToDrawerButton(isactive: boolean) {
11-
const hamburgersvg = document.querySelector(".hamburger")
12-
13-
const cross = document.querySelector(".cross")
14-
15-
if (isactive) {
16-
cross?.classList.add("active")
17-
hamburgersvg?.classList.remove("active")
18-
19-
} else {
20-
cross?.classList.remove("active")
21-
hamburgersvg?.classList.add("active")
22-
23-
}
24-
}

quartz/components/scripts/util.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ export async function fetchCanonical(url: URL): Promise<Response> {
4343
const [_, redirect] = text.match(canonicalRegex) ?? []
4444
return redirect ? fetch(`${new URL(redirect, url)}`) : res
4545
}
46+
47+
export function assignActiveClassToDrawerButton(isactive: boolean) {
48+
const hamburgersvg = document.querySelector(".hamburger")
49+
const cross = document.querySelector(".cross")
50+
51+
if (isactive) {
52+
cross?.classList.add("active")
53+
hamburgersvg?.classList.remove("active")
54+
document.body.style.overflow = "hidden"
55+
document.body.style.height = "100vh"
56+
} else {
57+
cross?.classList.remove("active")
58+
hamburgersvg?.classList.add("active")
59+
document.body.style.overflow = "auto"
60+
document.body.style.height = "100%"
61+
}
62+
}

quartz/components/styles/drawer.scss

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
.drawer {
44
position: fixed;
5-
top: 60px;
5+
top: 0px;
66
right: 0;
77
width: 100vw;
88
transform: translateX(-100%);
99
transition: transform 0.3s ease;
10-
height: 90vh;
10+
height: 100vh;
1111
background-color: rgba(0, 0, 0, 0.5);
1212
color: var(--gray);
1313
z-index: 600;
@@ -30,27 +30,34 @@
3030
}
3131
}
3232

33+
.drawer-title{
34+
margin-top: 1rem;
35+
margin-bottom: 0.5rem;
36+
text-align: center;
37+
color: var(--secondary);
38+
}
39+
3340
.drawer-wrapper {
3441
display: flex;
3542
flex-direction: column;
3643
gap: 8px;
37-
width: 80%;
38-
height: 90%;
44+
width: 70%;
45+
height: 85%;
46+
padding: 10px 10px 10px 20px;
3947
background-color: var(--light);
4048

4149
& > .links {
4250
display: flex;
4351
flex-direction: column;
4452
justify-content: center;
4553
gap: 5px;
46-
padding-left: 0;
54+
padding: 0;
55+
margin: 0;
4756

4857
& > li {
4958
list-style: none;
50-
text-align: center;
5159
display: inline-block;
5260
font-size: 18px;
53-
padding: 0 6px;
5461

5562
& > a {
5663
display: inline-block;

0 commit comments

Comments
 (0)