Files
suwayomi-material-you-webui/src/theme.ts
T

85 lines
2.6 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2024-05-20 16:28:36 +02:00
import {
createTheme as createMuiTheme,
darken,
Direction,
lighten,
Palette as MuiPalette,
Theme,
} from '@mui/material/styles';
2023-06-04 21:08:39 +02:00
declare module '@mui/material/styles/createPalette' {
interface Palette {
custom: Palette['primary'];
}
interface PaletteOptions {
2023-06-04 21:08:39 +02:00
custom: PaletteOptions['primary'];
}
}
2024-08-30 15:52:02 +02:00
export const SCROLLBAR_WIDTH = 14;
2023-06-04 21:08:39 +02:00
type DefaultMuiPalette = Omit<MuiPalette, 'custom'>;
type DefaultMuiTheme = Omit<Theme, 'palette'> & { palette: DefaultMuiPalette };
let theme: Theme;
export const getCurrentTheme = () => theme;
2024-04-25 14:07:59 +02:00
export const createTheme = (dark?: boolean, direction: Direction = 'ltr') => {
2023-06-04 21:08:39 +02:00
const baseTheme: DefaultMuiTheme = createMuiTheme({
2024-04-25 14:07:59 +02:00
direction,
palette: {
mode: dark ? 'dark' : 'light',
},
2023-06-04 21:08:39 +02:00
} as Theme);
2024-01-05 20:11:29 +01:00
const suwayomiTheme = createMuiTheme(
2023-02-06 10:06:33 +01:00
{
palette: {
custom: {
main: dark ? baseTheme.palette.common.black : baseTheme.palette.common.white,
light: dark ? baseTheme.palette.grey[900] : baseTheme.palette.grey[100],
},
},
2023-02-06 10:06:33 +01:00
components: {
2023-06-17 16:50:17 +02:00
MuiUseMediaQuery: {
defaultProps: {
noSsr: true,
},
},
2023-02-06 10:06:33 +01:00
MuiCssBaseline: {
styleOverrides: `
2024-05-20 16:28:36 +02:00
*::-webkit-scrollbar {
2024-08-30 15:52:02 +02:00
width: ${SCROLLBAR_WIDTH}px;
2024-05-20 16:28:36 +02:00
}
*::-webkit-scrollbar-thumb {
border: 4px solid rgba(0, 0, 0, 0);
background-clip: padding-box;
border-radius: 9999px;
background-color: ${dark ? lighten(baseTheme.palette.background.default, 0.4) : darken(baseTheme.palette.background.default, 0.4)};
}
*::-webkit-scrollbar-thumb:hover {
border-width: 2px;
}
`,
2023-02-06 10:06:33 +01:00
},
},
},
2023-02-06 10:06:33 +01:00
baseTheme,
);
theme = suwayomiTheme;
2024-01-05 20:11:29 +01:00
return suwayomiTheme;
};
2024-04-26 12:53:31 +02:00
export const getOptionForDirection = <T>(ltrOption: T, rtlOption: T): T =>
(theme?.direction ?? 'ltr') === 'ltr' ? ltrOption : rtlOption;