-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[styled] CSS Animations (@keyframes) do not work with the built-in "styled" function #24851
Comments
The problem was solved in v5: import * as React from "react";
import { keyframes } from "@material-ui/styled-engine";
import { experimentalStyled as styled } from "@material-ui/core/styles";
const bounce = keyframes`
from {
opacity: 1;
transform: scale(1);
}
to {
opacity: 0;
transform: scale(2);
}
`;
const PulsatingCircle = styled("div")(({ theme }) => ({
background: theme.palette.primary.main,
width: 10,
height: 10,
borderRadius: "100%",
animation: `${bounce} 1s infinite ease`,
position: "absolute",
zIndex: -2
})); https://codesandbox.io/s/material-ui-issue-forked-cxkn7?file=/src/Demo.js cc @mnajdova It seems that the JavaScript syntax for the usage works fine. We might want to document it if we get more questions about it. We didn't with JSS so we might not need it for emotion/sc either |
@oliviertassinari I need a solution for v4, would it be possible to fix this for v4? If this is not possible then when will v5 be released? |
@roymdavis in v4, you can use the makeStyles/withStyles API, the API supports it (not styled). You can check the source components some depend on keyframes. |
For anyone who's facing the same issue I was able to come up with the following using the withStyles API const PulsatingCircleComponent = styled("div")(({
theme,
}) => ({
background: theme.palette.primary.main,
borderRadius: "100%",
animation: "pulsate 1s infinite ease",
position: "absolute",
zIndex: -2,
}));
const PulsatingCircle = withStyles({
"@global @keyframes pulsate": {
from: {
opacity: 1,
transform: "scale(1)",
},
to: {
opacity: 0,
transform: "scale(2)",
},
},
})(() => {
return (
<PulsatingCircleComponent />
);
}); @oliviertassinari This compiles/works, so thanks for pointing me in the right direction. However I don't think this solution is very elegant, would it be possible to add a quick fix for this issue in v4? If it's not possible then would you be open to accepting a pull request with a fix for v4? |
@roymdavis We don't plan nor will accept fixes for v4. The development of v4 has been paused for almost a year now |
@oliviertassinari Got it, thanks for clarifying and the quick response. |
Question....how would this look in v5? |
@Gungrave223 take a look at the CircularProgress usage. |
@mnajdova much appreciated....worked perfectly...also... outstanding job on mui. |
Just to add to Oliver's answer, keyframes come from styled-engine in v5: |
@justdvl it will be exported from both the |
Current Behavior 😯
I'm trying to add a CSS animation in my styled component using the built in styled function from @material-ui/styles, adding the animation causes an error to be returned. Here's what my code looks like:
Error that's returned:
I also tried "scoping" the animation globally as per some recommend solutions for JSS that I found online, but it still resulted in the same error being thrown. Here's what it looks like when scoped globally:
I believe I'm following the correct format for adding keyframe animations to a JSS object. For reference here's the JSS docs for adding keyframes: https://cssinjs.org/jss-syntax/?v=v10.5.1#keyframes-animation
Expected Behavior 🤔
The keyframe animation should be usable in the styled component.
Steps to Reproduce 🕹
Codesandbox link: https://codesandbox.io/s/material-ui-issue-forked-rj600
See details above. Adding a MUI styled component with a CSS keyframe animation results in the error posted above being thrown.
Context 🔦
I'm attempting to add an animation to my styled component, and this error is not allowing me to.
Your Environment 🌎
I'm developing on Brave Browser Version 1.19.92 (Chromium: 88.0.4324.152 64 bit)
`npx @material-ui/envinfo`
The text was updated successfully, but these errors were encountered: