Files
AFFiNE-Mirror/packages/app/src/ui/menu/menu-item.tsx
T
2022-12-05 22:20:21 +08:00

36 lines
819 B
TypeScript

import {
cloneElement,
forwardRef,
HTMLAttributes,
PropsWithChildren,
ReactElement,
} from 'react';
import { StyledMenuItem, StyledArrow } from './styles';
export type IconMenuProps = PropsWithChildren<{
isDir?: boolean;
icon?: ReactElement;
}> &
HTMLAttributes<HTMLButtonElement>;
export const MenuItem = forwardRef<HTMLButtonElement, IconMenuProps>(
({ isDir = false, icon, children, ...props }, ref) => {
return (
<StyledMenuItem ref={ref} {...props}>
{icon &&
cloneElement(icon, {
width: 16,
height: 16,
style: {
marginRight: 14,
},
})}
{children}
{isDir ? <StyledArrow /> : null}
</StyledMenuItem>
);
}
);
MenuItem.displayName = 'MenuItem';
export default MenuItem;