forked from akai/readest
c4d9652335
* fix(annotator): enhance PDF context menu for translation and improve touch handling * feat(annotator, shortcuts): add keyboard shortcuts for selection actions * feat(annotator): reposition popups on scroll to enhance user experience * feat(annotator): disable currently unsupported annotator functions for PDFs --------- Co-authored-by: Huang Xin <chrox.huang@gmail.com>
44 lines
968 B
TypeScript
44 lines
968 B
TypeScript
import clsx from 'clsx';
|
|
import React, { useState } from 'react';
|
|
|
|
interface PopupButtonProps {
|
|
showTooltip: boolean;
|
|
tooltipText: string;
|
|
disabled?: boolean;
|
|
Icon: React.ElementType;
|
|
onClick: () => void;
|
|
}
|
|
|
|
const PopupButton: React.FC<PopupButtonProps> = ({
|
|
showTooltip,
|
|
tooltipText,
|
|
disabled,
|
|
Icon,
|
|
onClick,
|
|
}) => {
|
|
const [buttonClicked, setButtonClicked] = useState(false);
|
|
const handleClick = () => {
|
|
setButtonClicked(true);
|
|
onClick();
|
|
};
|
|
return (
|
|
<div
|
|
className='lg:tooltip lg:tooltip-bottom'
|
|
data-tip={!buttonClicked && showTooltip ? tooltipText : null}
|
|
>
|
|
<button
|
|
onClick={handleClick}
|
|
className={clsx(
|
|
'flex h-8 min-h-8 w-8 items-center justify-center p-0',
|
|
disabled ? 'cursor-not-allowed opacity-50' : 'rounded-md hover:bg-gray-500',
|
|
)}
|
|
disabled={disabled}
|
|
>
|
|
<Icon />
|
|
</button>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PopupButton;
|