UNPKG

@react-awesome-query-builder/mui

Version:
48 lines 1.32 kB
import React, { memo } from "react"; import Button from "@mui/material/Button"; import IconButton from "@mui/material/IconButton"; var hideLabelsFor = { "addSubRuleSimple": true, // "addSubRule": true, // "addSubGroup": true, "delGroup": true, "delRuleGroup": true, "delRule": true }; var typeToColor = { "addRule": "primary", "addGroup": "primary", "delGroup": "secondary", "delRuleGroup": "secondary", "delRule": "secondary" }; export default /*#__PURE__*/memo(function (props) { var type = props.type, label = props.label, onClick = props.onClick, readonly = props.readonly, renderIcon = props.renderIcon; var iconProps = { type: type, readonly: readonly }; var icon = renderIcon === null || renderIcon === void 0 ? void 0 : renderIcon(iconProps); if (!label || hideLabelsFor[type]) { // For icons, use the label as aria-label for accessibility return /*#__PURE__*/React.createElement(IconButton, { size: "small", disabled: readonly, onClick: onClick, color: typeToColor[type], "aria-label": label }, icon); } else { return /*#__PURE__*/React.createElement(Button, { size: "small", disabled: readonly, onClick: onClick, color: typeToColor[type], startIcon: icon }, label); } });