-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9e5f4a
commit 0b4597c
Showing
7 changed files
with
108 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
import { useDark, useMediaQuery, useToggle } from '@vueuse/core' | ||
import { useDark, useMediaQuery, useToggle } from "@vueuse/core"; | ||
|
||
const listeners = [] | ||
const listeners = []; | ||
|
||
const isDark = useDark({ | ||
selector: 'html', | ||
attribute: 'class', | ||
valueDark: 'dark', | ||
valueLight: 'light', | ||
}) | ||
const toogleDark = useToggle(isDark) | ||
selector: "html", | ||
attribute: "class", | ||
valueDark: "dark", | ||
valueLight: "light", | ||
}); | ||
const toogleDark = useToggle(isDark); | ||
|
||
let _current = Boolean(isDark.value) | ||
let _current = Boolean(isDark.value); | ||
|
||
export function Toggle () { | ||
_current = toogleDark() | ||
const evt = getEvent(_current) | ||
useMediaQuery(`(prefers-color-scheme: ${evt.color})`) | ||
listeners.forEach(fn => { | ||
fn.call(this, evt) | ||
}) | ||
return _current | ||
export function Toggle() { | ||
_current = toogleDark(); | ||
const evt = getEvent(_current); | ||
useMediaQuery(`(prefers-color-scheme: ${evt.color})`); | ||
listeners.forEach((fn) => { | ||
fn.call(this, evt); | ||
}); | ||
return _current; | ||
} | ||
|
||
export function Listen(fn) { | ||
listeners.push(fn) | ||
listeners.push(fn); | ||
} | ||
|
||
export function Get () { | ||
return _current | ||
export function Get() { | ||
return _current; | ||
} | ||
|
||
function getEvent(isDark) { | ||
const color = isDark ? 'dark' : 'light' | ||
const evt = new Event('DarkMode') | ||
evt.isDark = isDark | ||
evt.color = color | ||
return evt | ||
const color = isDark ? "dark" : "light"; | ||
const evt = new Event("DarkMode"); | ||
evt.isDark = isDark; | ||
evt.color = color; | ||
return evt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters