/* * 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 { useTranslation } from 'react-i18next'; import React, { TouchEvent, useMemo } from 'react'; import { Button, Tooltip } from '@mui/material'; import Checkbox from '@mui/material/Checkbox'; import IconButton from '@mui/material/IconButton'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import { PopupState } from 'material-ui-popup-state/es/hooks'; import { bindTrigger } from 'material-ui-popup-state'; import { isMobile } from 'react-device-detect'; import { SelectableCollectionReturnType } from '@/components/collection/useSelectableCollection.ts'; import { TManga } from '@/typings.ts'; export const MangaOptionButton = ({ id, selected, handleSelection, asCheckbox = false, popupState, }: { id: number; selected?: boolean | null; handleSelection?: SelectableCollectionReturnType['handleSelection']; asCheckbox?: boolean; popupState: PopupState; }) => { const { t } = useTranslation(); const bindTriggerProps = useMemo(() => bindTrigger(popupState), [popupState]); const preventDefaultAction = (e: React.BaseSyntheticEvent) => { e.stopPropagation(); e.preventDefault(); }; const handleSelectionChange = (e: React.BaseSyntheticEvent, isSelected: boolean) => { preventDefaultAction(e); handleSelection?.(id, isSelected); }; const handleClick = (e: React.BaseSyntheticEvent) => { preventDefaultAction(e); bindTriggerProps.onClick(e as any); }; const handleTouchStart = (e: React.BaseSyntheticEvent) => { preventDefaultAction(e); bindTriggerProps.onTouchStart(e as TouchEvent); }; if (!handleSelection) { return null; } const isSelected = selected !== null; if (isSelected) { if (!asCheckbox) { return null; } return ( ); } if (asCheckbox) { return ( ); } return ( ); };