moreiraj93 commited on
Commit
d7a36e7
·
verified ·
1 Parent(s): 84844d3

make the background dark buttins movable with a drop down menu

Browse files
Files changed (2) hide show
  1. components/sidebar.js +87 -121
  2. style.css +1 -17
components/sidebar.js CHANGED
@@ -1,9 +1,7 @@
1
-
2
  class CustomSidebar extends HTMLElement {
3
  constructor() {
4
  super();
5
- this.darkMode = true;
6
- this.collapsed = false;
7
  }
8
 
9
  connectedCallback() {
@@ -16,168 +14,101 @@ class CustomSidebar extends HTMLElement {
16
  this.shadowRoot.innerHTML = `
17
  <style>
18
  .sidebar {
19
- width: 250px;
20
  min-height: 100vh;
21
- background-color: #1a1a1a;
22
- color: #fff;
23
  display: flex;
24
  flex-direction: column;
25
  padding: 1.5rem;
 
 
26
  position: fixed;
27
  top: 0;
28
  left: 0;
29
  z-index: 1000;
30
- transition: all 0.3s ease;
31
- border-right: 1px solid #333;
32
- }
33
-
34
- .sidebar.collapsed {
35
- width: 70px;
36
- overflow: hidden;
37
- }
38
-
39
- .sidebar.collapsed .nav-text,
40
- .sidebar.collapsed h2 {
41
- display: none;
42
- }
43
-
44
- .toggle-sidebar {
45
- position: absolute;
46
- right: 10px;
47
- top: 10px;
48
- background: none;
49
- border: none;
50
- color: #fff;
51
- cursor: pointer;
52
- font-size: 1.2rem;
53
  }
54
 
55
- .sidebar-header {
56
- display: flex;
57
- align-items: center;
58
- margin-bottom: 2rem;
59
- padding-bottom: 1rem;
60
- border-bottom: 1px solid #333;
61
  }
62
 
63
- .menu-icon {
64
- margin-right: 10px;
65
- min-width: 24px;
 
66
  }
67
 
68
  .nav-item {
69
- display: flex;
70
- align-items: center;
71
- padding: 0.75rem;
72
  margin-bottom: 0.5rem;
73
  cursor: pointer;
74
- border-radius: 6px;
75
- transition: all 0.2s ease;
 
76
  }
77
 
78
  .nav-item:hover {
79
- background-color: #333;
80
- }
81
-
82
- .nav-item.active {
83
- background-color: #ff4777;
84
- }
85
-
86
- .submenu {
87
- margin-left: 1.5rem;
88
- max-height: 0;
89
- overflow: hidden;
90
- transition: max-height 0.3s ease;
91
- }
92
-
93
- .submenu.open {
94
- max-height: 500px;
95
- }
96
-
97
- .submenu-item {
98
- padding: 0.5rem 0;
99
- color: #aaa;
100
- transition: color 0.2s;
101
- }
102
-
103
- .submenu-item:hover {
104
- color: #fff;
105
  }
106
 
107
- .theme-toggle {
108
- margin-top: auto;
109
- margin-bottom: 1rem;
110
  }
111
 
112
  .toggle-btn {
113
- width: 100%;
114
- background: #333;
115
  color: #fff;
116
  border: none;
117
- padding: 0.75rem;
118
  border-radius: 6px;
119
  cursor: pointer;
120
- display: flex;
121
- align-items: center;
122
- justify-content: center;
123
- transition: background 0.2s;
124
  }
125
 
126
  .toggle-btn:hover {
127
- background: #444;
128
  }
129
 
130
- .toggle-btn i {
131
- margin-right: 0.5rem;
 
132
  }
133
  </style>
134
- <div class="sidebar ${this.collapsed ? 'collapsed' : ''} dark">
135
- <button class="toggle-sidebar">${this.collapsed ? '☰' : '×'}</button>
136
-
137
- <div class="sidebar-header">
138
- <span class="menu-icon">☰</span>
139
- <h2>MLTX Menu</h2>
140
- </div>
141
-
142
- <div class="nav-item active">
143
- <span class="menu-icon">🏠</span>
144
- <span class="nav-text"><a href="/" style="text-decoration: none; color: inherit;">Dashboard</a></span>
145
- </div>
146
-
147
- <div class="nav-item">
148
- <span class="menu-icon">📦</span>
149
- <span class="nav-text"><a href="/orders.html" style="text-decoration: none; color: inherit;">Orders</a></span>
150
- </div>
151
-
152
- <div class="nav-item with-submenu">
153
- <span class="menu-icon">⚙️</span>
154
- <span class="nav-text">Settings</span>
155
- <span class="submenu-icon">▼</span>
156
- </div>
157
- <div class="submenu">
158
- <div class="submenu-item"><a href="/settings.html" style="text-decoration: none; color: inherit;">General</a></div>
159
- <div class="submenu-item"><a href="/profile.html" style="text-decoration: none; color: inherit;">Profile</a></div>
160
- <div class="submenu-item"><a href="/security.html" style="text-decoration: none; color: inherit;">Security</a></div>
161
- </div>
162
 
163
- <div class="theme-toggle">
164
- <button class="toggle-btn">
165
- <i>🌓</i>
166
- <span class="nav-text">Toggle Theme</span>
167
- </button>
168
- </div>
169
  </div>
170
- `;
171
  }
172
-
173
  setupEventListeners() {
174
  const toggleBtn = this.shadowRoot.querySelector('.toggle-btn');
 
175
  const sidebar = this.shadowRoot.querySelector('.sidebar');
 
 
 
 
 
 
 
 
176
 
 
177
  toggleBtn.addEventListener('click', () => {
178
  this.darkMode = !this.darkMode;
179
- sidebar.classList.toggle('dark', this.darkMode);
180
- toggleBtn.textContent = `Toggle ${this.darkMode ? 'Light' : 'Dark'} Mode`;
181
 
182
  // Dispatch custom event for other components
183
  this.dispatchEvent(new CustomEvent('darkModeToggle', {
@@ -185,7 +116,42 @@ class CustomSidebar extends HTMLElement {
185
  bubbles: true
186
  }));
187
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
189
  }
 
190
 
191
- customElements.define('custom-sidebar', CustomSidebar);
 
 
 
 
 
 
 
1
  class CustomSidebar extends HTMLElement {
2
  constructor() {
3
  super();
4
+ this.darkMode = false;
 
5
  }
6
 
7
  connectedCallback() {
 
14
  this.shadowRoot.innerHTML = `
15
  <style>
16
  .sidebar {
17
+ width: 220px;
18
  min-height: 100vh;
19
+ background-color: var(--sidebar-bg, #f0f0f0);
20
+ color: var(--sidebar-color, #222);
21
  display: flex;
22
  flex-direction: column;
23
  padding: 1.5rem;
24
+ box-shadow: var(--sidebar-shadow, 2px 0 8px rgba(0,0,0,0.1));
25
+ transition: all 0.3s ease;
26
  position: fixed;
27
  top: 0;
28
  left: 0;
29
  z-index: 1000;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
+ .sidebar.dark {
33
+ --sidebar-bg: #1a1a1a;
34
+ --sidebar-color: #fff;
35
+ --sidebar-shadow: 2px 0 8px rgba(0,0,0,0.6);
 
 
36
  }
37
 
38
+ .sidebar h2 {
39
+ margin-bottom: 1.5rem;
40
+ font-size: 1.5rem;
41
+ font-weight: 600;
42
  }
43
 
44
  .nav-item {
45
+ padding: 0.5rem 0;
 
 
46
  margin-bottom: 0.5rem;
47
  cursor: pointer;
48
+ border-radius: 4px;
49
+ transition: background 0.2s ease;
50
+ padding-left: 0.5rem;
51
  }
52
 
53
  .nav-item:hover {
54
+ background-color: var(--nav-hover, rgba(0,0,0,0.1));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
+ .dark .nav-item:hover {
58
+ --nav-hover: rgba(255,255,255,0.1);
 
59
  }
60
 
61
  .toggle-btn {
62
+ background-color: var(--btn-bg, #0078d4);
 
63
  color: #fff;
64
  border: none;
65
+ padding: 0.5rem 1rem;
66
  border-radius: 6px;
67
  cursor: pointer;
68
+ margin-top: auto;
69
+ transition: background 0.2s ease;
70
+ font-size: 0.9rem;
 
71
  }
72
 
73
  .toggle-btn:hover {
74
+ background-color: var(--btn-hover, #005a9e);
75
  }
76
 
77
+ .dark .toggle-btn {
78
+ --btn-bg: #1e88e5;
79
+ --btn-hover: #1565c0;
80
  }
81
  </style>
82
+ <div class="sidebar">
83
+ <h2>MLTX Menu</h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
+ <div class="nav-item"><a href="/" style="text-decoration: none; color: inherit;">Dashboard</a></div>
86
+ <div class="nav-item"><a href="/orders.html" style="text-decoration: none; color: inherit;">Orders</a></div>
87
+ <div class="nav-item"><a href="/settings.html" style="text-decoration: none; color: inherit;">Settings</a></div>
88
+ <div class="nav-item"><a href="/profile.html" style="text-decoration: none; color: inherit;">Profile</a></div>
89
+
90
+ <button class="toggle-btn">Toggle Light Mode</button>
91
  </div>
92
+ `;
93
  }
 
94
  setupEventListeners() {
95
  const toggleBtn = this.shadowRoot.querySelector('.toggle-btn');
96
+ const menuToggle = this.shadowRoot.querySelector('.menu-toggle');
97
  const sidebar = this.shadowRoot.querySelector('.sidebar');
98
+ const dropdown = this.shadowRoot.querySelector('.dropdown');
99
+
100
+ // Toggle sidebar collapse
101
+ menuToggle.addEventListener('click', () => {
102
+ this.collapsed = !this.collapsed;
103
+ sidebar.classList.toggle('collapsed', this.collapsed);
104
+ this.saveState();
105
+ });
106
 
107
+ // Toggle dark mode
108
  toggleBtn.addEventListener('click', () => {
109
  this.darkMode = !this.darkMode;
110
+ document.documentElement.classList.toggle('dark', this.darkMode);
111
+ this.saveState();
112
 
113
  // Dispatch custom event for other components
114
  this.dispatchEvent(new CustomEvent('darkModeToggle', {
 
116
  bubbles: true
117
  }));
118
  });
119
+
120
+ // Toggle dropdown
121
+ dropdown.addEventListener('click', () => {
122
+ dropdown.classList.toggle('active');
123
+ });
124
+
125
+ // Initialize from localStorage
126
+ this.loadState();
127
+ feather.replace();
128
+ }
129
+
130
+ saveState() {
131
+ localStorage.setItem('sidebarCollapsed', this.collapsed);
132
+ localStorage.setItem('darkMode', this.darkMode);
133
+ }
134
+
135
+ loadState() {
136
+ const collapsed = localStorage.getItem('sidebarCollapsed') === 'true';
137
+ const darkMode = localStorage.getItem('darkMode') === 'true';
138
+
139
+ if (collapsed) {
140
+ this.collapsed = true;
141
+ this.shadowRoot.querySelector('.sidebar').classList.add('collapsed');
142
+ }
143
+
144
+ if (darkMode) {
145
+ this.darkMode = true;
146
+ document.documentElement.classList.add('dark');
147
+ }
148
  }
149
  }
150
+ customElements.define('custom-sidebar', CustomSidebar);
151
 
152
+ // Initialize dark mode if set
153
+ document.addEventListener('DOMContentLoaded', () => {
154
+ if (localStorage.getItem('darkMode') === 'true') {
155
+ document.documentElement.classList.add('dark');
156
+ }
157
+ });
style.css CHANGED
@@ -3,28 +3,12 @@
3
  * {
4
  font-family: 'Inter', sans-serif;
5
  }
 
6
  /* Smooth scroll behavior */
7
  html {
8
  scroll-behavior: smooth;
9
  }
10
 
11
- /* Dark mode by default */
12
- html.dark {
13
- background-color: #111;
14
- color: #fff;
15
- }
16
-
17
- /* Main content margin for sidebar */
18
- .main-content {
19
- margin-left: 250px;
20
- transition: margin-left 0.3s ease;
21
- padding: 2rem;
22
- }
23
-
24
- /* Collapsed sidebar state */
25
- .sidebar.collapsed ~ .main-content {
26
- margin-left: 70px;
27
- }
28
  /* Custom scrollbar */
29
  ::-webkit-scrollbar {
30
  width: 8px;
 
3
  * {
4
  font-family: 'Inter', sans-serif;
5
  }
6
+
7
  /* Smooth scroll behavior */
8
  html {
9
  scroll-behavior: smooth;
10
  }
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  /* Custom scrollbar */
13
  ::-webkit-scrollbar {
14
  width: 8px;