Nitish commited on
Commit
979995a
·
1 Parent(s): 1af53e9

feat: add dark/light mode toggle with persistence

Browse files
Files changed (3) hide show
  1. static/index.html +5 -1
  2. static/main.js +30 -1
  3. static/style.css +58 -10
static/index.html CHANGED
@@ -1,5 +1,5 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -33,6 +33,10 @@
33
  <button class="mac-tab" data-tab="details">Model Details</button>
34
  <button class="mac-tab" data-tab="specs">API Specs</button>
35
  </div>
 
 
 
 
36
  </div>
37
 
38
  <div class="window-content">
 
1
  <!DOCTYPE html>
2
+ <html lang="en" data-theme="dark">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
33
  <button class="mac-tab" data-tab="details">Model Details</button>
34
  <button class="mac-tab" data-tab="specs">API Specs</button>
35
  </div>
36
+ <button id="theme-toggle" class="theme-toggle" title="Toggle Theme">
37
+ <svg id="sun-icon" class="hidden" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>
38
+ <svg id="moon-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
39
+ </button>
40
  </div>
41
 
42
  <div class="window-content">
static/main.js CHANGED
@@ -28,11 +28,40 @@ document.addEventListener('DOMContentLoaded', () => {
28
 
29
  // Tab elements
30
  tabs: document.querySelectorAll('.mac-tab'),
31
- panes: document.querySelectorAll('.tab-pane')
 
 
 
 
 
 
32
  };
33
 
34
  let isDone = false;
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  // Tab Switching Logic
37
  elements.tabs.forEach(tab => {
38
  tab.addEventListener('click', () => {
 
28
 
29
  // Tab elements
30
  tabs: document.querySelectorAll('.mac-tab'),
31
+ panes: document.querySelectorAll('.tab-pane'),
32
+
33
+ // Theme elements
34
+ themeToggle: document.getElementById('theme-toggle'),
35
+ html: document.documentElement,
36
+ sunIcon: document.getElementById('sun-icon'),
37
+ moonIcon: document.getElementById('moon-icon')
38
  };
39
 
40
  let isDone = false;
41
 
42
+ // Theme Logic
43
+ function setTheme(theme) {
44
+ elements.html.setAttribute('data-theme', theme);
45
+ localStorage.setItem('theme', theme);
46
+
47
+ if (theme === 'dark') {
48
+ elements.sunIcon.classList.add('hidden');
49
+ elements.moonIcon.classList.remove('hidden');
50
+ } else {
51
+ elements.sunIcon.classList.remove('hidden');
52
+ elements.moonIcon.classList.add('hidden');
53
+ }
54
+ }
55
+
56
+ // Initialize theme
57
+ const savedTheme = localStorage.getItem('theme') || 'dark';
58
+ setTheme(savedTheme);
59
+
60
+ elements.themeToggle.addEventListener('click', () => {
61
+ const currentTheme = elements.html.getAttribute('data-theme');
62
+ setTheme(currentTheme === 'dark' ? 'light' : 'dark');
63
+ });
64
+
65
  // Tab Switching Logic
66
  elements.tabs.forEach(tab => {
67
  tab.addEventListener('click', () => {
static/style.css CHANGED
@@ -1,17 +1,39 @@
1
- :root {
 
 
 
 
2
  --bg-primary: #000000;
3
  --bg-card: #151515;
4
  --bg-input: #1f1f1f;
5
  --border-card: #2e2e2e;
6
  --border-input: #3e3e3e;
7
-
8
- /* NVIDIA Green */
9
- --accent-primary: #76b900;
10
  --accent-hover: #88d400;
11
  --accent-glow: rgba(118, 185, 0, 0.2);
12
-
13
  --text-main: #ffffff;
14
  --text-muted: #a1a1aa;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  --success: #76b900;
16
  --error: #ef4444;
17
  }
@@ -75,7 +97,7 @@ h1 {
75
  }
76
 
77
  .mac-title-bar {
78
- background: #1a1a1a;
79
  height: 44px;
80
  display: flex;
81
  align-items: center;
@@ -255,14 +277,14 @@ h2 {
255
  }
256
 
257
  .code-container {
258
- background: #09090b;
259
  border-radius: 6px;
260
  overflow: hidden;
261
  border: 1px solid var(--border-card);
262
  }
263
 
264
  .code-header {
265
- background: #18181b;
266
  padding: 0.5rem 1rem;
267
  font-size: 0.75rem;
268
  color: var(--text-muted);
@@ -355,7 +377,7 @@ button {
355
  position: fixed;
356
  bottom: 2rem;
357
  right: 2rem;
358
- background: #18181b;
359
  border: 1px solid var(--accent-primary);
360
  border-left: 4px solid var(--accent-primary);
361
  padding: 1rem 1.25rem;
@@ -366,11 +388,37 @@ button {
366
  box-shadow: 0 10px 25px rgba(0,0,0,0.5), 0 0 15px var(--accent-glow);
367
  transform: translateY(100px);
368
  opacity: 0;
369
- animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
370
  z-index: 100;
371
  min-width: 320px;
372
  }
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  @keyframes slideUp {
375
  to {
376
  transform: translateY(0);
 
1
+ --secondary: #52525b;
2
+ }
3
+
4
+ /* Default to Dark Mode */
5
+ [data-theme='dark'] {
6
  --bg-primary: #000000;
7
  --bg-card: #151515;
8
  --bg-input: #1f1f1f;
9
  --border-card: #2e2e2e;
10
  --border-input: #3e3e3e;
11
+ --accent-primary: #76b900; /* NVIDIA Green */
 
 
12
  --accent-hover: #88d400;
13
  --accent-glow: rgba(118, 185, 0, 0.2);
 
14
  --text-main: #ffffff;
15
  --text-muted: #a1a1aa;
16
+ --code-bg: #09090b;
17
+ --header-bg: #1a1a1a;
18
+ }
19
+
20
+ /* Light Mode */
21
+ [data-theme='light'] {
22
+ --bg-primary: #f5f5f7;
23
+ --bg-card: #ffffff;
24
+ --bg-input: #ffffff;
25
+ --border-card: #d2d2d7;
26
+ --border-input: #e5e7eb;
27
+ --accent-primary: #0071e3; /* Mac Blue */
28
+ --accent-hover: #0077ed;
29
+ --accent-glow: rgba(0, 113, 227, 0.1);
30
+ --text-main: #1d1d1f;
31
+ --text-muted: #6e6e73;
32
+ --code-bg: #f5f5f7;
33
+ --header-bg: #ebebeb;
34
+ }
35
+
36
+ :root {
37
  --success: #76b900;
38
  --error: #ef4444;
39
  }
 
97
  }
98
 
99
  .mac-title-bar {
100
+ background: var(--header-bg);
101
  height: 44px;
102
  display: flex;
103
  align-items: center;
 
277
  }
278
 
279
  .code-container {
280
+ background: var(--code-bg);
281
  border-radius: 6px;
282
  overflow: hidden;
283
  border: 1px solid var(--border-card);
284
  }
285
 
286
  .code-header {
287
+ background: var(--header-bg);
288
  padding: 0.5rem 1rem;
289
  font-size: 0.75rem;
290
  color: var(--text-muted);
 
377
  position: fixed;
378
  bottom: 2rem;
379
  right: 2rem;
380
+ background: var(--bg-card);
381
  border: 1px solid var(--accent-primary);
382
  border-left: 4px solid var(--accent-primary);
383
  padding: 1rem 1.25rem;
 
388
  box-shadow: 0 10px 25px rgba(0,0,0,0.5), 0 0 15px var(--accent-glow);
389
  transform: translateY(100px);
390
  opacity: 0;
391
+ transition: transform 0.3s, opacity 0.3s;
392
  z-index: 100;
393
  min-width: 320px;
394
  }
395
 
396
+ /* Theme Toggle Button */
397
+ .theme-toggle {
398
+ position: absolute;
399
+ right: 16px;
400
+ background: transparent;
401
+ border: none;
402
+ cursor: pointer;
403
+ color: var(--text-muted);
404
+ padding: 4px;
405
+ display: flex;
406
+ align-items: center;
407
+ justify-content: center;
408
+ width: auto;
409
+ margin: 0;
410
+ transition: color 0.2s;
411
+ }
412
+
413
+ .theme-toggle:hover {
414
+ color: var(--text-main);
415
+ }
416
+
417
+ .theme-toggle svg {
418
+ width: 18px;
419
+ height: 18px;
420
+ }
421
+
422
  @keyframes slideUp {
423
  to {
424
  transform: translateY(0);