Files
suwayomi-material-you-webui/src/features/reader/overlay/progress-bar/components/ReaderProgressBarDirectionWrapper.tsx

49 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-09-28 03:24:16 +02:00
/*
* 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/.
*/
import { forwardRef, useMemo } from 'react';
2024-09-28 03:24:16 +02:00
import { CacheProvider } from '@emotion/react';
import { ThemeProvider } from '@mui/material/styles';
import Box, { BoxProps } from '@mui/material/Box';
2025-08-15 22:02:58 +02:00
import { useMetadataServerSettings } from '@/features/settings/services/ServerSettingsMetadata.ts';
import { getTheme } from '@/features/theme/services/AppThemes.ts';
import { createTheme } from '@/features/theme/services/ThemeCreator.ts';
import { ReaderService } from '@/features/reader/services/ReaderService.ts';
import { DIRECTION_TO_CACHE } from '@/features/theme/ThemeDirectionCache.ts';
import { withPropsFrom } from '@/features/core/hoc/withPropsFrom.tsx';
2024-09-28 03:24:16 +02:00
const BaseReaderProgressBarDirectionWrapper = forwardRef<
HTMLElement,
BoxProps & {
direction: ReturnType<typeof ReaderService.useGetThemeDirection>;
}
>(({ direction, ...boxProps }, ref) => {
2024-09-28 03:24:16 +02:00
const {
settings: { customThemes, appTheme, themeMode, shouldUsePureBlackMode },
2024-09-28 03:24:16 +02:00
} = useMetadataServerSettings();
const readerTheme = useMemo(
() => createTheme(themeMode, getTheme(appTheme, customThemes), shouldUsePureBlackMode, direction),
[themeMode, appTheme, customThemes, shouldUsePureBlackMode, direction],
2024-09-28 03:24:16 +02:00
);
return (
<CacheProvider value={DIRECTION_TO_CACHE[direction]}>
<ThemeProvider theme={readerTheme}>
<Box {...boxProps} ref={ref} dir={direction} />
2024-09-28 03:24:16 +02:00
</ThemeProvider>
</CacheProvider>
);
});
2024-12-21 03:46:55 +01:00
export const ReaderProgressBarDirectionWrapper = withPropsFrom(
BaseReaderProgressBarDirectionWrapper,
[() => ({ direction: ReaderService.useGetThemeDirection() })],
['direction'],
);