Skip to content

Commit f4b7aa8

Browse files
authored
Merge pull request #9 from cmpnd-ai/darkmode
Added Dark Mode
2 parents 7cc92f3 + 4a4b4b3 commit f4b7aa8

File tree

3 files changed

+280
-100
lines changed

3 files changed

+280
-100
lines changed

src/dspy_cli/templates/ui/static/script.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
// DSPy UI JavaScript
22

3+
/**
4+
* Initialize theme on page load
5+
* Reads theme preference from localStorage or falls back to system preference
6+
*/
7+
function initTheme() {
8+
// Check localStorage for saved preference
9+
const savedTheme = localStorage.getItem('theme');
10+
11+
if (savedTheme) {
12+
// Use saved preference
13+
document.documentElement.setAttribute('data-theme', savedTheme);
14+
} else {
15+
// Use system preference if no saved preference
16+
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
17+
const theme = prefersDark ? 'dark' : 'light';
18+
document.documentElement.setAttribute('data-theme', theme);
19+
}
20+
21+
// Update toggle button icon if it exists
22+
updateThemeIcon();
23+
}
24+
25+
/**
26+
* Toggle between light and dark themes
27+
*/
28+
function toggleTheme() {
29+
const currentTheme = document.documentElement.getAttribute('data-theme');
30+
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
31+
32+
// Update theme
33+
document.documentElement.setAttribute('data-theme', newTheme);
34+
35+
// Save preference
36+
localStorage.setItem('theme', newTheme);
37+
38+
// Update icon
39+
updateThemeIcon();
40+
}
41+
42+
/**
43+
* Update theme toggle button icon
44+
*/
45+
function updateThemeIcon() {
46+
const themeIcon = document.getElementById('themeIcon');
47+
if (!themeIcon) return;
48+
49+
const currentTheme = document.documentElement.getAttribute('data-theme');
50+
// Show moon for light mode (click to go dark), sun for dark mode (click to go light)
51+
themeIcon.textContent = currentTheme === 'dark' ? '☀️' : '🌙';
52+
}
53+
354
/**
455
* Initialize the program page with event handlers and log loading
556
*/

0 commit comments

Comments
 (0)