2021-01-13 07:55:56 +08:00
|
|
|
import { createMuiTheme, Theme } from "@material-ui/core/styles";
|
2021-01-14 05:58:10 +08:00
|
|
|
import { ThemePreference } from "./reducers/settingsReducer";
|
|
|
|
import useMediaQuery from "@material-ui/core/useMediaQuery";
|
2020-11-24 22:54:00 +08:00
|
|
|
|
2021-01-15 12:46:41 +08:00
|
|
|
export function useTheme(themePreference: ThemePreference): Theme {
|
2021-01-14 05:58:10 +08:00
|
|
|
let prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
|
|
|
if (themePreference === ThemePreference.Always) {
|
|
|
|
prefersDarkMode = true;
|
|
|
|
} else if (themePreference === ThemePreference.Never) {
|
|
|
|
prefersDarkMode = false;
|
|
|
|
}
|
2021-01-13 07:55:56 +08:00
|
|
|
return createMuiTheme({
|
|
|
|
// Got color palette from https://htmlcolors.com/palette/31/stripe
|
|
|
|
palette: {
|
|
|
|
primary: {
|
|
|
|
main: "#4379FF",
|
|
|
|
},
|
|
|
|
secondary: {
|
|
|
|
main: "#97FBD1",
|
|
|
|
},
|
|
|
|
background: {
|
|
|
|
default: "#f5f7f9",
|
|
|
|
},
|
2021-01-14 05:58:10 +08:00
|
|
|
type: prefersDarkMode ? "dark" : "light",
|
2020-11-24 22:54:00 +08:00
|
|
|
},
|
2021-01-13 07:55:56 +08:00
|
|
|
});
|
|
|
|
}
|