1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-11 18:13:52 +02:00
focalboard/webapp/src/theme.ts

72 lines
2.1 KiB
TypeScript
Raw Normal View History

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
}
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',
}
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)
localStorage.setItem('theme', JSON.stringify(theme))
}
2021-01-28 23:51:45 +02:00
export function loadTheme(): Theme {
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
} catch (e) {
setTheme(defaultTheme)
2021-01-28 23:51:45 +02:00
return defaultTheme
}
} else {
setTheme(defaultTheme)
2021-01-28 23:51:45 +02:00
return defaultTheme
}
2020-10-27 12:40:32 +02:00
}