File size: 2,186 Bytes
4e1096a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import clsx from 'clsx';
import React from 'react';
import { AnnotationToolType } from '@/types/annotator';
import { useTranslation } from '@/hooks/useTranslation';
import { annotationToolQuickActions } from './AnnotationTools';
import { eventDispatcher } from '@/utils/event';
import MenuItem from '@/components/MenuItem';
import Menu from '@/components/Menu';
interface QuickActionMenuProps {
menuClassName?: string;
selectedAction?: AnnotationToolType | null;
onActionSelect: (action: AnnotationToolType) => void;
setIsDropdownOpen?: (open: boolean) => void;
}
const QuickActionMenu: React.FC<QuickActionMenuProps> = ({
menuClassName,
selectedAction,
onActionSelect,
setIsDropdownOpen,
}) => {
const _ = useTranslation();
const handleActionClick = (action: AnnotationToolType) => {
onActionSelect(action);
if (selectedAction === action) {
eventDispatcher.dispatch('toast', {
type: 'info',
timeout: 2000,
message: _('Instant {{action}} Disabled', {
action: _(
annotationToolQuickActions.find((btn) => btn.type === action)?.label || _('Annotation'),
),
}),
});
} else {
eventDispatcher.dispatch('toast', {
type: 'info',
timeout: 2000,
message: _(annotationToolQuickActions.find((btn) => btn.type === action)?.tooltip || ''),
});
}
setIsDropdownOpen?.(false);
};
return (
<Menu
className={clsx(
'annotation-quick-action-menu dropdown-content z-20 mt-1 border',
'bgcolor-base-200 shadow-2xl',
menuClassName,
)}
style={{
maxWidth: `${window.innerWidth - 40}px`,
}}
onCancel={() => setIsDropdownOpen?.(false)}
>
{annotationToolQuickActions.map((button) => (
<MenuItem
key={button.type}
label={_('Instant {{action}}', { action: _(button.label) })}
tooltip={_(button.tooltip)}
buttonClass={selectedAction === button.type ? 'bg-base-300/85' : ''}
Icon={button.Icon}
onClick={() => handleActionClick(button.type)}
/>
))}
</Menu>
);
};
export default QuickActionMenu;
|