koel/resources/assets/js/stores/themeStore.ts

124 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-04-21 22:51:48 +00:00
import { reactive } from 'vue'
2022-04-24 08:50:45 +00:00
import { preferenceStore as preferences } from '@/stores'
2022-04-15 14:24:30 +00:00
2022-04-20 09:34:15 +00:00
import bgRosePetal from '@/../img/themes/bg-rose-petals.svg'
import bgPurpleWaves from '@/../img/themes/bg-purple-waves.svg'
import bgPopCulture from '@/../img/themes/bg-pop-culture.jpg'
import bgJungle from '@/../img/themes/bg-jungle.jpg'
import bgMountains from '@/../img/themes/bg-mountains.jpg'
import bgPines from '@/../img/themes/bg-pines.jpg'
import bgNemo from '@/../img/themes/bg-nemo.jpg'
import bgCat from '@/../img/themes/bg-cat.jpg'
2022-04-15 14:24:30 +00:00
export const themeStore = {
2022-04-21 22:51:48 +00:00
state: reactive({
2022-04-15 14:24:30 +00:00
themes: [
{
id: 'classic',
thumbnailColor: '#181818'
},
{
id: 'violet',
thumbnailColor: '#31094e'
},
{
id: 'oak',
thumbnailColor: '#560d25'
},
{
id: 'slate',
thumbnailColor: '#29434e'
},
{
id: 'madison',
thumbnailColor: '#0e3463'
},
{
id: 'astronaut',
thumbnailColor: '#2a3074'
},
{
id: 'chocolate',
thumbnailColor: '#3f2724'
},
{
id: 'laura',
thumbnailColor: '#126673'
},
{
id: 'rose-petals',
name: '…Has Its Thorns',
thumbnailColor: '#7d083b',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgRosePetal
2022-04-15 14:24:30 +00:00
},
{
id: 'purple-waves',
name: 'Waves of Fortune',
thumbnailColor: '#44115c',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgPurpleWaves
2022-04-15 14:24:30 +00:00
},
{
id: 'pop-culture',
thumbnailColor: '#ad0937',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgPopCulture
2022-04-15 14:24:30 +00:00
},
{
id: 'jungle',
name: 'Welcome to the Jungle',
thumbnailColor: '#0f0f03',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgJungle
2022-04-15 14:24:30 +00:00
},
{
id: 'mountains',
name: 'Rocky Mountain High',
thumbnailColor: '#0e2656',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgMountains
2022-04-15 14:24:30 +00:00
},
{
id: 'pines',
name: 'In the Pines',
thumbnailColor: '#06090c',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgPines
2022-04-15 14:24:30 +00:00
},
{
id: 'nemo',
thumbnailColor: '#031724',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgNemo
2022-04-15 14:24:30 +00:00
},
{
id: 'cat',
name: 'What\'s New Pussycat?',
thumbnailColor: '#000',
2022-04-20 09:34:15 +00:00
thumbnailUrl: bgCat
2022-04-15 14:24:30 +00:00
}
] as Theme[]
2022-04-21 22:51:48 +00:00
}),
2022-04-15 14:24:30 +00:00
init () {
this.applyThemeFromPreference()
},
setTheme (theme: Theme) {
document.documentElement.setAttribute('data-theme', theme.id)
preferences.theme = theme.id
2022-04-21 22:51:48 +00:00
this.state.themes.forEach(t => (t.selected = t.id === theme.id))
2022-04-15 14:24:30 +00:00
},
2022-04-21 22:51:48 +00:00
getThemeById (id: string) {
2022-04-15 14:24:30 +00:00
return this.state.themes.find(theme => theme.id === id)
},
getDefaultTheme (): Theme {
return this.getThemeById('classic')!
},
applyThemeFromPreference (): void {
const theme = preferences.theme
? (this.getThemeById(preferences.theme) ?? this.getDefaultTheme())
: this.getDefaultTheme()
this.setTheme(theme)
}
}