2020-10-27 12:40:32 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
|
|
|
export type Theme = {
|
|
|
|
mainBg: string
|
|
|
|
mainFg: string
|
|
|
|
buttonBg: string
|
|
|
|
buttonFg: string
|
|
|
|
sidebarBg: string
|
|
|
|
sidebarFg: string
|
2021-01-28 23:51:45 +02:00
|
|
|
sidebarWhiteLogo: string
|
2020-10-27 12:40:32 +02:00
|
|
|
}
|
|
|
|
|
2021-01-04 21:19:03 +02:00
|
|
|
export const defaultTheme = {
|
|
|
|
mainBg: '255, 255, 255',
|
|
|
|
mainFg: '55, 53, 47',
|
|
|
|
buttonBg: '22, 109, 224',
|
|
|
|
buttonFg: '255, 255, 255',
|
|
|
|
sidebarBg: '20, 93, 191',
|
|
|
|
sidebarFg: '255, 255, 255',
|
2021-01-28 23:51:45 +02:00
|
|
|
sidebarWhiteLogo: 'true',
|
2021-01-04 21:19:03 +02:00
|
|
|
}
|
|
|
|
|
2020-10-27 12:40:32 +02:00
|
|
|
export const darkTheme = {
|
|
|
|
mainBg: '55, 53, 47',
|
|
|
|
mainFg: '200, 200, 200',
|
|
|
|
buttonBg: '80, 170, 221',
|
|
|
|
buttonFg: '255, 255, 255',
|
|
|
|
sidebarBg: '75, 73, 67',
|
|
|
|
sidebarFg: '255, 255, 255',
|
2021-01-28 23:51:45 +02:00
|
|
|
sidebarWhiteLogo: 'true',
|
2020-10-27 12:40:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const lightTheme = {
|
|
|
|
mainBg: '255, 255, 255',
|
|
|
|
mainFg: '55, 53, 47',
|
|
|
|
buttonBg: '80, 170, 221',
|
|
|
|
buttonFg: '255, 255, 255',
|
|
|
|
sidebarBg: '247, 246, 243',
|
|
|
|
sidebarFg: '55, 53, 47',
|
2021-01-28 23:51:45 +02:00
|
|
|
sidebarWhiteLogo: 'false',
|
2020-10-27 12:40:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setTheme(theme: Theme): void {
|
|
|
|
document.documentElement.style.setProperty('--main-bg', theme.mainBg)
|
|
|
|
document.documentElement.style.setProperty('--main-fg', theme.mainFg)
|
2021-01-28 23:51:45 +02:00
|
|
|
document.documentElement.style.setProperty('--body-color', theme.mainFg)
|
2020-10-27 12:40:32 +02:00
|
|
|
document.documentElement.style.setProperty('--button-bg', theme.buttonBg)
|
|
|
|
document.documentElement.style.setProperty('--button-fg', theme.buttonFg)
|
|
|
|
document.documentElement.style.setProperty('--sidebar-bg', theme.sidebarBg)
|
|
|
|
document.documentElement.style.setProperty('--sidebar-fg', theme.sidebarFg)
|
2021-01-28 23:51:45 +02:00
|
|
|
document.documentElement.style.setProperty('--sidebar-white-logo', theme.sidebarWhiteLogo)
|
2020-10-27 14:01:15 +02:00
|
|
|
localStorage.setItem('theme', JSON.stringify(theme))
|
|
|
|
}
|
|
|
|
|
2021-01-28 23:51:45 +02:00
|
|
|
export function loadTheme(): Theme {
|
2020-10-27 14:01:15 +02:00
|
|
|
const themeStr = localStorage.getItem('theme')
|
|
|
|
if (themeStr) {
|
|
|
|
try {
|
|
|
|
const theme = JSON.parse(themeStr)
|
|
|
|
setTheme(theme)
|
2021-01-28 23:51:45 +02:00
|
|
|
return theme
|
2020-10-27 14:01:15 +02:00
|
|
|
} catch (e) {
|
2021-01-04 21:19:03 +02:00
|
|
|
setTheme(defaultTheme)
|
2021-01-28 23:51:45 +02:00
|
|
|
return defaultTheme
|
2020-10-27 14:01:15 +02:00
|
|
|
}
|
|
|
|
} else {
|
2021-01-04 21:19:03 +02:00
|
|
|
setTheme(defaultTheme)
|
2021-01-28 23:51:45 +02:00
|
|
|
return defaultTheme
|
2020-10-27 14:01:15 +02:00
|
|
|
}
|
2020-10-27 12:40:32 +02:00
|
|
|
}
|