Add view transition

pull/5002/head
Cagatay Civici 2023-12-27 00:35:16 +03:00
parent 54ed75b7b7
commit 75a1201d4f
1 changed files with 16 additions and 5 deletions

21
app.vue
View File

@ -22,17 +22,28 @@ export default {
}, },
mounted() { mounted() {
this.themeChangeListener = (event) => { this.themeChangeListener = (event) => {
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => { if (!document.startViewTransition) {
this.$appState.theme = event.theme; this.applyTheme(event);
this.$appState.darkTheme = event.dark;
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark }); return;
}); }
document.startViewTransition(() => this.applyTheme(event));
}; };
EventBus.on('theme-change', this.themeChangeListener); EventBus.on('theme-change', this.themeChangeListener);
}, },
beforeUnmount() { beforeUnmount() {
EventBus.off('theme-change', this.themeChangeListener); EventBus.off('theme-change', this.themeChangeListener);
},
methods: {
applyTheme(event) {
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => {
this.$appState.theme = event.theme;
this.$appState.darkTheme = event.dark;
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark });
});
}
} }
}; };
</script> </script>