primevue-mirror/app.vue

51 lines
1.5 KiB
Vue
Raw Normal View History

2022-09-06 11:52:18 +00:00
<template>
2023-10-10 05:41:15 +00:00
<NuxtLayout>
2022-09-14 14:26:41 +00:00
<NuxtPage />
</NuxtLayout>
2022-09-06 11:52:18 +00:00
</template>
2022-09-06 13:53:29 +00:00
<script>
2023-02-28 08:29:30 +00:00
import EventBus from '@/layouts/AppEventBus';
2024-03-06 10:38:51 +00:00
import { useColorScheme } from 'primevue/themes';
2022-09-09 14:35:31 +00:00
2022-09-09 10:25:14 +00:00
export default {
beforeMount() {
const isDark = localStorage['primevue-theme'] === 'dark' || (!('primevue-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (isDark) document.documentElement.classList.add('p-dark');
else document.documentElement.classList.remove('p-dark');
//@todo - set initial colorScheme
},
2022-09-09 10:25:14 +00:00
mounted() {
EventBus.on('theme-change', this.themeChangeListener);
},
beforeUnmount() {
EventBus.off('theme-change', this.themeChangeListener);
2023-12-26 21:35:16 +00:00
},
methods: {
2023-12-30 22:26:14 +00:00
themeChangeListener(event) {
if (!document.startViewTransition) {
this.applyTheme(event);
return;
}
document.startViewTransition(() => this.applyTheme(event));
},
2023-12-26 21:35:16 +00:00
applyTheme(event) {
2024-03-06 10:38:51 +00:00
const { toggleColorScheme } = useColorScheme();
const newColorScheme = toggleColorScheme();
localStorage['primevue-theme'] = newColorScheme;
2024-03-05 09:22:33 +00:00
/*this.$appState.darkTheme = event.dark;
2024-02-07 10:15:47 +00:00
2024-02-05 21:20:00 +00:00
if (event.dark) document.documentElement.classList.add('p-dark');
2024-03-05 09:22:33 +00:00
else document.documentElement.classList.remove('p-dark');*/
2023-12-26 21:35:16 +00:00
}
2022-09-09 10:25:14 +00:00
}
2022-09-14 14:26:41 +00:00
};
</script>
2022-12-09 09:02:20 +00:00
2023-09-25 11:09:54 +00:00
<style lang="scss"></style>