Skip to content

Commit 570b827

Browse files
Merge pull request #73 from KharuRai/feature/sidebar-arrow-button
feat: Add arrow button to show collapsed sidebar
2 parents 59f2b74 + 26b2af2 commit 570b827

File tree

1 file changed

+103
-3
lines changed

1 file changed

+103
-3
lines changed

index.html

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
margin: 2rem 0 1.5rem;
265265
color: var(--hf-orange);
266266
background: linear-gradient(90deg, var(--hf-orange), var(--hf-purple));
267+
background-clip: text;
267268
-webkit-background-clip: text;
268269
-webkit-text-fill-color: transparent;
269270
}
@@ -380,6 +381,10 @@
380381
margin-right: 0;
381382
}
382383

384+
.sidebar.collapsed .brand .brand-text {
385+
display: none;
386+
}
387+
383388
.sidebar.collapsed #toc {
384389
display: none;
385390
}
@@ -404,6 +409,46 @@
404409
display: none;
405410
}
406411

412+
/* Show/Hide arrow button styles */
413+
.show-sidebar-btn {
414+
position: fixed;
415+
top: 50%;
416+
left: 20px;
417+
transform: translateY(-50%);
418+
background: linear-gradient(135deg, var(--hf-orange), var(--hf-purple));
419+
border: none;
420+
color: var(--hf-light);
421+
width: 50px;
422+
height: 50px;
423+
border-radius: 50%;
424+
cursor: pointer;
425+
font-size: 1.2rem;
426+
box-shadow: 0 4px 15px rgba(155, 89, 182, 0.3);
427+
transition: all 0.3s ease;
428+
z-index: 1001;
429+
display: none;
430+
align-items: center;
431+
justify-content: center;
432+
}
433+
434+
.show-sidebar-btn:hover {
435+
transform: translateY(-50%) scale(1.1);
436+
box-shadow: 0 6px 20px rgba(155, 89, 182, 0.4);
437+
}
438+
439+
.show-sidebar-btn.visible {
440+
display: flex;
441+
}
442+
443+
.show-sidebar-btn::before {
444+
content: "→";
445+
transition: transform 0.3s ease;
446+
}
447+
448+
.show-sidebar-btn:hover::before {
449+
transform: translateX(3px);
450+
}
451+
407452
@keyframes fadeIn {
408453
from {
409454
opacity: 0;
@@ -746,8 +791,8 @@
746791
<aside class="sidebar" id="sidebar" aria-label="Table of contents">
747792
<div class="brand">
748793
<a href="./" title="Home"
749-
><span class="logo-blob" aria-hidden="true"></span>Hacktoberfest
750-
2025</a
794+
><span class="logo-blob" aria-hidden="true"></span
795+
><span class="brand-text">Hacktoberfest 2025</span></a
751796
>
752797
</div>
753798

@@ -782,6 +827,14 @@
782827
</footer>
783828
</aside>
784829

830+
<!-- Show sidebar button (appears when sidebar is collapsed) -->
831+
<button
832+
id="show-sidebar-btn"
833+
class="show-sidebar-btn"
834+
aria-label="Show sidebar"
835+
title="Show sidebar"
836+
></button>
837+
785838
<main class="content" id="content" role="main">
786839
<div class="bg-decor" aria-hidden="true">
787840
<svg viewBox="0 0 100 100" preserveAspectRatio="none">
@@ -1033,9 +1086,29 @@ <h1 class="loading-title">Loading README.md…</h1>
10331086
// TOC toggle for small screens
10341087
document.getElementById("toc-toggle").addEventListener("click", (e) => {
10351088
const sidebar = document.getElementById("sidebar");
1089+
const showBtn = document.getElementById("show-sidebar-btn");
10361090
const expanded = sidebar.classList.toggle("collapsed");
10371091
e.target.textContent = expanded ? "Show" : "Hide";
10381092
e.target.setAttribute("aria-expanded", String(!expanded));
1093+
1094+
// Show/hide the arrow button
1095+
if (expanded) {
1096+
showBtn.classList.add("visible");
1097+
} else {
1098+
showBtn.classList.remove("visible");
1099+
}
1100+
});
1101+
1102+
// Show sidebar button functionality
1103+
document.getElementById("show-sidebar-btn").addEventListener("click", () => {
1104+
const sidebar = document.getElementById("sidebar");
1105+
const showBtn = document.getElementById("show-sidebar-btn");
1106+
const tocToggle = document.getElementById("toc-toggle");
1107+
1108+
sidebar.classList.remove("collapsed");
1109+
showBtn.classList.remove("visible");
1110+
tocToggle.textContent = "Hide";
1111+
tocToggle.setAttribute("aria-expanded", "true");
10391112
});
10401113

10411114
// Navbar interactions: focus search and toggle sidebar
@@ -1050,18 +1123,39 @@ <h1 class="loading-title">Loading README.md…</h1>
10501123
});
10511124
document.getElementById("hamburger").addEventListener("click", () => {
10521125
const sidebar = document.getElementById("sidebar");
1053-
sidebar.classList.toggle("collapsed");
1126+
const showBtn = document.getElementById("show-sidebar-btn");
1127+
const tocToggle = document.getElementById("toc-toggle");
1128+
const expanded = sidebar.classList.toggle("collapsed");
1129+
1130+
// Update show button visibility
1131+
if (expanded) {
1132+
showBtn.classList.add("visible");
1133+
} else {
1134+
showBtn.classList.remove("visible");
1135+
}
1136+
1137+
// Update TOC toggle text
1138+
tocToggle.textContent = expanded ? "Show" : "Hide";
1139+
tocToggle.setAttribute("aria-expanded", String(!expanded));
10541140
});
10551141

10561142
// Auto-collapse sidebar on mobile and handle window resize
10571143
function handleSidebarResponsiveness() {
10581144
const sidebar = document.getElementById("sidebar");
1145+
const showBtn = document.getElementById("show-sidebar-btn");
1146+
const tocToggle = document.getElementById("toc-toggle");
10591147
const isMobile = window.innerWidth <= 900;
10601148

10611149
if (isMobile) {
10621150
sidebar.classList.add("collapsed");
1151+
showBtn.classList.add("visible");
1152+
tocToggle.textContent = "Show";
1153+
tocToggle.setAttribute("aria-expanded", "false");
10631154
} else {
10641155
sidebar.classList.remove("collapsed");
1156+
showBtn.classList.remove("visible");
1157+
tocToggle.textContent = "Hide";
1158+
tocToggle.setAttribute("aria-expanded", "true");
10651159
}
10661160
}
10671161

@@ -1073,15 +1167,21 @@ <h1 class="loading-title">Loading README.md…</h1>
10731167
document.addEventListener("click", (e) => {
10741168
const sidebar = document.getElementById("sidebar");
10751169
const hamburger = document.getElementById("hamburger");
1170+
const showBtn = document.getElementById("show-sidebar-btn");
1171+
const tocToggle = document.getElementById("toc-toggle");
10761172
const isMobile = window.innerWidth <= 900;
10771173

10781174
if (
10791175
isMobile &&
10801176
!sidebar.contains(e.target) &&
10811177
!hamburger.contains(e.target) &&
1178+
!showBtn.contains(e.target) &&
10821179
!sidebar.classList.contains("collapsed")
10831180
) {
10841181
sidebar.classList.add("collapsed");
1182+
showBtn.classList.add("visible");
1183+
tocToggle.textContent = "Show";
1184+
tocToggle.setAttribute("aria-expanded", "false");
10851185
}
10861186
});
10871187

0 commit comments

Comments
 (0)