bitburner-src/src/ui/React/Theme.tsx

288 lines
7.0 KiB
TypeScript
Raw Normal View History

2021-09-13 18:44:46 +02:00
import React from "react";
2021-09-18 01:43:08 +02:00
import { createTheme, ThemeProvider, Theme, StyledEngineProvider } from "@mui/material/styles";
2021-09-22 07:36:17 +02:00
import { EventEmitter } from "../../utils/EventEmitter";
2021-09-22 08:20:29 +02:00
import { Settings } from "../../Settings/Settings";
2021-09-22 07:36:17 +02:00
export const ThemeEvents = new EventEmitter<[]>();
2021-09-17 01:23:03 +02:00
2021-09-21 02:42:13 +02:00
declare module "@mui/material/styles" {
interface Theme {
colors: {
hp: React.CSSProperties["color"];
money: React.CSSProperties["color"];
hack: React.CSSProperties["color"];
combat: React.CSSProperties["color"];
cha: React.CSSProperties["color"];
int: React.CSSProperties["color"];
rep: React.CSSProperties["color"];
};
}
interface ThemeOptions {
colors: {
hp: React.CSSProperties["color"];
money: React.CSSProperties["color"];
hack: React.CSSProperties["color"];
combat: React.CSSProperties["color"];
cha: React.CSSProperties["color"];
int: React.CSSProperties["color"];
rep: React.CSSProperties["color"];
};
}
2021-09-17 01:23:03 +02:00
}
2021-09-13 18:44:46 +02:00
2021-09-22 02:30:00 +02:00
let theme: Theme;
2021-09-21 19:08:05 +02:00
2021-09-25 07:26:03 +02:00
export function refreshTheme(): void {
2021-09-21 19:08:05 +02:00
theme = createTheme({
colors: {
2021-09-22 08:20:29 +02:00
hp: Settings.theme.hp,
money: Settings.theme.money,
hack: Settings.theme.hack,
combat: Settings.theme.combat,
cha: Settings.theme.cha,
int: Settings.theme.int,
rep: Settings.theme.rep,
2021-09-18 03:30:02 +02:00
},
2021-09-21 19:08:05 +02:00
palette: {
primary: {
2021-09-22 08:20:29 +02:00
light: Settings.theme.primarylight,
main: Settings.theme.primary,
dark: Settings.theme.primarydark,
2021-09-21 19:08:05 +02:00
},
secondary: {
2021-09-22 08:20:29 +02:00
light: Settings.theme.secondarylight,
main: Settings.theme.secondary,
dark: Settings.theme.secondarydark,
2021-09-21 19:08:05 +02:00
},
error: {
2021-09-22 08:20:29 +02:00
light: Settings.theme.errorlight,
main: Settings.theme.error,
dark: Settings.theme.errordark,
2021-09-21 19:08:05 +02:00
},
info: {
2021-09-22 08:20:29 +02:00
light: Settings.theme.infolight,
main: Settings.theme.info,
dark: Settings.theme.infodark,
2021-09-21 19:08:05 +02:00
},
warning: {
2021-09-22 08:20:29 +02:00
light: Settings.theme.warninglight,
main: Settings.theme.warning,
dark: Settings.theme.warningdark,
2021-09-21 19:08:05 +02:00
},
background: {
2021-09-22 08:20:29 +02:00
default: Settings.theme.black,
paper: Settings.theme.well,
2021-09-21 19:08:05 +02:00
},
2021-09-27 03:37:22 +02:00
action: {
disabled: Settings.theme.disabled,
},
2021-09-15 03:05:49 +02:00
},
2021-09-21 19:08:05 +02:00
typography: {
fontFamily: "monospace",
button: {
textTransform: "none",
},
2021-09-13 18:44:46 +02:00
},
2021-09-21 19:08:05 +02:00
components: {
MuiInputBase: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.well,
color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
input: {
"&::placeholder": {
userSelect: "none",
2021-09-22 08:20:29 +02:00
color: Settings.theme.primarydark,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
},
2021-09-17 01:23:03 +02:00
2021-09-21 19:08:05 +02:00
MuiInput: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.well,
2021-09-21 19:08:05 +02:00
borderBottomColor: "#fff",
2021-09-17 01:23:03 +02:00
},
2021-09-21 19:08:05 +02:00
underline: {
"&:hover": {
2021-09-22 08:20:29 +02:00
borderBottomColor: Settings.theme.primarydark,
2021-09-21 19:08:05 +02:00
},
"&:before": {
2021-09-22 08:20:29 +02:00
borderBottomColor: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
"&:after": {
2021-09-22 08:20:29 +02:00
borderBottomColor: Settings.theme.primarylight,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
},
2021-09-17 01:23:03 +02:00
2021-09-21 19:08:05 +02:00
MuiInputLabel: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primarydark, // why is this switched?
2021-09-21 19:08:05 +02:00
userSelect: "none",
"&:before": {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primarylight,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
},
2021-09-21 19:08:05 +02:00
MuiButton: {
styleOverrides: {
root: {
backgroundColor: "#333",
2021-09-22 08:20:29 +02:00
border: "1px solid " + Settings.theme.well,
// color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
"&:hover": {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.black,
2021-09-21 19:08:05 +02:00
},
2021-09-14 04:27:43 +02:00
2021-09-21 19:08:05 +02:00
borderRadius: 0,
},
2021-09-18 06:16:02 +02:00
},
},
2021-09-21 19:08:05 +02:00
MuiSelect: {
styleOverrides: {
icon: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
2021-09-21 19:08:05 +02:00
MuiMenu: {
styleOverrides: {
list: {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.well,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
2021-09-21 19:08:05 +02:00
MuiMenuItem: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
2021-09-21 19:08:05 +02:00
MuiAccordionSummary: {
styleOverrides: {
root: {
backgroundColor: "#111",
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
2021-09-21 19:08:05 +02:00
MuiAccordionDetails: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.black,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 02:37:35 +02:00
},
2021-09-21 19:08:05 +02:00
MuiIconButton: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 04:27:43 +02:00
},
2021-09-21 19:08:05 +02:00
MuiTooltip: {
styleOverrides: {
tooltip: {
fontSize: "1em",
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
backgroundColor: Settings.theme.well,
2021-09-21 19:08:05 +02:00
borderRadius: 0,
border: "2px solid white",
maxWidth: "100vh",
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 04:27:43 +02:00
},
2021-09-21 19:08:05 +02:00
MuiSlider: {
styleOverrides: {
valueLabel: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
backgroundColor: Settings.theme.well,
2021-09-21 19:08:05 +02:00
},
},
},
2021-09-21 19:08:05 +02:00
MuiDrawer: {
styleOverrides: {
paper: {
"&::-webkit-scrollbar": {
// webkit
display: "none",
},
scrollbarWidth: "none", // firefox
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.black,
2021-09-21 19:08:05 +02:00
},
paperAnchorDockedLeft: {
2021-09-22 08:20:29 +02:00
borderRight: "1px solid " + Settings.theme.welllight,
2021-09-17 01:23:03 +02:00
},
2021-09-14 20:10:59 +02:00
},
},
2021-09-21 19:08:05 +02:00
MuiDivider: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.welllight,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-15 03:05:49 +02:00
},
2021-09-21 19:08:05 +02:00
MuiFormControlLabel: {
styleOverrides: {
root: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-15 03:05:49 +02:00
},
2021-09-21 19:08:05 +02:00
MuiSwitch: {
styleOverrides: {
switchBase: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primarydark,
2021-09-21 19:08:05 +02:00
},
track: {
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.welllight,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-14 20:10:59 +02:00
},
2021-09-21 19:08:05 +02:00
MuiPaper: {
styleOverrides: {
root: {
borderRadius: 0,
2021-09-22 08:20:29 +02:00
backgroundColor: Settings.theme.black,
border: "1px solid " + Settings.theme.welllight,
2021-09-21 19:08:05 +02:00
},
2021-09-17 01:23:03 +02:00
},
2021-09-16 23:30:47 +02:00
},
2021-09-21 19:08:05 +02:00
MuiTablePagination: {
styleOverrides: {
select: {
2021-09-22 08:20:29 +02:00
color: Settings.theme.primary,
2021-09-21 19:08:05 +02:00
},
2021-09-18 06:16:02 +02:00
},
},
2021-09-27 23:09:48 +02:00
MuiTab: {
styleOverrides: {
textColorPrimary: {
color: Settings.theme.secondary,
"&.Mui-selected": {
color: Settings.theme.primary,
},
},
},
},
2021-09-18 06:16:02 +02:00
},
2021-09-21 19:08:05 +02:00
});
}
refreshTheme();
2021-09-13 18:44:46 +02:00
interface IProps {
children: JSX.Element[] | JSX.Element;
}
2021-09-17 01:23:03 +02:00
export const TTheme = ({ children }: IProps): React.ReactElement => (
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</StyledEngineProvider>
2021-09-13 18:44:46 +02:00
);