Skip to content

Commit

Permalink
return back GridOverlays file to persist changes history
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii committed Nov 25, 2024
1 parent aeab112 commit d877a2e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 106 deletions.
117 changes: 117 additions & 0 deletions packages/x-data-grid/src/components/base/GridOverlays.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
99 changes: 2 additions & 97 deletions packages/x-data-grid/src/components/containers/GridOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,20 @@ import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { Theme, SxProps, styled } from '@mui/system';
import type { DataGridProcessedProps } from '../../models/props/DataGridProps';
import { minimalContentHeight } from '../../hooks/features/rows/gridRowsUtils';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { gridDimensionsSelector } from '../../hooks/features/dimensions';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { GridSlotsComponent } from '../../models';

export type GridOverlayProps = React.HTMLAttributes<HTMLDivElement> & {
sx?: SxProps<Theme>;
};

type GridLoadingOverlayVariant = 'circular-progress' | 'linear-progress' | 'skeleton';

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 = DataGridProcessedProps;

const useUtilityClasses = (ownerState: OwnerState) => {
const { classes } = ownerState;

const slots = {
root: ['overlay'],
wrapperRoot: ['overlayWrapper'],
wrapperInner: ['overlayWrapperInner'],
};

return composeClasses(slots, getDataGridUtilityClass, classes);
Expand All @@ -88,49 +37,14 @@ const GridOverlayRoot = styled('div', {
backgroundColor: 'var(--unstable_DataGrid-overlayBackground)',
});

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(rootProps);

return (
<GridOverlayWrapperRoot
className={clsx(classes.wrapperRoot)}
{...props}
right={dimensions.columnsTotalWidth - dimensions.viewportOuterSize.width}
>
<GridOverlayWrapperInner
className={clsx(classes.wrapperInner)}
style={{
height,
width: dimensions.viewportOuterSize.width,
}}
{...props}
/>
</GridOverlayWrapperRoot>
);
}
const GridOverlay = React.forwardRef<HTMLDivElement, GridOverlayProps>(function GridOverlay(
props: GridOverlayProps,
ref,
) {
const { className, ...other } = props;
const rootProps = useGridRootProps();
const classes = useUtilityClasses(rootProps);

return (
<GridOverlayRoot
ref={ref}
Expand All @@ -153,13 +67,4 @@ GridOverlay.propTypes = {
]),
} as any;

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;

export { GridOverlay, GridOverlayWrapper };
export { GridOverlay };
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import { useGridRootProps } from '../../utils/useGridRootProps';
import { gridExpandedRowCountSelector } from '../filter';
import { gridRowCountSelector, gridRowsLoadingSelector } from '../rows';
import { GridLoadingOverlayVariant } from '../../../components/GridLoadingOverlay';
import { GridSlotsComponent } from '../../../models/gridSlotsComponent';
import { GridOverlayWrapper } from '../../../components/containers';

export type GridOverlayType =
| keyof Pick<GridSlotsComponent, 'noRowsOverlay' | 'noResultsOverlay' | 'loadingOverlay'>
| null;
import { GridOverlayWrapper } from '../../../components/base/GridOverlays';
import type { GridOverlayType } from '../../../components/base/GridOverlays';

/**
* Uses the grid state to determine which overlay to display.
Expand Down
1 change: 0 additions & 1 deletion scripts/x-data-grid-premium.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@
{ "name": "gridNumberComparator", "kind": "Variable" },
{ "name": "GridOverlay", "kind": "Variable" },
{ "name": "GridOverlayProps", "kind": "TypeAlias" },
{ "name": "GridOverlayWrapper", "kind": "Function" },
{ "name": "gridPageCountSelector", "kind": "Variable" },
{ "name": "gridPageSelector", "kind": "Variable" },
{ "name": "gridPageSizeSelector", "kind": "Variable" },
Expand Down
1 change: 0 additions & 1 deletion scripts/x-data-grid-pro.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@
{ "name": "gridNumberComparator", "kind": "Variable" },
{ "name": "GridOverlay", "kind": "Variable" },
{ "name": "GridOverlayProps", "kind": "TypeAlias" },
{ "name": "GridOverlayWrapper", "kind": "Function" },
{ "name": "gridPageCountSelector", "kind": "Variable" },
{ "name": "gridPageSelector", "kind": "Variable" },
{ "name": "gridPageSizeSelector", "kind": "Variable" },
Expand Down
1 change: 0 additions & 1 deletion scripts/x-data-grid.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@
{ "name": "gridNumberComparator", "kind": "Variable" },
{ "name": "GridOverlay", "kind": "Variable" },
{ "name": "GridOverlayProps", "kind": "TypeAlias" },
{ "name": "GridOverlayWrapper", "kind": "Function" },
{ "name": "gridPageCountSelector", "kind": "Variable" },
{ "name": "gridPageSelector", "kind": "Variable" },
{ "name": "gridPageSizeSelector", "kind": "Variable" },
Expand Down

0 comments on commit d877a2e

Please sign in to comment.