-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add dark mode toggle to application header #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,21 @@ | ||
| <script setup lang="ts"> | ||
| import { ref, onMounted } from 'vue' | ||
| import { RouterView } from 'vue-router' | ||
| import { Github } from 'lucide-vue-next' | ||
| import { Github, Moon, Sun } from 'lucide-vue-next' | ||
|
|
||
| const isDark = ref(false) | ||
|
|
||
| function toggleDark() { | ||
| isDark.value = !isDark.value | ||
| document.documentElement.classList.toggle('dark', isDark.value) | ||
| localStorage.setItem('theme', isDark.value ? 'dark' : 'light') | ||
| } | ||
|
|
||
| onMounted(() => { | ||
| const saved = localStorage.getItem('theme') | ||
| isDark.value = saved === 'dark' || (!saved && window.matchMedia('(prefers-color-scheme: dark)').matches) | ||
| document.documentElement.classList.toggle('dark', isDark.value) | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
|
|
@@ -27,6 +42,15 @@ | |
| Encounters | ||
| </RouterLink> | ||
| </nav> | ||
| <div class="flex items-center gap-4"> | ||
| <button | ||
| @click="toggleDark" | ||
| class="inline-flex items-center justify-center rounded-md p-2 text-muted-foreground transition-colors hover:text-primary hover:bg-accent" | ||
|
Check warning on line 48 in web/src/App.vue
|
||
| :title="isDark ? 'Switch to light mode' : 'Switch to dark mode'" | ||
|
Check warning on line 49 in web/src/App.vue
|
||
|
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reorder button attributes to clear lint warnings. Static analysis reports attribute order warnings. Move 🧹 Proposed fix- <button
- `@click`="toggleDark"
- class="inline-flex items-center justify-center rounded-md p-2 text-muted-foreground transition-colors hover:text-primary hover:bg-accent"
- :title="isDark ? 'Switch to light mode' : 'Switch to dark mode'"
- >
+ <button
+ class="inline-flex items-center justify-center rounded-md p-2 text-muted-foreground transition-colors hover:text-primary hover:bg-accent"
+ :title="isDark ? 'Switch to light mode' : 'Switch to dark mode'"
+ `@click`="toggleDark"
+ >🧰 Tools🤖 Prompt for AI Agents |
||
| > | ||
| <Sun v-if="isDark" :size="18" /> | ||
| <Moon v-else :size="18" /> | ||
| </button> | ||
| <a | ||
| href="https://github.com/platzhersh/open-cis" | ||
| target="_blank" | ||
|
|
@@ -37,6 +61,7 @@ | |
| <Github :size="18" /> | ||
| <span>Open Source</span> | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </header> | ||
| <main class="container py-6"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix ESLint no-undef for
localStorage(CI is failing).Lint/pipeline errors report
localStorageas undefined on Line 11 and Line 15. Usewindow.localStorage(orglobalThis.localStorage) to satisfy the ESLint environment and keep behavior unchanged.🐛 Proposed fix
function toggleDark() { isDark.value = !isDark.value document.documentElement.classList.toggle('dark', isDark.value) - localStorage.setItem('theme', isDark.value ? 'dark' : 'light') + window.localStorage.setItem('theme', isDark.value ? 'dark' : 'light') } onMounted(() => { - const saved = localStorage.getItem('theme') + const saved = window.localStorage.getItem('theme') isDark.value = saved === 'dark' || (!saved && window.matchMedia('(prefers-color-scheme: dark)').matches) document.documentElement.classList.toggle('dark', isDark.value) })📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Frontend CI
[error] 11-11: ESLint: 'localStorage' is not defined. (no-undef)
🪛 GitHub Check: lint-and-test
[failure] 15-15:
'localStorage' is not defined
[failure] 11-11:
'localStorage' is not defined
🤖 Prompt for AI Agents