Files
suwayomi-material-you-webui/src/components/manga/SelectionFAB.tsx
T

63 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-11-09 18:09:15 +01: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/.
*/
2022-11-09 18:09:15 +01:00
import MoreHoriz from '@mui/icons-material/MoreHoriz';
2023-12-30 04:04:59 +01:00
import { Fab, Box, styled } from '@mui/material';
import React from 'react';
2023-03-23 13:59:32 +01:00
import { useTranslation } from 'react-i18next';
2023-12-30 04:04:59 +01:00
import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state';
2023-06-05 01:42:39 +02:00
import { DEFAULT_FAB_STYLE } from '@/components/util/StyledFab';
import { TranslationKey } from '@/typings.ts';
2023-12-30 04:04:59 +01:00
import { Menu } from '@/components/manga/Menu.tsx';
2022-11-09 18:09:15 +01:00
2023-02-06 10:06:33 +01:00
interface SelectionFABProps {
2023-12-30 14:26:50 +01:00
children: (handleClose: () => void, setHideMenu: (hide: boolean) => void) => JSX.Element;
selectedItemsCount: number;
title: TranslationKey;
2022-11-09 18:09:15 +01:00
}
2023-12-25 21:37:45 +01:00
const FabContainer = styled(Box)(({ theme }) => ({
...DEFAULT_FAB_STYLE,
height: `calc(${DEFAULT_FAB_STYLE.height} + 1)`,
paddingTop: '8px',
zIndex: 1, // the "Checkbox" (MUI) component of the "ChapterCard" has z-index 1, which causes it to take over the mouse events
[theme.breakpoints.down('md')]: {
marginBottom: '64px',
},
}));
export const SelectionFAB: React.FC<SelectionFABProps> = ({ children, selectedItemsCount, title }) => {
2023-03-23 13:59:32 +01:00
const { t } = useTranslation();
2022-11-09 18:09:15 +01:00
return (
2023-12-30 04:04:59 +01:00
<PopupState variant="popover" popupId="selection-fab-menu">
{(popupState) => (
<>
<FabContainer {...bindTrigger(popupState)}>
<Fab variant="extended" color="primary" id="selectionMenuButton">
{`${selectedItemsCount} ${t(title, { count: selectedItemsCount })}`}
<MoreHoriz sx={{ ml: 1 }} />
</Fab>
</FabContainer>
<Menu
{...bindMenu(popupState)}
id="selectionMenu"
anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
transformOrigin={{ horizontal: 'right', vertical: 'bottom' }}
MenuListProps={{
'aria-labelledby': 'selectionMenuButton',
}}
>
2023-12-30 14:26:50 +01:00
{(onClose, setHideMenu) => children(onClose, setHideMenu)}
2023-12-30 04:04:59 +01:00
</Menu>
</>
)}
</PopupState>
2022-11-09 18:09:15 +01:00
);
};