-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
[CircularProgress] Allow set a gradient stroke #9496
Comments
@aristidescata I'm not sure to understand your use case. What are you trying to accomplish? |
Sorry, i'll try to be more clear using the example you provide and modifying it a little bit: basically i want to give a gradient color to the circle line instead of a solid color. and i don't know how to do it. The color property does not support gradients, i.e. things like color: 'linear-gradient(90deg, #2bb0af 0, #23a7d7)' |
The closest thing I could find is https://stackoverflow.com/questions/30147879/how-to-draw-a-linear-gradient-circle-by-svg. I fear you can't get along by simply modifying the CSS. You have to change the svg structure. It's not something we are directly interested in supporting. Let us know if you found a way. We could study how we could port the support back to the library. |
For those, who seek a convenient way to do this, I want to offer a solution below. We need to use CircularProgress with SVG linear-gradient and set an id property to that linear-gradient. After, we can define a class that will refer to that id by CSS And in the end, we need to add that class to CircularProgress "class" property and override the "circle" class. import React from 'react';
import { CircularProgress, makeStyles } from "@material-ui/core";
const useStyles = makeStyles(() => ({
circle: {
stroke: "url(#linearColors)",
},
}));
export default function GradientCircularProgress() {
const classes = useStyles({});
return (
<>
<svg width="300" height="300">
<linearGradient id="linearColors" x1="0" y1="0" x2="1" y2="1">
<stop offset="20%" stopColor="#39F" />
<stop offset="90%" stopColor="#F3F" />
</linearGradient>
</svg>
<CircularProgress
thickness={4}
classes={{ circle: classes.circle }}
/>
</>
);
} Here is the link below to the codesandbox with an example and a gif. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thank you bro, its work! |
Mui 5 way:
|
thank you guys! @antokhio @ShamansCoding |
Hi, I want to set a gradient stroke for the CircularProgress component.
currently using the circle prop exposed by that component:
Circular Progress API
but sadly the stroke property does not allow to set the gradient that way. You have to define this way:
I looked through the issues to see if someone else had the same problem and coudln't find any anwser.
The closest thing I got was this comment:
#7221 (comment)
which is exactly what i want.
Is there a special way to handle this?
The text was updated successfully, but these errors were encountered: