124 lines
4.8 KiB
JavaScript
124 lines
4.8 KiB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
const _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "hasFocus", "tabIndex", "hideDescendantCount"];
|
|
import * as React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import composeClasses from '@mui/utils/composeClasses';
|
|
import { useGridSelector } from "../../hooks/utils/useGridSelector.mjs";
|
|
import { gridRowMaximumTreeDepthSelector } from "../../hooks/features/rows/gridRowsSelector.mjs";
|
|
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
|
|
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
|
|
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.mjs";
|
|
import { isAutogeneratedRowNode } from "../../hooks/features/rows/gridRowsUtils.mjs";
|
|
import { GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from "../../internals/constants.mjs";
|
|
import { GridFooterCell } from "./GridFooterCell.mjs";
|
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
const useUtilityClasses = ownerState => {
|
|
const {
|
|
classes
|
|
} = ownerState;
|
|
const slots = {
|
|
root: ['booleanCell']
|
|
};
|
|
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
};
|
|
function GridBooleanCellRaw(props) {
|
|
const {
|
|
value,
|
|
rowNode
|
|
} = props,
|
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
const apiRef = useGridApiContext();
|
|
const rootProps = useGridRootProps();
|
|
const ownerState = {
|
|
classes: rootProps.classes
|
|
};
|
|
const classes = useUtilityClasses(ownerState);
|
|
const maxDepth = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector);
|
|
const isServerSideRowGroupingRow =
|
|
// @ts-expect-error - Access tree data prop
|
|
maxDepth > 0 && rowNode.type === 'group' && rootProps.treeData === false;
|
|
const Icon = React.useMemo(() => value ? rootProps.slots.booleanCellTrueIcon : rootProps.slots.booleanCellFalseIcon, [rootProps.slots.booleanCellFalseIcon, rootProps.slots.booleanCellTrueIcon, value]);
|
|
if (isServerSideRowGroupingRow && value === undefined) {
|
|
return null;
|
|
}
|
|
return /*#__PURE__*/_jsx(Icon, _extends({
|
|
fontSize: "small",
|
|
className: classes.root,
|
|
titleAccess: apiRef.current.getLocaleText(value ? 'booleanCellTrueLabel' : 'booleanCellFalseLabel'),
|
|
"data-value": Boolean(value)
|
|
}, other));
|
|
}
|
|
process.env.NODE_ENV !== "production" ? GridBooleanCellRaw.propTypes /* remove-proptypes */ = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
/**
|
|
* GridApi that let you manipulate the grid.
|
|
*/
|
|
api: PropTypes.object.isRequired,
|
|
/**
|
|
* The mode of the cell.
|
|
*/
|
|
cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
|
|
/**
|
|
* The column of the row that the current cell belongs to.
|
|
*/
|
|
colDef: PropTypes.object.isRequired,
|
|
/**
|
|
* The column field of the cell that triggered the event.
|
|
*/
|
|
field: PropTypes.string.isRequired,
|
|
/**
|
|
* The cell value formatted with the column valueFormatter.
|
|
*/
|
|
formattedValue: PropTypes.any,
|
|
/**
|
|
* If true, the cell is the active element.
|
|
*/
|
|
hasFocus: PropTypes.bool.isRequired,
|
|
hideDescendantCount: PropTypes.bool,
|
|
/**
|
|
* The grid row id.
|
|
*/
|
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
/**
|
|
* If true, the cell is editable.
|
|
*/
|
|
isEditable: PropTypes.bool,
|
|
/**
|
|
* The row model of the row that the current cell belongs to.
|
|
*/
|
|
row: PropTypes.any.isRequired,
|
|
/**
|
|
* The node of the row that the current cell belongs to.
|
|
*/
|
|
rowNode: PropTypes.object.isRequired,
|
|
/**
|
|
* the tabIndex value.
|
|
*/
|
|
tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
|
|
/**
|
|
* The cell value.
|
|
* If the column has `valueGetter`, use `params.row` to directly access the fields.
|
|
*/
|
|
value: PropTypes.any
|
|
} : void 0;
|
|
const GridBooleanCell = /*#__PURE__*/React.memo(GridBooleanCellRaw);
|
|
if (process.env.NODE_ENV !== "production") GridBooleanCell.displayName = "GridBooleanCell";
|
|
export { GridBooleanCell };
|
|
export const renderBooleanCell = params => {
|
|
if (params.field !== GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD && isAutogeneratedRowNode(params.rowNode)) {
|
|
const aggregationMetaData = params.aggregation;
|
|
if (!aggregationMetaData) {
|
|
return '';
|
|
}
|
|
if (aggregationMetaData.position === 'footer') {
|
|
return /*#__PURE__*/_jsx(GridFooterCell, _extends({}, params));
|
|
}
|
|
return params.formattedValue;
|
|
}
|
|
return /*#__PURE__*/_jsx(GridBooleanCell, _extends({}, params));
|
|
};
|
|
if (process.env.NODE_ENV !== "production") renderBooleanCell.displayName = "renderBooleanCell"; |