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

[material-ui] Convert LinearProgress to support Pigment CSS #41816

Merged
merged 8 commits into from
Apr 17, 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
42 changes: 22 additions & 20 deletions packages/mui-material/src/CircularProgress/CircularProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ const circularDashKeyframe = keyframes`
}
`;

const rotateAnimation = css`
animation: ${circularRotateKeyframe} 1.4s linear infinite;
`;
// This implementation is for supporting both Styled-components v4+ and Pigment CSS.
// A global animation has to be created here for Styled-components v4+ (https://github.com/styled-components/styled-components/blob/main/packages/styled-components/src/utils/errors.md#12).
// which can be done by checking typeof indeterminate1Keyframe !== 'string' (at runtime, Pigment CSS transform keyframes`` to a string).
const rotateAnimation =
typeof circularRotateKeyframe !== 'string'
? css`
animation: ${circularRotateKeyframe} 1.4s linear infinite;
`
: null;
Comment on lines +45 to +50
Copy link
Member Author

@siriwatknp siriwatknp Apr 12, 2024

Choose a reason for hiding this comment

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

I decided to move the logic here so that rotateAnimation is not generated for Pigment CSS since the keyframe is already enough.


const dashAnimation = css`
animation: ${circularDashKeyframe} 1.4s ease-in-out infinite;
`;
const dashAnimation =
typeof circularDashKeyframe !== 'string'
? css`
animation: ${circularDashKeyframe} 1.4s ease-in-out infinite;
`
: null;

const useUtilityClasses = (ownerState) => {
const { classes, variant, color, disableShrink } = ownerState;
Expand Down Expand Up @@ -86,13 +95,9 @@ const CircularProgressRoot = styled('span', {
props: {
variant: 'indeterminate',
},
style:
// For Styled-components v4+: https://github.com/styled-components/styled-components/blob/main/packages/styled-components/src/utils/errors.md#12
rotateAnimation !== 'string'
? rotateAnimation
: {
animation: `${circularRotateKeyframe} 1.4s linear infinite`,
},
style: rotateAnimation || {
animation: `${circularRotateKeyframe} 1.4s linear infinite`,
},
},
...Object.entries(theme.palette)
.filter(([, palette]) => palette.main)
Expand Down Expand Up @@ -147,15 +152,12 @@ const CircularProgressCircle = styled('circle', {
},
},
{
// For Styled-components v4+: https://github.com/styled-components/styled-components/blob/main/packages/styled-components/src/utils/errors.md#12
props: ({ ownerState }) =>
ownerState.variant === 'indeterminate' && !ownerState.disableShrink,
style:
typeof dashAnimation !== 'string'
? dashAnimation
: {
animation: `${circularDashKeyframe} 1.4s ease-in-out infinite`,
},
style: dashAnimation || {
// At runtime for Pigment CSS, `bufferAnimation` will be null and the generated keyframe will be used.
animation: `${circularDashKeyframe} 1.4s ease-in-out infinite`,
},
},
],
}));
Expand Down
Loading
Loading