mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-10 10:06:24 +01:00
43 lines
973 B
JavaScript
43 lines
973 B
JavaScript
import { Menu, MenuItem, SubMenu } from '@szhsin/react-menu';
|
|
import { cloneElement } from 'preact';
|
|
|
|
function MenuConfirm({
|
|
subMenu = false,
|
|
confirm = true,
|
|
confirmLabel,
|
|
menuItemClassName,
|
|
menuFooter,
|
|
...props
|
|
}) {
|
|
const { children, onClick, ...restProps } = props;
|
|
if (!confirm) {
|
|
if (subMenu) return <MenuItem {...props} />;
|
|
if (onClick) {
|
|
return cloneElement(children, {
|
|
onClick,
|
|
});
|
|
}
|
|
return children;
|
|
}
|
|
const Parent = subMenu ? SubMenu : Menu;
|
|
return (
|
|
<Parent
|
|
openTrigger="clickOnly"
|
|
direction="bottom"
|
|
overflow="auto"
|
|
gap={-8}
|
|
shift={8}
|
|
menuClassName="menu-emphasized"
|
|
{...restProps}
|
|
menuButton={subMenu ? undefined : children}
|
|
label={subMenu ? children : undefined}
|
|
>
|
|
<MenuItem className={menuItemClassName} onClick={onClick}>
|
|
{confirmLabel}
|
|
</MenuItem>
|
|
{menuFooter}
|
|
</Parent>
|
|
);
|
|
}
|
|
|
|
export default MenuConfirm;
|