diff --git a/app.vue b/app.vue index c9767ddef..3bf06b61d 100644 --- a/app.vue +++ b/app.vue @@ -46,21 +46,10 @@ export default { }; this.themeChangeListener = (event) => { - const elementId = 'theme-link'; - const linkElement = document.getElementById(elementId); - const cloneLinkElement = linkElement.cloneNode(true); - const newThemeUrl = linkElement.getAttribute('href').replace(this.$appState.theme, event.theme); - - cloneLinkElement.setAttribute('id', elementId + '-clone'); - cloneLinkElement.setAttribute('href', newThemeUrl); - cloneLinkElement.addEventListener('load', () => { - linkElement.remove(); - cloneLinkElement.setAttribute('id', elementId); + this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => { + this.$appState.theme = event.theme; + this.$appState.darkTheme = event.dark; }); - linkElement.parentNode?.insertBefore(cloneLinkElement, linkElement.nextSibling); - - this.$appState.theme = event.theme; - this.$appState.darkTheme = event.dark; }; EventBus.on('theme-change', this.themeChangeListener); @@ -76,5 +65,4 @@ export default { diff --git a/assets/styles/demo/_common.scss b/assets/styles/demo/_common.scss deleted file mode 100644 index 7324fd59a..000000000 --- a/assets/styles/demo/_common.scss +++ /dev/null @@ -1,4 +0,0 @@ -.mypanel .p-panel-header { - background-color: #07c4e8; - color: #ffffff; -} \ No newline at end of file diff --git a/assets/styles/demo/demo.scss b/assets/styles/demo/demo.scss deleted file mode 100644 index 542aa90f9..000000000 --- a/assets/styles/demo/demo.scss +++ /dev/null @@ -1 +0,0 @@ -@import './_common'; \ No newline at end of file diff --git a/components/config/PrimeVue.js b/components/config/PrimeVue.js index 67d2c3606..b10d0e4e4 100644 --- a/components/config/PrimeVue.js +++ b/components/config/PrimeVue.js @@ -145,11 +145,30 @@ export function usePrimeVue() { return PrimeVue; } +function switchTheme(currentTheme, newTheme, linkElementId, callback) { + const linkElement = document.getElementById(linkElementId); + const cloneLinkElement = linkElement.cloneNode(true); + const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme); + + cloneLinkElement.setAttribute('id', linkElementId + '-clone'); + cloneLinkElement.setAttribute('href', newThemeUrl); + cloneLinkElement.addEventListener('load', () => { + linkElement.remove(); + cloneLinkElement.setAttribute('id', linkElementId); + + if (callback) { + callback(); + } + }); + linkElement.parentNode?.insertBefore(cloneLinkElement, linkElement.nextSibling); +} + export default { install: (app, options) => { let configOptions = options ? { ...defaultOptions, ...options } : { ...defaultOptions }; const PrimeVue = { - config: reactive(configOptions) + config: reactive(configOptions), + changeTheme: switchTheme }; app.config.globalProperties.$primevue = PrimeVue; diff --git a/doc/theming/ArchitectureDoc.vue b/doc/theming/ArchitectureDoc.vue index 4016a3314..62d874ec4 100644 --- a/doc/theming/ArchitectureDoc.vue +++ b/doc/theming/ArchitectureDoc.vue @@ -1,10 +1,12 @@