Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix dark and light mode in playground editor
- Loading branch information
Showing
4 changed files
with
40 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ref, computed, inject } from 'vue'; | ||
|
||
export function createDarkMode(app) { | ||
const prefersDark = ref(false); | ||
const setting = ref('auto'); | ||
|
||
const isDark = computed( | ||
() => | ||
setting.value === 'dark' || | ||
(prefersDark.value && setting.value !== 'light') | ||
); | ||
const toggleDark = () => { | ||
setting.value = setting.value === 'dark' ? 'light' : 'dark'; | ||
localStorage.setItem('color-scheme', setting.value); | ||
}; | ||
|
||
prefersDark.value = | ||
window.matchMedia && | ||
window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
setting.value = localStorage.getItem('color-scheme') || 'auto'; | ||
|
||
app.provide('is-dark', { isDark, toggleDark }); | ||
} | ||
|
||
export function useDarkMode() { | ||
return inject('is-dark'); | ||
} |
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