import { useShowDeleteConfirm } from '@/hooks/common-hooks'; import { DeleteOutlined, MoreOutlined } from '@ant-design/icons'; import { Dropdown, MenuProps, Space } from 'antd'; import { useTranslation } from 'react-i18next'; import React, { useMemo } from 'react'; import styles from './index.less'; interface IProps { deleteItem: () => Promise | void; iconFontSize?: number; iconFontColor?: string; items?: MenuProps['items']; height?: number; needsDeletionValidation?: boolean; } const OperateDropdown = ({ deleteItem, children, iconFontSize = 30, iconFontColor = 'gray', items: otherItems = [], height = 24, needsDeletionValidation = true, }: React.PropsWithChildren) => { const { t } = useTranslation(); const showDeleteConfirm = useShowDeleteConfirm(); const handleDelete = () => { if (needsDeletionValidation) { showDeleteConfirm({ onOk: deleteItem }); } else { deleteItem(); } }; const handleDropdownMenuClick: MenuProps['onClick'] = ({ domEvent, key }) => { domEvent.preventDefault(); domEvent.stopPropagation(); if (key === '1') { handleDelete(); } }; const items: MenuProps['items'] = useMemo(() => { return [ { key: '1', label: ( {t('common.delete')} ), }, ...otherItems, ]; }, [t, otherItems]); return ( {children || ( )} ); }; export default OperateDropdown;