Skip to content

Commit

Permalink
fix: Optimize Dark Mode Toggle Functionality (#35)
Browse files Browse the repository at this point in the history
This PR simplifies and optimizes the dark mode toggle logic. It ensures correct functionality when the color mode preference is set to 'system'. Now, the button works seamlessly for all initial states, including 'system', and correctly toggles between 'dark' and 'light' modes.
  • Loading branch information
zackha authored Jan 27, 2025
1 parent 10d4d19 commit 40189e0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ watch(loggedIn, () => {
}
})
function toggleColorMode() {
colorMode.preference = colorMode.preference === 'dark' ? 'light' : 'dark'
}
const isDarkMode = computed({
get: () => colorMode.preference === 'dark',
set: () =>
(colorMode.preference = colorMode.value === 'dark' ? 'light' : 'dark')
})
useHead({
htmlAttrs: { lang: 'en' },
Expand Down Expand Up @@ -47,8 +49,12 @@ const items = [
square
variant="ghost"
color="black"
:icon="$colorMode.preference === 'dark' ? 'i-heroicons-moon' : 'i-heroicons-sun'"
@click="toggleColorMode"
:icon="
$colorMode.preference === 'dark' || $colorMode.preference === 'system'
? 'i-heroicons-moon'
: 'i-heroicons-sun'
"
@click="isDarkMode = !isDarkMode"
/>
</div>

Expand Down

0 comments on commit 40189e0

Please sign in to comment.