-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathGridOverlays.tsx
117 lines (102 loc) · 4.29 KB
/
GridOverlays.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/system';
import composeClasses from '@mui/utils/composeClasses';
import clsx from 'clsx';
import { minimalContentHeight } from '../../hooks/features/rows/gridRowsUtils';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { gridDimensionsSelector } from '../../hooks/features/dimensions';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { GridLoadingOverlayVariant } from '../GridLoadingOverlay';
import { GridSlotsComponent } from '../../models';
export type GridOverlayType =
| keyof Pick<GridSlotsComponent, 'noRowsOverlay' | 'noResultsOverlay' | 'loadingOverlay'>
| null;
interface GridOverlaysProps {
overlayType: GridOverlayType;
loadingOverlayVariant: GridLoadingOverlayVariant | null;
}
interface GridOverlayWrapperRootProps extends GridOverlaysProps {
right: number;
}
const GridOverlayWrapperRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'OverlayWrapper',
shouldForwardProp: (prop) =>
prop !== 'overlayType' && prop !== 'loadingOverlayVariant' && prop !== 'right',
overridesResolver: (props, styles) => styles.overlayWrapper,
})<GridOverlayWrapperRootProps>(({ overlayType, loadingOverlayVariant, right }) =>
// Skeleton overlay should flow with the scroll container and not be sticky
loadingOverlayVariant !== 'skeleton'
? {
position: 'sticky', // To stay in place while scrolling
top: 'var(--DataGrid-headersTotalHeight)', // TODO: take pinned rows into account
left: 0,
right: `${right}px`,
width: 0, // To stay above the content instead of shifting it down
height: 0, // To stay above the content instead of shifting it down
zIndex:
overlayType === 'loadingOverlay'
? 5 // Should be above pinned columns, pinned rows, and detail panel
: 4, // Should be above pinned columns and detail panel
}
: {},
);
const GridOverlayWrapperInner = styled('div', {
name: 'MuiDataGrid',
slot: 'OverlayWrapperInner',
shouldForwardProp: (prop) => prop !== 'overlayType' && prop !== 'loadingOverlayVariant',
overridesResolver: (props, styles) => styles.overlayWrapperInner,
})({});
type OwnerState = { classes: DataGridProcessedProps['classes'] };
const useUtilityClasses = (ownerState: OwnerState) => {
const { classes } = ownerState;
const slots = {
root: ['overlayWrapper'],
inner: ['overlayWrapperInner'],
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
export function GridOverlayWrapper(props: React.PropsWithChildren<GridOverlaysProps>) {
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
let height: React.CSSProperties['height'] = Math.max(
dimensions.viewportOuterSize.height -
dimensions.topContainerHeight -
dimensions.bottomContainerHeight -
(dimensions.hasScrollX ? dimensions.scrollbarSize : 0),
0,
);
if (height === 0) {
height = minimalContentHeight;
}
const classes = useUtilityClasses({ ...props, classes: rootProps.classes });
return (
<GridOverlayWrapperRoot
className={clsx(classes.root)}
{...props}
right={dimensions.columnsTotalWidth - dimensions.viewportOuterSize.width}
>
<GridOverlayWrapperInner
className={clsx(classes.inner)}
style={{
height,
width: dimensions.viewportOuterSize.width,
}}
{...props}
/>
</GridOverlayWrapperRoot>
);
}
GridOverlayWrapper.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
loadingOverlayVariant: PropTypes.oneOf(['circular-progress', 'linear-progress', 'skeleton']),
overlayType: PropTypes.oneOf(['loadingOverlay', 'noResultsOverlay', 'noRowsOverlay']),
} as any;