UNPKG

@mui/x-data-grid

Version:

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

149 lines (130 loc) 4.8 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["id", "value", "formattedValue", "api", "field", "row", "rowNode", "colDef", "cellMode", "isEditable", "hasFocus", "tabIndex", "getValue"]; import * as React from 'react'; import PropTypes from 'prop-types'; import { unstable_composeClasses as composeClasses } from '@mui/material'; import { getDataGridUtilityClass } from '../../constants/gridClasses'; import { useGridRootProps } from '../../hooks/utils/useGridRootProps'; import { useGridApiContext } from '../../hooks/utils/useGridApiContext'; import { jsx as _jsx } from "react/jsx-runtime"; var useUtilityClasses = function useUtilityClasses(ownerState) { var classes = ownerState.classes; var slots = { root: ['booleanCell'] }; return composeClasses(slots, getDataGridUtilityClass, classes); }; var GridBooleanCellRaw = function GridBooleanCellRaw(props) { var id = props.id, value = props.value, formattedValue = props.formattedValue, api = props.api, field = props.field, row = props.row, rowNode = props.rowNode, colDef = props.colDef, cellMode = props.cellMode, isEditable = props.isEditable, hasFocus = props.hasFocus, tabIndex = props.tabIndex, getValue = props.getValue, other = _objectWithoutProperties(props, _excluded); var apiRef = useGridApiContext(); var rootProps = useGridRootProps(); var ownerState = { classes: rootProps.classes }; var classes = useUtilityClasses(ownerState); var Icon = React.useMemo(function () { return value ? rootProps.components.BooleanCellTrueIcon : rootProps.components.BooleanCellFalseIcon; }, [rootProps.components.BooleanCellFalseIcon, rootProps.components.BooleanCellTrueIcon, value]); 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 = { // ----------------------------- 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. * @deprecated Use the `apiRef` returned by `useGridApiContext` or `useGridApiRef` (only available in `@mui/x-data-grid-pro`) */ api: PropTypes.any.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, /** * A ref allowing to set imperative focus. * It can be passed to the element that should receive focus. * @ignore - do not document. */ focusElementRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.shape({ focus: PropTypes.func.isRequired }) })]), /** * The cell value formatted with the column valueFormatter. */ formattedValue: PropTypes.any, /** * Get the cell value of a row and field. * @param {GridRowId} id The row id. * @param {string} field The field. * @returns {any} The cell value. * @deprecated Use `params.row` to directly access the fields you want instead. */ getValue: PropTypes.func.isRequired, /** * If true, the cell is the active element. */ hasFocus: PropTypes.bool.isRequired, /** * 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.object.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; var GridBooleanCell = /*#__PURE__*/React.memo(GridBooleanCellRaw); export { GridBooleanCell }; export var renderBooleanCell = function renderBooleanCell(params) { if (params.rowNode.isAutoGenerated) { return ''; } return /*#__PURE__*/_jsx(GridBooleanCell, _extends({}, params)); };