2019-03-25 21:48:25 +01:00
|
|
|
import { createMuiTheme, Theme } from '@material-ui/core';
|
2019-04-20 22:35:38 +02:00
|
|
|
import { HyperspaceTheme, themes, defaultTheme } from '../types/HyperspaceTheme';
|
2019-03-27 22:39:25 +01:00
|
|
|
import { getUserDefaultBool } from './settings';
|
2019-03-25 21:48:25 +01:00
|
|
|
|
2019-04-20 22:35:38 +02:00
|
|
|
/**
|
|
|
|
* Locates a Hyperspace theme from the themes catalog
|
|
|
|
* @param name The name of the theme to return
|
|
|
|
* @returns Hyperspace theme with name or the default
|
|
|
|
*/
|
|
|
|
export function getHyperspaceTheme(name: string): HyperspaceTheme {
|
|
|
|
let theme: HyperspaceTheme = defaultTheme;
|
|
|
|
themes.forEach((themeItem: HyperspaceTheme) => {
|
|
|
|
if (themeItem.key === name) {
|
|
|
|
theme = themeItem;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return theme;
|
|
|
|
}
|
|
|
|
|
2019-03-25 21:48:25 +01:00
|
|
|
/**
|
|
|
|
* Creates a Material-UI theme from a selected Hyperspace theme palette.
|
|
|
|
* @param theme The Hyperspace theme that should be applied
|
|
|
|
* @returns A Material-UI theme with the Hyperspace theme's palette colors
|
|
|
|
*/
|
|
|
|
export function setHyperspaceTheme(theme: HyperspaceTheme): Theme {
|
|
|
|
return createMuiTheme({
|
|
|
|
typography: {
|
|
|
|
fontFamily: [
|
|
|
|
'-apple-system',
|
|
|
|
'BlinkMacSystemFont',
|
|
|
|
'"Segoe UI"',
|
|
|
|
'Roboto',
|
|
|
|
'"Helvetica Neue"',
|
|
|
|
'Arial',
|
|
|
|
'sans-serif',
|
|
|
|
'"Apple Color Emoji"',
|
|
|
|
'"Segoe UI Emoji"',
|
|
|
|
'"Segoe UI Symbol"',
|
|
|
|
].join(','),
|
2019-03-26 02:37:02 +01:00
|
|
|
useNextVariants: true,
|
2019-03-25 21:48:25 +01:00
|
|
|
},
|
|
|
|
palette: {
|
|
|
|
primary: theme.palette.primary,
|
2019-03-27 22:39:25 +01:00
|
|
|
secondary: theme.palette.secondary,
|
|
|
|
type: getUserDefaultBool('darkModeEnabled')? "dark": "light"
|
2019-03-25 21:48:25 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the app's palette type (aka. turns on an off dark mode)
|
|
|
|
* @param theme The Material-UI theme to toggle the dark mode on
|
|
|
|
* @param setting Whether dark mode should be on (`true`) or off (`false`)
|
|
|
|
*/
|
|
|
|
export function darkMode(theme: Theme, setting: boolean): Theme {
|
|
|
|
if (setting) {
|
|
|
|
theme.palette.type = 'dark';
|
|
|
|
} else {
|
|
|
|
theme.palette.type = 'light';
|
|
|
|
}
|
|
|
|
return theme;
|
|
|
|
}
|