Skip to content

Commit 624604f

Browse files
committed
Add theme toggle functionality and update background color for dark mode
1 parent 785875e commit 624604f

File tree

2 files changed

+78
-13
lines changed

2 files changed

+78
-13
lines changed

resources/views/errors/minimal.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
}
7070
[data-theme="dark"] {
7171
.dark\:bg-gray-700 {
72-
background-color:rgb(40, 47, 58);
72+
background-color: #111827;
7373
}
7474
.dark\:text-gray-400 {
7575
color: #9ca3af;

resources/views/welcome.blade.php

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,28 +1123,39 @@ class="grid grid-cols-2 items-center gap-2 py-10 lg:grid-cols-3"
11231123
</svg>
11241124
</div>
11251125
@if (Route::has('login'))
1126-
<nav class="-mx-3 flex flex-1 justify-end">
1126+
<nav class="-mx-3 flex flex-1 justify-end items-center">
1127+
<button
1128+
id="theme-toggle"
1129+
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
1130+
>
1131+
<svg id="theme-icon" class="size-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
1132+
<path id="sun-icon" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" />
1133+
<path id="moon-icon" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z" />
1134+
<path id="system-icon" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25" />
1135+
</svg>
1136+
1137+
</button>
11271138
@auth
11281139
<a
1129-
href="{{ config('nova.path') }}"
1130-
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
1140+
href="{{ config('nova.path') }}"
1141+
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
11311142
>
1132-
Dashboard
1143+
Dashboard
11331144
</a>
11341145
@else
11351146
<a
1136-
href="{{ route('login') }}"
1137-
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
1147+
href="{{ route('login') }}"
1148+
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
11381149
>
1139-
Log in
1150+
Log in
11401151
</a>
11411152

11421153
@if (Route::has('register'))
11431154
<a
1144-
href="{{ route('register') }}"
1145-
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
1155+
href="{{ route('register') }}"
1156+
class="rounded-md px-3 py-2 text-black ring-1 ring-transparent transition hover:text-black/70 focus:outline-none focus-visible:ring-[#18B69C] dark:text-white dark:hover:text-white/80 dark:focus-visible:ring-white"
11461157
>
1147-
Register
1158+
Register
11481159
</a>
11491160
@endif @endauth
11501161
</nav>
@@ -1416,8 +1427,62 @@ class="py-16 text-center text-sm text-grey dark:text-grey/70"
14161427
</div>
14171428
</div>
14181429
<script>
1419-
const theme = localStorage.getItem('novaTheme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
1420-
document.documentElement.setAttribute('data-theme', theme);
1430+
const themeToggle = document.getElementById('theme-toggle');
1431+
const sunIcon = document.getElementById('sun-icon');
1432+
const moonIcon = document.getElementById('moon-icon');
1433+
const systemIcon = document.getElementById('system-icon');
1434+
1435+
const updateThemeIcon = (theme) => {
1436+
sunIcon.classList.add('hidden');
1437+
moonIcon.classList.add('hidden');
1438+
systemIcon.classList.add('hidden');
1439+
if (theme === 'light') {
1440+
sunIcon.classList.remove('hidden');
1441+
} else if (theme === 'dark') {
1442+
moonIcon.classList.remove('hidden');
1443+
} else {
1444+
systemIcon.classList.remove('hidden');
1445+
}
1446+
};
1447+
1448+
themeToggle.addEventListener('click', () => {
1449+
let theme = localStorage.getItem('novaTheme') || 'system';
1450+
if (theme === 'light') {
1451+
theme = 'dark';
1452+
} else if (theme === 'dark') {
1453+
theme = 'system';
1454+
} else {
1455+
theme = 'light';
1456+
}
1457+
updateThemeIcon(theme);
1458+
if (theme === 'system') {
1459+
localStorage.removeItem('novaTheme');
1460+
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
1461+
} else {
1462+
localStorage.setItem('novaTheme', theme);
1463+
}
1464+
document.documentElement.setAttribute('data-theme', theme);
1465+
});
1466+
1467+
// Initialize theme on page load
1468+
const initTheme = () => {
1469+
let theme = localStorage.getItem('novaTheme') || 'system';
1470+
updateThemeIcon(theme);
1471+
if (theme === 'system') {
1472+
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
1473+
}
1474+
document.documentElement.setAttribute('data-theme', theme);
1475+
};
1476+
1477+
// Listen for system theme changes
1478+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
1479+
if (!localStorage.getItem('novaTheme')) {
1480+
const newTheme = e.matches ? 'dark' : 'light';
1481+
document.documentElement.setAttribute('data-theme', newTheme);
1482+
}
1483+
});
1484+
1485+
initTheme();
14211486
</script>
14221487
</body>
14231488
</html>

0 commit comments

Comments
 (0)