2020-10-27 11:40:32 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2021-06-04 15:23:15 +02:00
|
|
|
import {CSSObject} from '@emotion/serialize'
|
2021-06-11 11:32:18 +02:00
|
|
|
import isEqual from 'lodash/isEqual'
|
2021-08-06 19:58:28 +02:00
|
|
|
import color from 'color'
|
|
|
|
|
|
|
|
import {Utils} from './utils'
|
2021-06-07 13:25:25 +02:00
|
|
|
|
|
|
|
let activeThemeName: string
|
2021-06-04 15:23:15 +02:00
|
|
|
|
2021-08-15 12:51:19 +02:00
|
|
|
import {UserSettings} from './userSettings'
|
|
|
|
|
2020-10-27 11:40:32 +01:00
|
|
|
export type Theme = {
|
2021-03-05 23:37:30 +01:00
|
|
|
mainBg: string,
|
|
|
|
mainFg: string,
|
|
|
|
buttonBg: string,
|
|
|
|
buttonFg: string,
|
|
|
|
sidebarBg: string,
|
|
|
|
sidebarFg: string,
|
2021-07-22 15:52:45 +02:00
|
|
|
sidebarTextActiveBorder: string,
|
2021-03-05 23:37:30 +01:00
|
|
|
sidebarWhiteLogo: string,
|
|
|
|
|
|
|
|
link: string,
|
|
|
|
linkVisited: string,
|
2021-03-05 23:27:42 +01:00
|
|
|
|
|
|
|
propDefault: string,
|
|
|
|
propGray: string,
|
|
|
|
propBrown: string,
|
|
|
|
propOrange: string,
|
|
|
|
propYellow: string,
|
|
|
|
propGreen: string,
|
|
|
|
propBlue: string,
|
|
|
|
propPurple: string,
|
|
|
|
propPink: string,
|
|
|
|
propRed: string,
|
2020-10-27 11:40:32 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 13:25:25 +02:00
|
|
|
export const systemThemeName = 'system-theme'
|
|
|
|
|
|
|
|
export const defaultThemeName = 'default-theme'
|
|
|
|
|
2021-01-04 20:19:03 +01:00
|
|
|
export const defaultTheme = {
|
|
|
|
mainBg: '255, 255, 255',
|
2021-09-14 13:13:52 +02:00
|
|
|
mainFg: '63, 67, 80',
|
|
|
|
buttonBg: '28, 88, 217',
|
2021-01-04 20:19:03 +01:00
|
|
|
buttonFg: '255, 255, 255',
|
2021-09-14 13:13:52 +02:00
|
|
|
sidebarBg: '30, 50, 92',
|
2021-01-04 20:19:03 +01:00
|
|
|
sidebarFg: '255, 255, 255',
|
2022-01-31 11:33:06 +01:00
|
|
|
sidebarTextActiveBorder: '93, 137, 243',
|
2021-01-28 22:51:45 +01:00
|
|
|
sidebarWhiteLogo: 'true',
|
2021-03-05 23:27:42 +01:00
|
|
|
|
2021-03-05 23:37:30 +01:00
|
|
|
link: '#0000ee',
|
|
|
|
linkVisited: '#551a8b',
|
|
|
|
|
2021-03-05 23:27:42 +01:00
|
|
|
propDefault: '#fff',
|
|
|
|
propGray: '#EDEDED',
|
|
|
|
propBrown: '#F7DDC3',
|
|
|
|
propOrange: '#ffd3c1',
|
|
|
|
propYellow: '#f7f0b6',
|
|
|
|
propGreen: '#c7eac3',
|
|
|
|
propBlue: '#B1D1F6',
|
|
|
|
propPurple: '#e6d0ff',
|
|
|
|
propPink: '#ffd6e9',
|
|
|
|
propRed: '#ffa9a9',
|
2021-01-04 20:19:03 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 13:25:25 +02:00
|
|
|
export const darkThemeName = 'dark-theme'
|
|
|
|
|
2020-10-27 11:40:32 +01:00
|
|
|
export const darkTheme = {
|
2021-03-05 23:27:42 +01:00
|
|
|
...defaultTheme,
|
|
|
|
|
2020-10-27 11:40:32 +01:00
|
|
|
mainBg: '55, 53, 47',
|
2021-07-20 17:54:03 +02:00
|
|
|
mainFg: '220, 220, 220',
|
2020-10-27 11:40:32 +01:00
|
|
|
buttonBg: '80, 170, 221',
|
|
|
|
buttonFg: '255, 255, 255',
|
|
|
|
sidebarBg: '75, 73, 67',
|
|
|
|
sidebarFg: '255, 255, 255',
|
2022-01-31 11:33:06 +01:00
|
|
|
sidebarTextActiveBorder: '102, 185, 167',
|
2021-01-28 22:51:45 +01:00
|
|
|
sidebarWhiteLogo: 'true',
|
2021-03-05 23:27:42 +01:00
|
|
|
|
2021-03-05 23:37:30 +01:00
|
|
|
link: '#0090ff',
|
|
|
|
linkVisited: 'hsla(270, 68%, 70%, 1.0)',
|
|
|
|
|
2021-07-20 17:54:03 +02:00
|
|
|
propDefault: 'hsla(0, 100%, 100%, 0.08)',
|
2021-03-05 23:27:42 +01:00
|
|
|
propGray: 'hsla(0, 0%, 70%, 0.4)',
|
|
|
|
propBrown: 'hsla(25, 60%, 40%, 0.4)',
|
|
|
|
propOrange: 'hsla(35, 100%, 50%, 0.4)',
|
|
|
|
propYellow: 'hsla(48, 100%, 70%, 0.4)',
|
|
|
|
propGreen: 'hsla(120, 100%, 70%, 0.4)',
|
|
|
|
propBlue: 'hsla(240, 100%, 70%, 0.4)',
|
|
|
|
propPurple: 'hsla(270, 100%, 64%, 0.4)',
|
|
|
|
propPink: 'hsla(310, 100%, 80%, 0.4)',
|
|
|
|
propRed: 'hsla(4, 100%, 70%, 0.4)',
|
2020-10-27 11:40:32 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 13:25:25 +02:00
|
|
|
export const lightThemeName = 'light-theme'
|
|
|
|
|
2020-10-27 11:40:32 +01:00
|
|
|
export const lightTheme = {
|
2021-03-05 23:27:42 +01:00
|
|
|
...defaultTheme,
|
|
|
|
|
2020-10-27 11:40:32 +01:00
|
|
|
mainBg: '255, 255, 255',
|
|
|
|
mainFg: '55, 53, 47',
|
|
|
|
buttonBg: '80, 170, 221',
|
|
|
|
buttonFg: '255, 255, 255',
|
|
|
|
sidebarBg: '247, 246, 243',
|
|
|
|
sidebarFg: '55, 53, 47',
|
2022-01-31 11:33:06 +01:00
|
|
|
sidebarTextActiveBorder: '87, 158, 255',
|
2021-01-28 22:51:45 +01:00
|
|
|
sidebarWhiteLogo: 'false',
|
2020-10-27 11:40:32 +01:00
|
|
|
}
|
|
|
|
|
2021-03-20 08:52:24 +01:00
|
|
|
export function setTheme(theme: Theme | null): Theme {
|
|
|
|
let consolidatedTheme = defaultTheme
|
|
|
|
if (theme) {
|
|
|
|
consolidatedTheme = {...defaultTheme, ...theme}
|
2021-08-15 12:51:19 +02:00
|
|
|
UserSettings.theme = JSON.stringify(consolidatedTheme)
|
2021-03-20 08:52:24 +01:00
|
|
|
} else {
|
2021-08-15 12:51:19 +02:00
|
|
|
UserSettings.theme = ''
|
2021-03-20 08:52:24 +01:00
|
|
|
const darkThemeMq = window.matchMedia('(prefers-color-scheme: dark)')
|
|
|
|
if (darkThemeMq.matches) {
|
|
|
|
consolidatedTheme = {...defaultTheme, ...darkTheme}
|
|
|
|
}
|
|
|
|
}
|
2021-03-05 23:27:42 +01:00
|
|
|
|
2021-06-07 13:25:25 +02:00
|
|
|
setActiveThemeName(consolidatedTheme, theme)
|
|
|
|
|
2021-08-06 19:58:28 +02:00
|
|
|
if (!Utils.isFocalboardPlugin()) {
|
|
|
|
document.documentElement.style.setProperty('--center-channel-bg-rgb', consolidatedTheme.mainBg)
|
|
|
|
document.documentElement.style.setProperty('--center-channel-color-rgb', consolidatedTheme.mainFg)
|
|
|
|
document.documentElement.style.setProperty('--button-bg-rgb', consolidatedTheme.buttonBg)
|
|
|
|
document.documentElement.style.setProperty('--button-color-rgb', consolidatedTheme.buttonFg)
|
|
|
|
document.documentElement.style.setProperty('--sidebar-bg-rgb', consolidatedTheme.sidebarBg)
|
|
|
|
document.documentElement.style.setProperty('--sidebar-text-rgb', consolidatedTheme.sidebarFg)
|
|
|
|
document.documentElement.style.setProperty('--link-color-rgb', consolidatedTheme.link)
|
2022-01-31 11:33:06 +01:00
|
|
|
document.documentElement.style.setProperty('--sidebar-text-active-border-rgb', consolidatedTheme.sidebarTextActiveBorder)
|
2021-08-06 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-05 23:27:42 +01:00
|
|
|
document.documentElement.style.setProperty('--sidebar-white-logo', consolidatedTheme.sidebarWhiteLogo)
|
2021-08-06 19:58:28 +02:00
|
|
|
document.documentElement.style.setProperty('--link-visited-color-rgb', consolidatedTheme.linkVisited)
|
2021-03-05 23:27:42 +01:00
|
|
|
|
2021-08-06 19:58:28 +02:00
|
|
|
const mainBgColor = color(`rgb(${getComputedStyle(document.documentElement).getPropertyValue('--center-channel-bg-rgb')})`)
|
|
|
|
|
|
|
|
if (Utils.isFocalboardPlugin()) {
|
|
|
|
let fixedTheme = lightTheme
|
|
|
|
if (mainBgColor.isDark()) {
|
|
|
|
fixedTheme = darkTheme
|
|
|
|
}
|
|
|
|
consolidatedTheme.propDefault = fixedTheme.propDefault
|
|
|
|
consolidatedTheme.propGray = fixedTheme.propGray
|
|
|
|
consolidatedTheme.propBrown = fixedTheme.propBrown
|
|
|
|
consolidatedTheme.propOrange = fixedTheme.propOrange
|
|
|
|
consolidatedTheme.propYellow = fixedTheme.propYellow
|
|
|
|
consolidatedTheme.propGreen = fixedTheme.propGreen
|
|
|
|
consolidatedTheme.propBlue = fixedTheme.propBlue
|
|
|
|
consolidatedTheme.propPurple = fixedTheme.propPurple
|
|
|
|
consolidatedTheme.propPink = fixedTheme.propPink
|
|
|
|
consolidatedTheme.propRed = fixedTheme.propRed
|
|
|
|
}
|
2021-03-05 23:37:30 +01:00
|
|
|
|
2021-03-05 23:27:42 +01:00
|
|
|
document.documentElement.style.setProperty('--prop-default', consolidatedTheme.propDefault)
|
|
|
|
document.documentElement.style.setProperty('--prop-gray', consolidatedTheme.propGray)
|
|
|
|
document.documentElement.style.setProperty('--prop-brown', consolidatedTheme.propBrown)
|
|
|
|
document.documentElement.style.setProperty('--prop-orange', consolidatedTheme.propOrange)
|
|
|
|
document.documentElement.style.setProperty('--prop-yellow', consolidatedTheme.propYellow)
|
|
|
|
document.documentElement.style.setProperty('--prop-green', consolidatedTheme.propGreen)
|
|
|
|
document.documentElement.style.setProperty('--prop-blue', consolidatedTheme.propBlue)
|
|
|
|
document.documentElement.style.setProperty('--prop-purple', consolidatedTheme.propPurple)
|
|
|
|
document.documentElement.style.setProperty('--prop-pink', consolidatedTheme.propPink)
|
|
|
|
document.documentElement.style.setProperty('--prop-red', consolidatedTheme.propRed)
|
|
|
|
|
2021-03-20 08:52:24 +01:00
|
|
|
return consolidatedTheme
|
2020-10-27 13:01:15 +01:00
|
|
|
}
|
|
|
|
|
2021-08-11 11:53:53 +02:00
|
|
|
export function setMattermostTheme(theme: any): Theme {
|
2021-09-14 13:13:52 +02:00
|
|
|
if (!theme) {
|
|
|
|
return setTheme(defaultTheme)
|
|
|
|
}
|
|
|
|
|
2021-08-11 11:53:53 +02:00
|
|
|
document.documentElement.style.setProperty('--center-channel-bg-rgb', color(theme.centerChannelBg).rgb().array().join(', '))
|
|
|
|
document.documentElement.style.setProperty('--center-channel-color-rgb', color(theme.centerChannelColor).rgb().array().join(', '))
|
|
|
|
document.documentElement.style.setProperty('--button-bg-rgb', color(theme.buttonBg).rgb().array().join(', '))
|
|
|
|
document.documentElement.style.setProperty('--button-color-rgb', color(theme.buttonColor).rgb().array().join(', '))
|
|
|
|
document.documentElement.style.setProperty('--sidebar-bg-rgb', color(theme.sidebarBg).rgb().array().join(', '))
|
|
|
|
document.documentElement.style.setProperty('--sidebar-text-rgb', color(theme.sidebarText).rgb().array().join(', '))
|
2021-08-13 16:51:18 +02:00
|
|
|
document.documentElement.style.setProperty('--link-color-rgb', theme.linkColor)
|
2022-01-31 11:33:06 +01:00
|
|
|
document.documentElement.style.setProperty('--sidebar-text-active-border-rgb', color(theme.sidebarTextActiveBorder).rgb().array().join(', '))
|
2021-08-11 11:53:53 +02:00
|
|
|
|
|
|
|
return setTheme({
|
|
|
|
...defaultTheme,
|
|
|
|
mainBg: color(theme.centerChannelBg).rgb().array().join(', '),
|
|
|
|
mainFg: color(theme.centerChannelColor).rgb().array().join(', '),
|
|
|
|
buttonBg: color(theme.buttonBg).rgb().array().join(', '),
|
|
|
|
buttonFg: color(theme.buttonColor).rgb().array().join(', '),
|
|
|
|
sidebarBg: color(theme.sidebarBg).rgb().array().join(', '),
|
|
|
|
sidebarFg: color(theme.sidebarColor || '#ffffff').rgb().array().join(', '),
|
|
|
|
sidebarTextActiveBorder: color(theme.sidebarTextActiveBorder).rgb().array().join(', '),
|
2021-08-13 16:51:18 +02:00
|
|
|
link: theme.linkColor,
|
2021-08-11 11:53:53 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-07 13:25:25 +02:00
|
|
|
function setActiveThemeName(consolidatedTheme: Theme, theme: Theme | null) {
|
|
|
|
if (theme === null) {
|
|
|
|
activeThemeName = systemThemeName
|
|
|
|
} else if (isEqual(consolidatedTheme, darkTheme)) {
|
|
|
|
activeThemeName = darkThemeName
|
|
|
|
} else if (isEqual(consolidatedTheme, lightTheme)) {
|
|
|
|
activeThemeName = lightThemeName
|
|
|
|
} else {
|
|
|
|
activeThemeName = defaultThemeName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 22:51:45 +01:00
|
|
|
export function loadTheme(): Theme {
|
2021-08-15 12:51:19 +02:00
|
|
|
const themeStr = UserSettings.theme
|
2020-10-27 13:01:15 +01:00
|
|
|
if (themeStr) {
|
|
|
|
try {
|
|
|
|
const theme = JSON.parse(themeStr)
|
2021-06-07 13:25:25 +02:00
|
|
|
const consolidatedTheme = setTheme(theme)
|
|
|
|
setActiveThemeName(consolidatedTheme, theme)
|
|
|
|
return consolidatedTheme
|
2020-10-27 13:01:15 +01:00
|
|
|
} catch (e) {
|
2021-03-20 08:52:24 +01:00
|
|
|
return setTheme(null)
|
2020-10-27 13:01:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-03-20 08:52:24 +01:00
|
|
|
return setTheme(null)
|
2020-10-27 13:01:15 +01:00
|
|
|
}
|
2020-10-27 11:40:32 +01:00
|
|
|
}
|
2021-03-21 08:51:22 +01:00
|
|
|
|
|
|
|
export function initThemes(): void {
|
|
|
|
const darkThemeMq = window.matchMedia('(prefers-color-scheme: dark)')
|
2021-04-01 07:03:16 +02:00
|
|
|
const changeHandler = () => {
|
2021-08-15 12:51:19 +02:00
|
|
|
const themeStr = UserSettings.theme
|
2021-03-21 08:51:22 +01:00
|
|
|
if (!themeStr) {
|
|
|
|
setTheme(null)
|
|
|
|
}
|
2021-04-01 07:03:16 +02:00
|
|
|
}
|
|
|
|
if (darkThemeMq.addEventListener) {
|
|
|
|
darkThemeMq.addEventListener('change', changeHandler)
|
|
|
|
} else if (darkThemeMq.addListener) {
|
|
|
|
// Safari and Mac app support
|
|
|
|
darkThemeMq.addListener(changeHandler)
|
|
|
|
}
|
2021-03-21 08:51:22 +01:00
|
|
|
loadTheme()
|
|
|
|
}
|
2021-06-04 15:23:15 +02:00
|
|
|
|
|
|
|
export function getSelectBaseStyle() {
|
|
|
|
return {
|
|
|
|
dropdownIndicator: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
display: 'none !important',
|
|
|
|
}),
|
|
|
|
indicatorSeparator: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
display: 'none',
|
|
|
|
}),
|
|
|
|
loadingIndicator: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
display: 'none',
|
|
|
|
}),
|
|
|
|
clearIndicator: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
display: 'none',
|
|
|
|
}),
|
|
|
|
menu: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
width: 'unset',
|
2021-08-06 19:58:28 +02:00
|
|
|
background: 'rgb(var(--center-channel-bg-rgb))',
|
2021-06-04 15:23:15 +02:00
|
|
|
}),
|
|
|
|
option: (provided: CSSObject, state: { isFocused: boolean }): CSSObject => ({
|
|
|
|
...provided,
|
2021-08-06 19:58:28 +02:00
|
|
|
background: state.isFocused ? 'rgba(var(--center-channel-color-rgb), 0.1)' : 'rgb(var(--center-channel-bg-rgb))',
|
|
|
|
color: state.isFocused ? 'rgb(var(--center-channel-color-rgb))' : 'rgb(var(--center-channel-color-rgb))',
|
2021-06-04 15:23:15 +02:00
|
|
|
padding: '2px 8px',
|
|
|
|
}),
|
|
|
|
control: (): CSSObject => ({
|
|
|
|
border: 0,
|
|
|
|
width: '100%',
|
|
|
|
margin: '4px 0 0 0',
|
|
|
|
|
|
|
|
// display: 'flex',
|
|
|
|
// marginTop: 0,
|
|
|
|
}),
|
|
|
|
valueContainer: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
padding: '0 5px',
|
|
|
|
overflow: 'unset',
|
|
|
|
}),
|
|
|
|
singleValue: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
2021-08-06 19:58:28 +02:00
|
|
|
color: 'rgb(var(--center-channel-color-rgb))',
|
2021-06-04 15:23:15 +02:00
|
|
|
overflow: 'unset',
|
|
|
|
maxWidth: 'calc(100% - 20px)',
|
|
|
|
}),
|
|
|
|
input: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
|
|
|
paddingBottom: 0,
|
|
|
|
paddingTop: 0,
|
|
|
|
marginBottom: 0,
|
|
|
|
marginTop: 0,
|
|
|
|
}),
|
|
|
|
menuList: (provided: CSSObject): CSSObject => ({
|
|
|
|
...provided,
|
2021-06-21 11:56:48 +02:00
|
|
|
overflowY: 'auto',
|
|
|
|
overflowX: 'hidden',
|
2021-06-04 15:23:15 +02:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
2021-06-07 13:25:25 +02:00
|
|
|
|
|
|
|
export function getActiveThemeName(): string {
|
|
|
|
return activeThemeName || defaultThemeName
|
|
|
|
}
|