Skip to content

Commit

Permalink
[DataGrid] Add Skeleton loading overlay support (mui#13293)
Browse files Browse the repository at this point in the history
Signed-off-by: Kenan Yusuf <[email protected]>
Co-authored-by: Olivier Tassinari <[email protected]>
Co-authored-by: Andrew Cherniavskii <[email protected]>
  • Loading branch information
3 people authored and thomasmoon committed Sep 6, 2024
1 parent 8549d1b commit 1ab8174
Show file tree
Hide file tree
Showing 32 changed files with 913 additions and 96 deletions.
2 changes: 1 addition & 1 deletion docs/data/data-grid/overlays/LoadingOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function LoadingOverlay() {
});

return (
<Box sx={{ width: '100%', height: 340 }}>
<Box sx={{ width: '100%', height: 400 }}>
<DataGrid {...data} loading />
</Box>
);
Expand Down
2 changes: 1 addition & 1 deletion docs/data/data-grid/overlays/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function LoadingOverlay() {
});

return (
<Box sx={{ width: '100%', height: 340 }}>
<Box sx={{ width: '100%', height: 400 }}>
<DataGrid {...data} loading />
</Box>
);
Expand Down
60 changes: 58 additions & 2 deletions docs/data/data-grid/overlays/LoadingOverlayCustom.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,63 @@
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import LinearProgress from '@mui/material/LinearProgress';
import { useDemoData } from '@mui/x-data-grid-generator';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import CircularProgress from '@mui/material/CircularProgress';

const StyledGridOverlay = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
backgroundColor:
theme.palette.mode === 'light'
? 'rgba(255, 255, 255, 0.9)'
: 'rgba(18, 18, 18, 0.9)',
}));

function CircularProgressWithLabel(props) {
return (
<Box sx={{ position: 'relative', display: 'inline-flex' }}>
<CircularProgress variant="determinate" {...props} />
<Box
sx={{
position: 'absolute',
inset: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Typography variant="caption" component="div" color="text.primary">
{`${Math.round(props.value)}%`}
</Typography>
</Box>
</Box>
);
}

function CustomLoadingOverlay() {
const [progress, setProgress] = React.useState(10);

React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);

return (
<StyledGridOverlay>
<CircularProgressWithLabel value={progress} />
<Box sx={{ mt: 2 }}>Loading rows…</Box>
</StyledGridOverlay>
);
}

export default function LoadingOverlayCustom() {
const { data } = useDemoData({
Expand All @@ -14,7 +70,7 @@ export default function LoadingOverlayCustom() {
<div style={{ height: 400, width: '100%' }}>
<DataGrid
slots={{
loadingOverlay: LinearProgress,
loadingOverlay: CustomLoadingOverlay,
}}
loading
{...data}
Expand Down
68 changes: 65 additions & 3 deletions docs/data/data-grid/overlays/LoadingOverlayCustom.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,69 @@
import * as React from 'react';
import { DataGrid, GridSlots } from '@mui/x-data-grid';
import LinearProgress from '@mui/material/LinearProgress';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import CircularProgress, {
CircularProgressProps,
} from '@mui/material/CircularProgress';

const StyledGridOverlay = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
backgroundColor:
theme.palette.mode === 'light'
? 'rgba(255, 255, 255, 0.9)'
: 'rgba(18, 18, 18, 0.9)',
}));

function CircularProgressWithLabel(
props: CircularProgressProps & { value: number },
) {
return (
<Box sx={{ position: 'relative', display: 'inline-flex' }}>
<CircularProgress variant="determinate" {...props} />
<Box
sx={{
position: 'absolute',
inset: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Typography
variant="caption"
component="div"
color="text.primary"
>{`${Math.round(props.value)}%`}</Typography>
</Box>
</Box>
);
}

function CustomLoadingOverlay() {
const [progress, setProgress] = React.useState(10);

React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);

return (
<StyledGridOverlay>
<CircularProgressWithLabel value={progress} />
<Box sx={{ mt: 2 }}>Loading rows…</Box>
</StyledGridOverlay>
);
}

export default function LoadingOverlayCustom() {
const { data } = useDemoData({
Expand All @@ -14,7 +76,7 @@ export default function LoadingOverlayCustom() {
<div style={{ height: 400, width: '100%' }}>
<DataGrid
slots={{
loadingOverlay: LinearProgress as GridSlots['loadingOverlay'],
loadingOverlay: CustomLoadingOverlay,
}}
loading
{...data}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<DataGrid
slots={{
loadingOverlay: LinearProgress as GridSlots['loadingOverlay'],
loadingOverlay: CustomLoadingOverlay,
}}
loading
{...data}
Expand Down
27 changes: 27 additions & 0 deletions docs/data/data-grid/overlays/LoadingOverlayLinearProgress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { useDemoData } from '@mui/x-data-grid-generator';
import { DataGrid } from '@mui/x-data-grid';

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

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

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

return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGrid
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'linear-progress',
noRowsVariant: 'linear-progress',
},
}}
/>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DataGrid
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'linear-progress',
noRowsVariant: 'linear-progress',
},
}}
/>
32 changes: 32 additions & 0 deletions docs/data/data-grid/overlays/LoadingOverlaySkeleton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 LoadingOverlaySkeleton() {
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'],
},
}}
/>
</Box>
);
}
32 changes: 32 additions & 0 deletions docs/data/data-grid/overlays/LoadingOverlaySkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 LoadingOverlaySkeleton() {
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'],
},
}}
/>
</Box>
);
}
15 changes: 15 additions & 0 deletions docs/data/data-grid/overlays/LoadingOverlaySkeleton.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DataGridPro
{...data}
loading
slotProps={{
loadingOverlay: {
variant: 'skeleton',
noRowsVariant: 'skeleton',
},
}}
initialState={{
pinnedColumns: {
left: ['desk'],
},
}}
/>
Loading

0 comments on commit 1ab8174

Please sign in to comment.