From 60e368c2a00320d818b945663372bddda8194087 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Fri, 3 Mar 2023 10:02:10 +0300 Subject: [PATCH] Add new theming docs and changeTheme api --- app.vue | 18 +---- assets/styles/demo/_common.scss | 4 - assets/styles/demo/demo.scss | 1 - components/config/PrimeVue.js | 21 +++++- doc/theming/ArchitectureDoc.vue | 10 ++- .../{ThemesDoc.vue => BuiltInThemesDoc.vue} | 9 ++- doc/theming/CSSModulesDoc.vue | 49 +++++++++++++ doc/theming/CSSVariablesDoc.vue | 5 -- doc/theming/CustomThemeDoc.vue | 65 +++++++++++++++++ doc/theming/DesignerDoc.vue | 21 ------ doc/theming/PrimeFlexDoc.vue | 12 +-- ...{ScopedStylingDoc.vue => ScopedCSSDoc.vue} | 27 ++++--- doc/theming/SwitchThemesDoc.vue | 73 +++++++++++++++++++ doc/theming/UtilsDoc.vue | 4 - layouts/doc/DocSections.vue | 2 +- pages/theming/index.vue | 42 ++++++----- 16 files changed, 271 insertions(+), 92 deletions(-) delete mode 100644 assets/styles/demo/_common.scss delete mode 100644 assets/styles/demo/demo.scss rename doc/theming/{ThemesDoc.vue => BuiltInThemesDoc.vue} (78%) create mode 100644 doc/theming/CSSModulesDoc.vue delete mode 100644 doc/theming/CSSVariablesDoc.vue create mode 100644 doc/theming/CustomThemeDoc.vue delete mode 100644 doc/theming/DesignerDoc.vue rename doc/theming/{ScopedStylingDoc.vue => ScopedCSSDoc.vue} (74%) create mode 100644 doc/theming/SwitchThemesDoc.vue 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 @@