Skip to content

Commit 75adce5

Browse files
michaeloboyleclaude
andcommitted
feat: Add system light/dark theme support to graph browser
Implements automatic theme detection respecting OS preferences: CSS Updates: - Added CSS custom properties for light/dark themes - Light theme (default): White backgrounds, dark text - Dark theme: Dark backgrounds, light text - @media (prefers-color-scheme: dark) for automatic switching - Smooth transitions between themes Theme Variables: Light Mode: - Backgrounds: #ffffff, #f5f5f5, #e8e8e8 - Text: #333, #666 - Borders: #ddd - Shadow: rgba(0,0,0,0.1) Dark Mode: - Backgrounds: #1e1e1e, #141414, #2a2a2a - Text: #e0e0e0, #999 - Borders: #333 - Shadow: rgba(0,0,0,0.3) CodeMirror Integration: - Light mode: 'eclipse' theme - Dark mode: 'dracula' theme - Dynamic theme switching with matchMedia listener - Responds to system theme changes in real-time Features: ✅ Automatic OS theme detection ✅ Real-time theme switching ✅ CodeMirror editor theme sync ✅ Maintains contrast in both modes ✅ Professional appearance in light/dark ✅ No manual toggle needed (respects OS) Test: - macOS: System Preferences → General → Appearance - Windows: Settings → Personalization → Colors - Linux: System settings → Appearance Browser will automatically update when system theme changes. 🚀 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 73f8aa8 commit 75adce5

File tree

1 file changed

+49
-24
lines changed

1 file changed

+49
-24
lines changed

examples/graph-browser/index.html

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<script src="https://unpkg.com/[email protected]/standalone/umd/vis-network.min.js"></script>
88
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/theme/dracula.min.css">
10+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/theme/eclipse.min.css">
1011
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.js"></script>
1112
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/sql/sql.min.js"></script>
1213
<style>
@@ -16,35 +17,51 @@
1617
box-sizing: border-box;
1718
}
1819

20+
/* Light theme (default) */
1921
:root {
2022
--primary: #0084ff;
2123
--primary-dark: #0066cc;
2224
--success: #28a745;
2325
--danger: #dc3545;
24-
--dark: #1e1e1e;
25-
--darker: #141414;
26-
--light: #f5f5f5;
27-
--border: #333;
28-
--text: #e0e0e0;
29-
--text-muted: #999;
26+
--bg-primary: #ffffff;
27+
--bg-secondary: #f5f5f5;
28+
--bg-tertiary: #e8e8e8;
29+
--border: #ddd;
30+
--text: #333;
31+
--text-muted: #666;
32+
--shadow: rgba(0, 0, 0, 0.1);
33+
}
34+
35+
/* Dark theme (when system prefers dark) */
36+
@media (prefers-color-scheme: dark) {
37+
:root {
38+
--bg-primary: #1e1e1e;
39+
--bg-secondary: #141414;
40+
--bg-tertiary: #2a2a2a;
41+
--border: #333;
42+
--text: #e0e0e0;
43+
--text-muted: #999;
44+
--shadow: rgba(0, 0, 0, 0.3);
45+
}
3046
}
3147

3248
body {
3349
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
34-
background: var(--darker);
50+
background: var(--bg-secondary);
3551
color: var(--text);
3652
height: 100vh;
3753
overflow: hidden;
3854
}
3955

4056
/* Header */
4157
.header {
42-
background: var(--dark);
58+
background: var(--bg-primary);
4359
border-bottom: 1px solid var(--border);
4460
padding: 15px 20px;
4561
display: flex;
4662
align-items: center;
4763
justify-content: space-between;
64+
box-shadow: 0 1px 3px var(--shadow);
4865
}
4966

5067
.logo {
@@ -77,11 +94,12 @@
7794
}
7895

7996
button.secondary {
80-
background: var(--border);
97+
background: var(--bg-tertiary);
98+
color: var(--text);
8199
}
82100

83101
button.secondary:hover {
84-
background: #444;
102+
background: var(--border);
85103
}
86104

87105
/* Main Layout */
@@ -93,7 +111,7 @@
93111
/* Sidebar */
94112
.sidebar {
95113
width: 300px;
96-
background: var(--dark);
114+
background: var(--bg-primary);
97115
border-right: 1px solid var(--border);
98116
display: flex;
99117
flex-direction: column;
@@ -113,7 +131,7 @@
113131
}
114132

115133
.sample-query {
116-
background: var(--darker);
134+
background: var(--bg-secondary);
117135
padding: 10px;
118136
border-radius: 4px;
119137
margin-bottom: 10px;
@@ -145,7 +163,7 @@
145163
}
146164

147165
.stat {
148-
background: var(--darker);
166+
background: var(--bg-secondary);
149167
padding: 12px;
150168
border-radius: 4px;
151169
text-align: center;
@@ -173,7 +191,7 @@
173191

174192
/* Query Editor */
175193
.query-editor {
176-
background: var(--dark);
194+
background: var(--bg-primary);
177195
border-bottom: 1px solid var(--border);
178196
padding: 15px;
179197
}
@@ -221,7 +239,7 @@
221239

222240
.tabs {
223241
display: flex;
224-
background: var(--dark);
242+
background: var(--bg-primary);
225243
border-bottom: 1px solid var(--border);
226244
}
227245

@@ -234,7 +252,7 @@
234252

235253
.tab.active {
236254
border-bottom-color: var(--primary);
237-
background: var(--darker);
255+
background: var(--bg-secondary);
238256
}
239257

240258
.tab-content {
@@ -251,7 +269,7 @@
251269
#graph-viz {
252270
width: 100%;
253271
height: 100%;
254-
background: var(--darker);
272+
background: var(--bg-secondary);
255273
}
256274

257275
/* Table View */
@@ -263,7 +281,7 @@
263281
table {
264282
width: 100%;
265283
border-collapse: collapse;
266-
background: var(--dark);
284+
background: var(--bg-primary);
267285
}
268286

269287
th, td {
@@ -273,7 +291,7 @@
273291
}
274292

275293
th {
276-
background: var(--darker);
294+
background: var(--bg-secondary);
277295
color: var(--text-muted);
278296
font-weight: 600;
279297
text-transform: uppercase;
@@ -285,7 +303,7 @@
285303
}
286304

287305
tr:hover {
288-
background: var(--darker);
306+
background: var(--bg-secondary);
289307
}
290308

291309
/* JSON View */
@@ -296,21 +314,22 @@
296314
}
297315

298316
pre {
299-
background: var(--dark);
317+
background: var(--bg-secondary);
300318
padding: 15px;
301319
border-radius: 4px;
302320
overflow-x: auto;
303321
}
304322

305323
/* Status Bar */
306324
.status-bar {
307-
background: var(--dark);
325+
background: var(--bg-primary);
308326
border-top: 1px solid var(--border);
309327
padding: 8px 20px;
310328
font-size: 12px;
311329
display: flex;
312330
justify-content: space-between;
313331
align-items: center;
332+
box-shadow: 0 -1px 3px var(--shadow);
314333
}
315334

316335
.status-item {
@@ -487,14 +506,20 @@ <h3>QUERY EDITOR</h3>
487506
</div>
488507

489508
<script>
490-
// Initialize CodeMirror
509+
// Initialize CodeMirror with theme based on system preference
510+
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
491511
const editor = CodeMirror.fromTextArea(document.getElementById('query-input'), {
492512
mode: 'text/javascript',
493-
theme: 'dracula',
513+
theme: prefersDark ? 'dracula' : 'eclipse',
494514
lineNumbers: true,
495515
lineWrapping: true,
496516
});
497517

518+
// Listen for system theme changes
519+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
520+
editor.setOption('theme', e.matches ? 'dracula' : 'eclipse');
521+
});
522+
498523
// Keyboard shortcuts
499524
editor.setOption('extraKeys', {
500525
'Cmd-Enter': executeQuery,

0 commit comments

Comments
 (0)