Skip to content

Commit d7b2037

Browse files
Added menu button logic to display SVG icons when clicked, along with CSS for the Drawer Component and NavigationLinks Component.
1 parent 3ff849e commit d7b2037

File tree

6 files changed

+100
-12
lines changed

6 files changed

+100
-12
lines changed

quartz/components/Drawer.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ interface Options {
99
export default ((opts?: Options) => {
1010
const Drawer: QuartzComponent = (props: QuartzComponentProps) => {
1111
const links = opts?.links ?? []
12-
return <div class="drawer">Drawer</div>
12+
return (
13+
<div class="drawer">
14+
<div class="drawer-wrapper">
15+
<ul class="links">
16+
{Object.entries(links).map(([text, link]) => (
17+
<li>
18+
<a href={link}>{text}</a>
19+
</li>
20+
))}
21+
</ul>
22+
</div>
23+
</div>
24+
)
1325
}
1426

1527
Drawer.css = style

quartz/components/NavigationLinks.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,30 @@ interface Options {
1111
export default ((opts?: Options) => {
1212
const NavigationLinks: QuartzComponent = (props: QuartzComponentProps) => {
1313
const links = opts?.links ?? []
14+
let crossactive = false
15+
1416
return (
1517
<nav class="nav-links">
16-
<button className="menu-btn">Menu</button>
18+
<button className="menu-btn">
19+
<svg
20+
xmlns="http://www.w3.org/2000/svg"
21+
width="24"
22+
height="24"
23+
viewBox="0 0 24 24"
24+
stroke-width="2"
25+
stroke-linecap="round"
26+
stroke-linejoin="round"
27+
class="hamburger active"
28+
>
29+
<line x1="4" x2="20" y1="12" y2="12" />
30+
<line x1="4" x2="20" y1="6" y2="6" />
31+
<line x1="4" x2="20" y1="18" y2="18" />
32+
</svg>
33+
<svg width="24" height="24" class="cross">
34+
<line x1="5" y1="5" x2="19" y2="19" stroke-width="2" />
35+
<line x1="19" y1="5" x2="5" y2="19" stroke-width="2" />
36+
</svg>
37+
</button>
1738
<ul class="links">
1839
{Object.entries(links).map(([text, link]) => (
1940
<li>

quartz/components/scripts/drawer.inline.ts

Whitespace-only changes.

quartz/components/scripts/navigationlinks.inline.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@ let drawer = document.getElementsByClassName("drawer")[0]
22

33
document.getElementsByClassName("menu-btn")[0].addEventListener("click", () => {
44
drawer.classList.toggle("active")
5-
})
5+
6+
const isdrawerActive: boolean = drawer.classList.contains("active")
7+
assignActiveClassToDrawerButton(isdrawerActive)
8+
})
9+
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/styles/drawer.scss

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
width: 100vw;
88
transform: translateX(-100%);
99
transition: transform 0.3s ease;
10-
height: 100vh;
10+
height: 90vh;
1111
background-color: rgba(0, 0, 0, 0.5);
1212
color: var(--gray);
1313
z-index: 600;
14+
display: flex;
15+
justify-content: center;
16+
align-items: center;
1417
box-shadow:
1518
rgba(85, 86, 86, 0.48) 6px 2px 16px 0px,
1619
rgba(0, 0, 0, 0.8) -6px -2px 16px 0px;
1720

1821
&.active {
19-
display: block;
2022
transform: translateX(0);
2123
@media all and ($tablet) {
2224
transform: translateX(-100%);
@@ -27,3 +29,35 @@
2729
}
2830
}
2931
}
32+
33+
.drawer-wrapper {
34+
display: flex;
35+
flex-direction: column;
36+
gap: 8px;
37+
width: 80%;
38+
height: 90%;
39+
background-color: var(--light);
40+
41+
& > .links {
42+
display: flex;
43+
flex-direction: column;
44+
justify-content: center;
45+
gap: 5px;
46+
padding-left: 0;
47+
48+
& > li {
49+
list-style: none;
50+
text-align: center;
51+
display: inline-block;
52+
font-size: 18px;
53+
padding: 0 6px;
54+
55+
& > a {
56+
display: inline-block;
57+
text-decoration: none;
58+
color: inherit;
59+
padding: 2px 0;
60+
}
61+
}
62+
}
63+
}

quartz/components/styles/navigationlinks.scss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
& .menu-btn {
1616
display: none;
17-
padding: 5px 20px;
17+
padding-top: 5px;
1818
background-color: var(--light);
19-
border: 1px solid var(--tertiary);
20-
border-radius: 30px;
19+
border: none;
2120
font-family: var(--bodyFont);
2221
font-size: 15px;
2322
outline: none;
@@ -27,10 +26,8 @@
2726
cursor: pointer;
2827
}
2928

30-
&:hover {
31-
background-color: var(--tertiary);
32-
transition: background-color 0.3s ease-in;
33-
color: var(--light);
29+
& > .active {
30+
display: inline;
3431
}
3532
}
3633

@@ -76,3 +73,8 @@
7673
width: 100%;
7774
}
7875
}
76+
.hamburger,
77+
.cross {
78+
stroke: var(--darkgray);
79+
display: none;
80+
}

0 commit comments

Comments
 (0)