UNPKG

@mui/x-data-grid

Version:

The community edition of the data grid component (MUI X).

121 lines (120 loc) 5.45 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.renderBooleanCell = exports.GridBooleanCell = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _utils = require("@mui/utils"); var _gridClasses = require("../../constants/gridClasses"); var _useGridRootProps = require("../../hooks/utils/useGridRootProps"); var _useGridApiContext = require("../../hooks/utils/useGridApiContext"); var _gridRowsUtils = require("../../hooks/features/rows/gridRowsUtils"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "hasFocus", "tabIndex"]; function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const useUtilityClasses = ownerState => { const { classes } = ownerState; const slots = { root: ['booleanCell'] }; return (0, _utils.unstable_composeClasses)(slots, _gridClasses.getDataGridUtilityClass, classes); }; function GridBooleanCellRaw(props) { const { value } = props, other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded); const apiRef = (0, _useGridApiContext.useGridApiContext)(); const rootProps = (0, _useGridRootProps.useGridRootProps)(); const ownerState = { classes: rootProps.classes }; const classes = useUtilityClasses(ownerState); const Icon = React.useMemo(() => value ? rootProps.slots.booleanCellTrueIcon : rootProps.slots.booleanCellFalseIcon, [rootProps.slots.booleanCellFalseIcon, rootProps.slots.booleanCellTrueIcon, value]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, (0, _extends2.default)({ fontSize: "small", className: classes.root, titleAccess: apiRef.current.getLocaleText(value ? 'booleanCellTrueLabel' : 'booleanCellFalseLabel'), "data-value": Boolean(value) }, other)); } process.env.NODE_ENV !== "production" ? GridBooleanCellRaw.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- /** * GridApi that let you manipulate the grid. */ api: _propTypes.default.object.isRequired, /** * The mode of the cell. */ cellMode: _propTypes.default.oneOf(['edit', 'view']).isRequired, /** * The column of the row that the current cell belongs to. */ colDef: _propTypes.default.object.isRequired, /** * The column field of the cell that triggered the event. */ field: _propTypes.default.string.isRequired, /** * A ref allowing to set imperative focus. * It can be passed to the element that should receive focus. * @ignore - do not document. */ focusElementRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({ current: _propTypes.default.shape({ focus: _propTypes.default.func.isRequired }) })]), /** * The cell value formatted with the column valueFormatter. */ formattedValue: _propTypes.default.any, /** * If true, the cell is the active element. */ hasFocus: _propTypes.default.bool.isRequired, /** * The grid row id. */ id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired, /** * If true, the cell is editable. */ isEditable: _propTypes.default.bool, /** * The row model of the row that the current cell belongs to. */ row: _propTypes.default.any.isRequired, /** * The node of the row that the current cell belongs to. */ rowNode: _propTypes.default.object.isRequired, /** * the tabIndex value. */ tabIndex: _propTypes.default.oneOf([-1, 0]).isRequired, /** * The cell value. * If the column has `valueGetter`, use `params.row` to directly access the fields. */ value: _propTypes.default.any } : void 0; const GridBooleanCell = exports.GridBooleanCell = /*#__PURE__*/React.memo(GridBooleanCellRaw); const renderBooleanCell = params => { if ((0, _gridRowsUtils.isAutoGeneratedRow)(params.rowNode)) { return ''; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridBooleanCell, (0, _extends2.default)({}, params)); }; exports.renderBooleanCell = renderBooleanCell;