Skip to content

Commit

Permalink
docs: use mutation observer to check dark mode class
Browse files Browse the repository at this point in the history
  • Loading branch information
bcakmakoglu committed Jun 10, 2022
1 parent 62dda36 commit 669f9a0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions docs/components/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@ import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
import Blobity from 'blobity'
import Intro from './flows/Intro.vue'
const dark = useDark({
const breakpoints = useBreakpoints(breakpointsTailwind)
const usesDark = useDark({
storageKey: 'vuepress-color-scheme',
selector: 'html',
})
const breakpoints = useBreakpoints(breakpointsTailwind)
const dark = ref(false)
onMounted(() => {
const html = document.getElementsByTagName('html')![0]
usesDark.value = html.classList.contains('dark')
const observer = new MutationObserver((mutations) => {
for (const m of mutations) {
dark.value = html.classList.contains('dark')
}
})
observer.observe(html, {
attributes: true,
attributeOldValue: true,
attributeFilter: ['class'],
})
})
onMounted(() => {
if (!breakpoints.isSmaller('md')) {
Expand Down

2 comments on commit 669f9a0

@vercel
Copy link

@vercel vercel bot commented on 669f9a0 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 669f9a0 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.