UNPKG

@mui/x-data-grid-pro

Version:

The Pro plan edition of the MUI X Data Grid components.

129 lines (128 loc) 4.93 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.GridDetailPanelToggleCell = GridDetailPanelToggleCell; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses")); var _xDataGrid = require("@mui/x-data-grid"); var _internals = require("@mui/x-data-grid/internals"); var _useGridRootProps = require("../hooks/utils/useGridRootProps"); var _useGridApiContext = require("../hooks/utils/useGridApiContext"); var _gridDetailPanelSelector = require("../hooks/features/detailPanel/gridDetailPanelSelector"); var _jsxRuntime = require("react/jsx-runtime"); const useUtilityClasses = ownerState => { const { classes, isExpanded } = ownerState; const slots = { root: ['detailPanelToggleCell', isExpanded && 'detailPanelToggleCell--expanded'] }; return (0, _composeClasses.default)(slots, _xDataGrid.getDataGridUtilityClass, classes); }; const isExpandedSelector = (0, _internals.createSelector)(_gridDetailPanelSelector.gridDetailPanelExpandedRowIdsSelector, (expandedRowIds, rowId) => { return expandedRowIds.has(rowId); }); function GridDetailPanelToggleCell(props) { const { id, row, api } = props; const rowId = api.getRowId(row); const isExpanded = (0, _xDataGrid.useGridSelector)({ current: api }, isExpandedSelector, rowId); const rootProps = (0, _useGridRootProps.useGridRootProps)(); const apiRef = (0, _useGridApiContext.useGridApiContext)(); const ownerState = { classes: rootProps.classes, isExpanded }; const classes = useUtilityClasses(ownerState); const contentCache = (0, _xDataGrid.useGridSelector)(apiRef, _gridDetailPanelSelector.gridDetailPanelExpandedRowsContentCacheSelector); const hasContent = /*#__PURE__*/React.isValidElement(contentCache[id]); const Icon = isExpanded ? rootProps.slots.detailPanelCollapseIcon : rootProps.slots.detailPanelExpandIcon; return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, (0, _extends2.default)({ size: "small", tabIndex: -1, disabled: !hasContent, className: classes.root, "aria-expanded": isExpanded, "aria-label": isExpanded ? apiRef.current.getLocaleText('collapseDetailPanel') : apiRef.current.getLocaleText('expandDetailPanel') }, rootProps.slotProps?.baseIconButton, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, { fontSize: "inherit" }) })); } process.env.NODE_ENV !== "production" ? GridDetailPanelToggleCell.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.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;