Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Change default loading overlay variants #15504

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Box from '@mui/material/Box';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function LoadingOverlay() {
export default function LoadingOverlayCircularProgress() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 6,
Expand All @@ -12,7 +12,16 @@ export default function LoadingOverlay() {

return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGrid {...data} loading />
<DataGrid
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'circular-progress',
noRowsVariant: 'circular-progress',
},
}}
/>
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Box from '@mui/material/Box';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function LoadingOverlay() {
export default function LoadingOverlayCircularProgress() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 6,
Expand All @@ -12,7 +12,16 @@ export default function LoadingOverlay() {

return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGrid {...data} loading />
<DataGrid
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'circular-progress',
noRowsVariant: 'circular-progress',
},
}}
/>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DataGrid
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'circular-progress',
noRowsVariant: 'circular-progress',
},
}}
/>
9 changes: 2 additions & 7 deletions docs/data/data-grid/overlays/LoadingOverlaySkeleton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { useDemoData } from '@mui/x-data-grid-generator';
import { DataGridPro } from '@mui/x-data-grid-pro';
import { DataGrid } from '@mui/x-data-grid';

export default function LoadingOverlaySkeleton() {
const { data } = useDemoData({
Expand All @@ -12,7 +12,7 @@ export default function LoadingOverlaySkeleton() {

return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGridPro
<DataGrid
{...data}
loading
slotProps={{
Expand All @@ -21,11 +21,6 @@ export default function LoadingOverlaySkeleton() {
noRowsVariant: 'skeleton',
},
}}
initialState={{
pinnedColumns: {
left: ['desk'],
},
}}
/>
</Box>
);
Expand Down
9 changes: 2 additions & 7 deletions docs/data/data-grid/overlays/LoadingOverlaySkeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { useDemoData } from '@mui/x-data-grid-generator';
import { DataGridPro } from '@mui/x-data-grid-pro';
import { DataGrid } from '@mui/x-data-grid';

export default function LoadingOverlaySkeleton() {
const { data } = useDemoData({
Expand All @@ -12,7 +12,7 @@ export default function LoadingOverlaySkeleton() {

return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGridPro
<DataGrid
{...data}
loading
slotProps={{
Expand All @@ -21,11 +21,6 @@ export default function LoadingOverlaySkeleton() {
noRowsVariant: 'skeleton',
},
}}
initialState={{
pinnedColumns: {
left: ['desk'],
},
}}
/>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<DataGridPro
<DataGrid
{...data}
loading
slotProps={{
Expand All @@ -7,9 +7,4 @@
noRowsVariant: 'skeleton',
},
}}
initialState={{
pinnedColumns: {
left: ['desk'],
},
}}
/>
20 changes: 10 additions & 10 deletions docs/data/data-grid/overlays/overlays.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went to the docs to see this change in practice, and realized that most of our demos aren't using the loading state and show no rows overlay instead 🫠
E.g.: https://deploy-preview-15504--material-ui-x.netlify.app/x/react-data-grid/sorting/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #15512

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ To display a loading overlay and signify that the Data Grid is in a loading stat

The Data Grid supports 3 loading overlay variants out of the box:

- `circular-progress` (default): a circular loading spinner.
- `linear-progress`: an indeterminate linear progress bar.
- `skeleton`: an animated placeholder of the Data Grid.
- `linear-progress`: an indeterminate linear progress bar.
- `circular-progress`: a circular loading spinner.

The type of loading overlay to display can be set via `slotProps.loadingOverlay` for the following two props:

- `variant`: when `loading` and there are rows in the table.
- `noRowsVariant`: when `loading` and there are not any rows in the table.
- `variant` (default: `linear-progress`): when `loading` and there are rows in the table.
- `noRowsVariant` (default: `skeleton`): when `loading` and there are not any rows in the table.

```tsx
<DataGrid
Expand All @@ -30,23 +30,23 @@ The type of loading overlay to display can be set via `slotProps.loadingOverlay`
/>
```

### Circular progress
### Skeleton

A circular loading spinner, the default loading overlay.
An animated placeholder of the Data Grid.

{{"demo": "LoadingOverlay.js", "bg": "inline"}}
{{"demo": "LoadingOverlaySkeleton.js", "bg": "inline"}}

### Linear progress

An indeterminate linear progress bar.

{{"demo": "LoadingOverlayLinearProgress.js", "bg": "inline"}}

### Skeleton
### Circular progress

An animated placeholder of the Data Grid.
A circular loading spinner.

{{"demo": "LoadingOverlaySkeleton.js", "bg": "inline"}}
{{"demo": "LoadingOverlayCircularProgress.js", "bg": "inline"}}

### Custom component

Expand Down
15 changes: 5 additions & 10 deletions packages/x-data-grid/src/components/GridLoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export type GridLoadingOverlayVariant = 'circular-progress' | 'linear-progress'
export interface GridLoadingOverlayProps extends GridOverlayProps {
/**
* The variant of the overlay.
* @default 'circular-progress'
* @default 'linear-progress'
*/
variant?: GridLoadingOverlayVariant;
/**
* The variant of the overlay when no rows are displayed.
* @default 'circular-progress'
* @default 'skeleton'
*/
noRowsVariant?: GridLoadingOverlayVariant;
}
Expand Down Expand Up @@ -45,12 +45,7 @@ const LOADING_VARIANTS: Record<

const GridLoadingOverlay = React.forwardRef<HTMLDivElement, GridLoadingOverlayProps>(
function GridLoadingOverlay(props, ref) {
const {
variant = 'circular-progress',
noRowsVariant = 'circular-progress',
style,
...other
} = props;
const { variant = 'linear-progress', noRowsVariant = 'skeleton', style, ...other } = props;
const apiRef = useGridApiContext();
const rowsCount = useGridSelector(apiRef, gridRowCountSelector);
const activeVariant = LOADING_VARIANTS[rowsCount === 0 ? noRowsVariant : variant];
Expand All @@ -70,7 +65,7 @@ GridLoadingOverlay.propTypes = {
// ----------------------------------------------------------------------
/**
* The variant of the overlay when no rows are displayed.
* @default 'circular-progress'
* @default 'skeleton'
*/
noRowsVariant: PropTypes.oneOf(['circular-progress', 'linear-progress', 'skeleton']),
sx: PropTypes.oneOfType([
Expand All @@ -80,7 +75,7 @@ GridLoadingOverlay.propTypes = {
]),
/**
* The variant of the overlay.
* @default 'circular-progress'
* @default 'linear-progress'
*/
variant: PropTypes.oneOf(['circular-progress', 'linear-progress', 'skeleton']),
} as any;
Expand Down
33 changes: 33 additions & 0 deletions test/regressions/data-grid/DataGridPinnedColumnsSkeletonLoading.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to ask for this demo for visual regression testing 👍🏻

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { useDemoData } from '@mui/x-data-grid-generator';
import { DataGridPro } from '@mui/x-data-grid-pro';

export default function DataGridPinnedColumnsSkeletonLoading() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 100,
maxColumns: 9,
});

return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGridPro
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'skeleton',
noRowsVariant: 'skeleton',
},
}}
initialState={{
pinnedColumns: {
left: ['desk'],
right: ['status'],
},
}}
/>
</Box>
);
}
Loading