/* eslint-disable no-unused-vars */ import * as React from "react"; import PropTypes from "prop-types"; import Icon from "@mui/material/Icon"; import IconButton from "@mui/material/IconButton"; import Tooltip from "@mui/material/Tooltip"; /* eslint-enable no-unused-vars */ class MTableAction extends React.Component { render() { let action = this.props.action; if (typeof action === "function") { action = action(this.props.data); if (!action) { return null; } } if (action.action) { action = action.action(this.props.data); if (!action) { return null; } } if (action.hidden) { return null; } const disabled = action.disabled || this.props.disabled; const handleOnClick = (event) => { if (action.onClick) { action.onClick(event, this.props.data); event.stopPropagation(); } }; const icon = typeof action.icon === "string" ? ( {action.icon} ) : typeof action.icon === "function" ? ( action.icon({ ...action.iconProps, disabled: disabled }) ) : ( ); const button = ( {icon} ); if (action.tooltip) { // fix for issue #1049 // https://github.com/mbrn/material-table/issues/1049 return disabled ? ( {button} ) : ( {button} ); } else { return button; } } } MTableAction.defaultProps = { action: {}, data: {}, }; MTableAction.propTypes = { action: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired, data: PropTypes.oneOfType([ PropTypes.object, PropTypes.arrayOf(PropTypes.object), ]), disabled: PropTypes.bool, size: PropTypes.string, }; export default MTableAction;