Skip to content
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

fix: dark mode input on mounted unchange #300

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/Layouts/Sidebar/Dark.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const THEME_KEY = "theme"
const THEME_REGEX = /\btheme-[a-z0-9]+\b/g

const toggler = document.getElementById("toggle-dark") as HTMLInputElement
const darkToggler = ref()
/**
* Toggle Dark Mode
*/
Expand All @@ -23,7 +23,7 @@ const toggleDarkTheme = () => {
const setTheme = (theme: string, dontPersist: boolean = false) => {
document.body.className = document.body.className.replace(THEME_REGEX, "")
document.body.classList.add(theme)
if (toggler) toggler.checked = theme == "theme-dark"
if (darkToggler) darkToggler.value.checked = theme == "theme-dark"

if (!dontPersist) {
localStorage.setItem(THEME_KEY, theme)
Expand Down Expand Up @@ -78,7 +78,7 @@ onMounted(() => {
</g>
</svg>
<div class="form-check form-switch fs-6">
<input class="form-check-input me-0" type="checkbox" id="toggle-dark" style="cursor: pointer" @click="toggleDarkTheme"/>
<input class="form-check-input me-0" type="checkbox" id="toggle-dark" ref="darkToggler" style="cursor: pointer" @click="toggleDarkTheme"/>
<label class="form-check-label"></label>
</div>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img"
Expand Down
4 changes: 1 addition & 3 deletions components/Layouts/Sidebar/LayoutSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ watch(() => store.isSidebarActive, (isSidebarActive) => {
<div class="logo">
<nuxt-link to="/"><img src="~/assets/images/logo/logo.png" alt="Logo"></nuxt-link>
</div>
<client-only>
<Dark />
</client-only>
<Dark />
<div class="toggler">
<a href="#" class="sidebar-hide d-xl-none d-block" @click="store.toggleSidebar">
<i class="bi bi-x bi-middle"></i>
Expand Down