forked from devhubapp/devhub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
51 lines (42 loc) · 1.5 KB
/
utils.ts
File metadata and controls
51 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { constants, isNight, Theme, ThemePair } from '@devhub/core'
import { themes } from './themes'
import { createThemeFromColor } from './themes/custom'
export function loadCustomTheme(color: string) {
return createThemeFromColor(color, 'custom', 'Custom')
}
export function loadTheme(
theme?: ThemePair,
preferredDarkTheme?: ThemePair,
preferredLightTheme?: ThemePair,
): Theme {
const _theme = theme || constants.DEFAULT_THEME_PAIR
if (_theme.id === 'custom' && _theme.color) {
return loadCustomTheme(_theme.color)
}
if (_theme.id === 'auto' || !_theme.id) {
const _preferredDarkTheme = preferredDarkTheme
? preferredDarkTheme.id === 'custom' && preferredDarkTheme.color
? loadCustomTheme(preferredDarkTheme.color)
: themes[preferredDarkTheme.id]
: undefined
const _preferredLightTheme = preferredLightTheme
? preferredLightTheme.id === 'custom' && preferredLightTheme.color
? loadCustomTheme(preferredLightTheme.color)
: themes[preferredLightTheme.id]
: undefined
const darkTheme: Theme =
_preferredDarkTheme || themes[constants.DEFAULT_DARK_THEME]!
const lightTheme: Theme =
_preferredLightTheme || themes[constants.DEFAULT_LIGHT_THEME]!
return isNight() ? darkTheme : lightTheme
}
return (
themes[_theme.id] ||
loadTheme(
{ id: 'auto', color: _theme.color },
preferredDarkTheme,
preferredLightTheme,
)
)
}
export const defaultTheme = loadTheme(constants.DEFAULT_THEME_PAIR)