import { ReactNode } from "react"; import { Menu, MenuButton, MenuList, MenuItem, IconButton, } from "@chakra-ui/react"; import { FiMoreVertical } from "react-icons/fi"; // A row action is a single menu item for the actions column export interface RowAction { title: string; onClick: (e: any, data: any) => any; show?: (data: any) => any; disabled?: (data: any) => any; icon?: any; } interface RowActionsProps { /** * Row Data */ data: any; /** * Actions */ actions: RowAction[]; } function RowActionsMenu({ data, actions }: RowActionsProps) { const elms: ReactNode[] = []; actions.map((action) => { if (!action.show || action.show(data)) { const disabled = action.disabled && action.disabled(data); elms.push( { action.onClick(e, data); }}> {action.title} , ); } return null; }); if (!elms.length) { return null; } return (
} variant="outline" /> {elms}
); } export { RowActionsMenu };