Skip to content

Commit

Permalink
feat(theme): add option for dedicated CSS file per theme
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Jul 22, 2024
1 parent 477c958 commit d6a4761
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions public/css/themes/vzbot.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
div.v-navigation-drawer__image div.v-image__image {
background-position: bottom center !important;
}
20 changes: 20 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,26 @@ export default class App extends Mixins(BaseMixin, ThemeMixin) {
this.drawFavicon(this.print_percent)
}
@Watch('themeCss')
themeCssChanged(newVal: string | null): void {
// remove linked CSS file if it exists
const style = document.getElementById('theme-css')
if (style) style.remove()
// if themeCss does not exist, stop here and load no CSS file
if (newVal === null) return
// fetch the CSS file and append it to the head
fetch(newVal)
.then((response) => response.text())
.then((css) => {
const newStyle = document.createElement('style')
newStyle.id = 'theme-css'
newStyle.innerHTML = css
document.head.appendChild(newStyle)
})
}
@Watch('print_percent')
print_percentChanged(newVal: number): void {
this.drawFavicon(newVal)
Expand Down
6 changes: 6 additions & 0 deletions src/components/mixins/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ export default class ThemeMixin extends Vue {

return `/img/themes/mainBackground-${this.themeName}.png`
}

get themeCss() {
if (!(this.theme.css ?? false)) return null

return `/css/themes/${this.themeName}.css`
}
}
1 change: 1 addition & 0 deletions src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export interface Theme {
show: boolean
light: boolean
}
css?: boolean
}
1 change: 1 addition & 0 deletions src/store/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const themes: Theme[] = [
colorLogo: '#FF0000',
logo: { show: true, light: false },
sidebarBackground: { show: true, light: false },
css: true,
},
{
name: 'prusa',
Expand Down

0 comments on commit d6a4761

Please sign in to comment.