UNPKG

@mui/x-data-grid-pro

Version:

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

57 lines (56 loc) 1.93 kB
'use client'; import * as React from 'react'; import { styled } from '@mui/material/styles'; import { gridRowNodeSelector } from '@mui/x-data-grid'; import { vars } from '@mui/x-data-grid/internals'; import { useResizeObserver } from '@mui/x-internals/useResizeObserver'; import { useGridRootProps } from "../hooks/utils/useGridRootProps.js"; import { useGridPrivateApiContext } from "../hooks/utils/useGridPrivateApiContext.js"; import { jsx as _jsx } from "react/jsx-runtime"; const DetailPanel = styled('div', { name: 'MuiDataGrid', slot: 'DetailPanel' })({ width: 'calc(var(--DataGrid-rowWidth) - var(--DataGrid-hasScrollY) * var(--DataGrid-scrollbarSize))', backgroundColor: vars.colors.background.base, overflow: 'auto' }); function GridDetailPanel(props) { const { rowId, height, className, children } = props; const apiRef = useGridPrivateApiContext(); const ref = React.useRef(null); const rootProps = useGridRootProps(); const ownerState = rootProps; const hasAutoHeight = height === 'auto'; const rowNode = gridRowNodeSelector(apiRef, rowId); React.useLayoutEffect(() => { if (hasAutoHeight && typeof ResizeObserver === 'undefined') { // Fallback for IE apiRef.current.storeDetailPanelHeight(rowId, ref.current.clientHeight); } }, [apiRef, hasAutoHeight, rowId]); useResizeObserver(ref, entries => { const [entry] = entries; const observedHeight = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height; apiRef.current.storeDetailPanelHeight(rowId, observedHeight); }, hasAutoHeight); if (rowNode?.type === 'skeletonRow') { return null; } return /*#__PURE__*/_jsx(DetailPanel, { ref: ref, ownerState: ownerState, role: "presentation", style: { height }, className: className, children: children }); } export { GridDetailPanel };