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 Box from '@mui/material/Box';
|
|
|
|
|
import { ReactNode } from 'react';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { CurrentPageSlotProps } from '@/features/reader/overlay/progress-bar/ReaderProgressBar.types.ts';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { applyStyles } from '@/base/utils/ApplyStyles.ts';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { getProgressBarPositionInfo } from '@/features/reader/overlay/progress-bar/ReaderProgressBar.utils.tsx';
|
|
|
|
|
import { READER_PROGRESS_BAR_POSITION_TO_PLACEMENT } from '@/features/reader/settings/ReaderSettings.constants.tsx';
|
2024-09-28 03:24:16 +02:00
|
|
|
|
|
|
|
|
export const ReaderProgressBarCurrentPageSlot = ({
|
|
|
|
|
pageName,
|
|
|
|
|
currentPagesIndex,
|
|
|
|
|
pagesLength,
|
|
|
|
|
isDragging,
|
|
|
|
|
boxProps,
|
|
|
|
|
children,
|
|
|
|
|
progressBarPosition,
|
|
|
|
|
}: CurrentPageSlotProps & { children?: ReactNode }) => (
|
2025-02-01 14:24:38 +01:00
|
|
|
<CustomTooltip
|
2024-09-28 03:24:16 +02:00
|
|
|
title={pageName}
|
|
|
|
|
slotProps={{
|
|
|
|
|
tooltip: { sx: { backgroundColor: 'primary.main', color: 'primary.contrastText' } },
|
|
|
|
|
}}
|
|
|
|
|
placement={READER_PROGRESS_BAR_POSITION_TO_PLACEMENT[progressBarPosition]}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
{...boxProps}
|
|
|
|
|
sx={{
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
cursor: isDragging ? 'grabbing' : 'grab',
|
|
|
|
|
...applyStyles(getProgressBarPositionInfo(progressBarPosition).isHorizontal, {
|
2024-12-27 17:01:34 +01:00
|
|
|
left: `${(Math.max(0, currentPagesIndex - 1) / (pagesLength - 1)) * 100}%`,
|
|
|
|
|
width: `calc(100% / ${pagesLength - 1})`,
|
2024-09-28 03:24:16 +02:00
|
|
|
height: '100%',
|
|
|
|
|
}),
|
|
|
|
|
...applyStyles(getProgressBarPositionInfo(progressBarPosition).isVertical, {
|
2025-01-02 21:25:35 +01:00
|
|
|
top: `${(Math.max(0, currentPagesIndex - 1) / (pagesLength - 1)) * 100}%`,
|
2024-09-28 03:24:16 +02:00
|
|
|
width: '100%',
|
2024-12-27 17:01:34 +01:00
|
|
|
height: `calc(100% / ${pagesLength - 1})`,
|
2024-09-28 03:24:16 +02:00
|
|
|
}),
|
|
|
|
|
...boxProps?.sx,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</Box>
|
2025-02-01 14:24:38 +01:00
|
|
|
</CustomTooltip>
|
2024-09-28 03:24:16 +02:00
|
|
|
);
|