Download material-table/src/components/m-table-action.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/material-table/src/components/m-table-action.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/material-table/src/components/m-table-action.js
-
curl -L -o m-table-action.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/material-table/src/components/m-table-action.js
2.1 kB
| /* 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" ? ( | |
| <Icon {...action.iconProps}>{action.icon}</Icon> | |
| ) : typeof action.icon === "function" ? ( | |
| action.icon({ ...action.iconProps, disabled: disabled }) | |
| ) : ( | |
| <action.icon /> | |
| ); | |
| const button = ( | |
| <IconButton | |
| size={this.props.size} | |
| color="inherit" | |
| disabled={disabled} | |
| onClick={handleOnClick} | |
| > | |
| {icon} | |
| </IconButton> | |
| ); | |
| if (action.tooltip) { | |
| // fix for issue #1049 | |
| // https://github.com/mbrn/material-table/issues/1049 | |
| return disabled ? ( | |
| <Tooltip title={action.tooltip}> | |
| <span>{button}</span> | |
| </Tooltip> | |
| ) : ( | |
| <Tooltip title={action.tooltip}>{button}</Tooltip> | |
| ); | |
| } 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; | |