@@ -4,20 +4,91 @@ const currentYear = (new Date()).getFullYear();
4
4
const yearsRange = Array .from ({ length: currentYear - startYear + 1 }, (_ , i ) => startYear + i );
5
5
---
6
6
7
- <nav class =" w-64 bg-gray-200 p-4" >
8
- <ul >
7
+ <nav id =" sidebar" class =" w-64 bg-gray-800 text-white p-4 fixed inset-y-0 left-0 transform transition-transform duration-200 ease-in-out -translate-x-full sm:translate-x-0 sm:relative z-30 overflow-y-auto h-full" >
8
+ <div class =" flex justify-between items-center mb-4" >
9
+ <span class =" text-lg font-bold" >Menu</span >
10
+ <button id =" closeBtn" class =" text-white" >
11
+ <svg xmlns =" http://www.w3.org/2000/svg" class =" h-6 w-6" fill =" none" viewBox =" 0 0 24 24" stroke =" currentColor" >
12
+ <path stroke-linecap =" round" stroke-linejoin =" round" stroke-width =" 2" d =" M6 18L18 6M6 6l12 12" />
13
+ </svg >
14
+ </button >
15
+ </div >
16
+
17
+ <ul class =" space-y-2" >
9
18
{ yearsRange .map ((year ) => (
10
- <li >
11
- <a href = { ` /profiles/${year } ` } >{ year } </a >
12
- </li >
19
+ <li >
20
+ <a href = { ` /profiles/${year } ` } class = " block p-2 hover:bg-gray-700 rounded transition" >
21
+ { year }
22
+ </a >
23
+ </li >
13
24
))}
14
25
</ul >
15
- <hr />
16
- <ul >
17
- <li ><a href =" /profiles/it" >IT</a ></li >
18
- <li ><a href =" /profiles/elx" >ELX</a ></li >
19
- <li ><a href =" /profiles/cmp" >COMP</a ></li >
20
- <li ><a href =" /profiles/se" >SE</a ></li >
21
- <li ><a href =" /profiles/civil" >CIVIL</a ></li >
26
+
27
+ <hr class =" my-4 border-gray-600" />
28
+
29
+ <ul class =" space-y-2" >
30
+ <li ><a href =" /profiles/it" class =" block p-2 hover:bg-gray-700 rounded transition" >IT</a ></li >
31
+ <li ><a href =" /profiles/elx" class =" block p-2 hover:bg-gray-700 rounded transition" >ELX</a ></li >
32
+ <li ><a href =" /profiles/cmp" class =" block p-2 hover:bg-gray-700 rounded transition" >COMP</a ></li >
33
+ <li ><a href =" /profiles/se" class =" block p-2 hover:bg-gray-700 rounded transition" >SE</a ></li >
34
+ <li ><a href =" /profiles/civil" class =" block p-2 hover:bg-gray-700 rounded transition" >CIVIL</a ></li >
22
35
</ul >
23
- </nav >
36
+ </nav >
37
+
38
+ <div id =" backdrop" class =" fixed inset-0 bg-black bg-opacity-50 z-20 hidden" ></div >
39
+
40
+ <button id =" toggleBtn" class =" sm:hidden text-white fixed top-4 left-4 z-40" >
41
+ <svg xmlns =" http://www.w3.org/2000/svg" class =" h-6 w-6" fill =" none" viewBox =" 0 0 24 24" stroke =" currentColor" >
42
+ <path stroke-linecap =" round" stroke-linejoin =" round" stroke-width =" 2" d =" M4 6h16M4 12h16m-7 6h7" />
43
+ </svg >
44
+ </button >
45
+
46
+ <script >
47
+ document.addEventListener('DOMContentLoaded', () => {
48
+ const sidebar = document.getElementById('sidebar');
49
+ const backdrop = document.getElementById('backdrop');
50
+ const toggleBtn = document.getElementById('toggleBtn');
51
+ const closeBtn = document.getElementById('closeBtn');
52
+
53
+ function toggleSidebar() {
54
+ console.log("opening sidebar")
55
+ const isHidden = sidebar.classList.toggle('-translate-x-full');
56
+ backdrop.classList.toggle('hidden', isHidden);
57
+ if (!isHidden) {
58
+ document.body.style.overflow = 'hidden'; // Disable scrolling
59
+ } else {
60
+ document.body.style.overflow = ''; // Enable scrolling
61
+ }
62
+ }
63
+
64
+ function closeSidebar() {
65
+ console.log("closing sidebar")
66
+ sidebar.classList.add('-translate-x-full');
67
+ backdrop.classList.add('hidden');
68
+ document.body.style.overflow = ''; // Enable scrolling
69
+ }
70
+
71
+ toggleBtn.addEventListener('click', toggleSidebar);
72
+ closeBtn.addEventListener('click', closeSidebar);
73
+ backdrop.addEventListener('click', closeSidebar);
74
+ });
75
+ </script >
76
+
77
+
78
+ <style >
79
+ @media (min-width: 640px) {
80
+ #sidebar {
81
+ transform: translateX(0);
82
+ }
83
+ }
84
+
85
+ @media (max-width: 639px) {
86
+ #sidebar {
87
+ transform: -translateX(-100%);
88
+ }
89
+ }
90
+
91
+ #backdrop {
92
+ transition: opacity 0.3s ease;
93
+ }
94
+ </style >
0 commit comments