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

70 lines
2.0 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-04-25 14:07:59 +02:00
import { createTheme as createMuiTheme, Direction, Palette as MuiPalette, Theme } from '@mui/material/styles';
declare module '@mui/material/styles/createPalette' {
interface Palette {
custom: Palette['primary'];
}
interface PaletteOptions {
custom: PaletteOptions['primary'];
}
}
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') => {
const baseTheme: DefaultMuiTheme = createMuiTheme({
2024-04-25 14:07:59 +02:00
direction,
palette: {
mode: dark ? 'dark' : 'light',
},
} as Theme);
const suwayomiTheme = createMuiTheme(
{
palette: {
custom: {
main: dark ? baseTheme.palette.common.black : baseTheme.palette.common.white,
light: dark ? baseTheme.palette.grey[900] : baseTheme.palette.grey[100],
},
},
components: {
Feature/virtualize manga grid (#363) * Disable ssr by default for "useMediaQuery" SSR would cause the hook to run once with default values and only after the first render with real values. This can cause issue on rendering when depending on useMediaQuery results like in 8c129f2e08e8c807b57c7eef802556faa2edcf1b * Virtualize manga grids * Remove SourceMangas load more guard Was required due to the previous load more trigger logic from the MangaGrid. Due to using Virtuoso now, load more will be triggered only once when the bottom of the grid was reached and thus won't trigger multiple load more requests * Remove old Library pagination Pagination is handled by virtuoso, thus, the previous pagination can be removed * Increase initial loaded pages to make infinite load work virtuoso requires enough initial items to be rendered, so that actual virtualization takes effect, for it to fire "endReached" * Prevent virtuoso grid scrollbar from jumping around In case the items have a big height difference there is a bug where the scrollbar starts jumping around the moment these new items are rendered * Restore scroll position For some reason the UI jumps around when accessing "document.documentElement" during loading more items. After the items are rendered the loading placeholder gets removed and the previous items jump to the bottom of the viewport. * Limit manga grid titles to two lines * Remove "last page" info from MangaGrid Info is not needed. The only thing the MangaGrid has to do is to trigger a request to load more data
2023-06-17 16:50:17 +02:00
MuiUseMediaQuery: {
defaultProps: {
noSsr: true,
},
},
MuiCssBaseline: {
styleOverrides: `
*::-webkit-scrollbar {
width: 10px;
background: ${dark ? '#222' : '#e1e1e1'};
}
*::-webkit-scrollbar-thumb {
background: ${dark ? '#111' : '#aaa'};
border-radius: 5px;
}
`,
},
},
},
baseTheme,
);
theme = suwayomiTheme;
return suwayomiTheme;
};