Skip to content

Commit

Permalink
[docs] Smooth performance animation (#8986)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored May 20, 2023
1 parent 8827562 commit 658e8be
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
31 changes: 20 additions & 11 deletions docs/data/data-grid/performance/GridWithReactMemo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { teal } from '@mui/material/colors';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { DataGridPro, GridRow, GridColumnHeaders } from '@mui/x-data-grid-pro';
import { useDemoData } from '@mui/x-data-grid-generator';
Expand All @@ -11,13 +10,17 @@ const TraceUpdates = React.forwardRef((props, ref) => {
const handleRef = useForkRef(rootRef, ref);

React.useEffect(() => {
rootRef.current?.classList.add('updating');
const root = rootRef.current;
root.classList.add('updating');
root.classList.add('updated');

const timer = setTimeout(() => {
rootRef.current?.classList.remove('updating');
}, 500);
root.classList.remove('updating');
}, 360);

return () => clearTimeout(timer);
return () => {
clearTimeout(timer);
};
});

return <Component ref={handleRef} {...other} />;
Expand Down Expand Up @@ -47,12 +50,18 @@ export default function GridWithReactMemo() {
sx={{
height: 400,
width: '100%',
'&&& .updating': (theme) => ({
background: teal[theme.palette.mode === 'dark' ? 900 : 100],
transition: theme.transitions.create('background', {
duration: theme.transitions.duration.standard,
}),
}),
'&&& .updated': {
transition: (theme) =>
theme.transitions.create(['background-color', 'outline'], {
duration: theme.transitions.duration.standard,
}),
},
'&&& .updating': {
backgroundColor: 'rgb(92 199 68 / 25%)',
outline: '1px solid rgb(92 199 68 / 35%)',
outlineOffset: '-1px',
transition: 'none',
},
}}
>
<DataGridPro
Expand Down
31 changes: 20 additions & 11 deletions docs/data/data-grid/performance/GridWithReactMemo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { teal } from '@mui/material/colors';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { DataGridPro, GridRow, GridColumnHeaders } from '@mui/x-data-grid-pro';
import { useDemoData } from '@mui/x-data-grid-generator';
Expand All @@ -11,13 +10,17 @@ const TraceUpdates = React.forwardRef<any, any>((props, ref) => {
const handleRef = useForkRef(rootRef, ref);

React.useEffect(() => {
rootRef.current?.classList.add('updating');
const root = rootRef.current;
root!.classList.add('updating');
root!.classList.add('updated');

const timer = setTimeout(() => {
rootRef.current?.classList.remove('updating');
}, 500);
root!.classList.remove('updating');
}, 360);

return () => clearTimeout(timer);
return () => {
clearTimeout(timer);
};
});

return <Component ref={handleRef} {...other} />;
Expand Down Expand Up @@ -47,12 +50,18 @@ export default function GridWithReactMemo() {
sx={{
height: 400,
width: '100%',
'&&& .updating': (theme) => ({
background: teal[theme.palette.mode === 'dark' ? 900 : 100],
transition: theme.transitions.create('background', {
duration: theme.transitions.duration.standard,
}),
}),
'&&& .updated': {
transition: (theme) =>
theme.transitions.create(['background-color', 'outline'], {
duration: theme.transitions.duration.standard,
}),
},
'&&& .updating': {
backgroundColor: 'rgb(92 199 68 / 25%)',
outline: '1px solid rgb(92 199 68 / 35%)',
outlineOffset: '-1px',
transition: 'none',
},
}}
>
<DataGridPro
Expand Down

0 comments on commit 658e8be

Please sign in to comment.