This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-06-15 03:57:50 -07:00
|
|
|
export default {
|
|
|
|
methods: {
|
2022-01-18 11:26:21 -08:00
|
|
|
getMode() {
|
|
|
|
if (!process.client) { return 'automatic'; }
|
|
|
|
|
|
|
|
return localStorage.getItem('mode') || 'automatic';
|
|
|
|
},
|
2021-06-15 03:57:50 -07:00
|
|
|
detectDark() {
|
2022-01-18 11:26:21 -08:00
|
|
|
if (!process.client) { return false; }
|
2021-06-15 03:57:50 -07:00
|
|
|
|
2022-01-18 11:26:21 -08:00
|
|
|
switch (this.getMode()) {
|
|
|
|
case 'light':
|
|
|
|
return false;
|
|
|
|
case 'dark':
|
|
|
|
return true;
|
|
|
|
case 'automatic':
|
|
|
|
default:
|
|
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
2021-06-15 03:57:50 -07:00
|
|
|
}
|
2022-01-18 11:26:21 -08:00
|
|
|
},
|
|
|
|
setMode(mode) {
|
|
|
|
if (!process.client) { return; }
|
2021-06-15 03:57:50 -07:00
|
|
|
|
2022-01-18 11:26:21 -08:00
|
|
|
localStorage.setItem('mode', mode);
|
2021-06-15 03:57:50 -07:00
|
|
|
},
|
2022-01-18 11:26:21 -08:00
|
|
|
setIsDark(dark) {
|
|
|
|
if (!process.client) { return; }
|
2021-06-15 03:57:50 -07:00
|
|
|
|
|
|
|
if (dark) {
|
|
|
|
document.body.setAttribute('data-theme', 'dark');
|
|
|
|
} else {
|
|
|
|
document.body.removeAttribute('data-theme');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|