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

[CircularProgress] Allow set a gradient stroke #9496

Closed
aristidescata opened this issue Dec 14, 2017 · 9 comments
Closed

[CircularProgress] Allow set a gradient stroke #9496

aristidescata opened this issue Dec 14, 2017 · 9 comments
Labels
component: CircularProgress The React component component: progress This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@aristidescata
Copy link

aristidescata commented Dec 14, 2017

Hi, I want to set a gradient stroke for the CircularProgress component.

currently using the circle prop exposed by that component:
Circular Progress API

const styles = theme => ({
    circle: {
        stroke: linear-gradient(90deg, #2bb0af 0, #23a7d7)
    }
});

but sadly the stroke property does not allow to set the gradient that way. You have to define this way:

<svg width="80px" height="30px" viewBox="0 0 80 30"
     xmlns="http://www.w3.org/2000/svg">

  <defs>
    <linearGradient id="Gradient01">
      <stop offset="20%" stop-color="#39F" />
      <stop offset="90%" stop-color="#F3F" />
    </linearGradient>
  </defs>

  <rect x="10" y="10" width="60" height="10" 
        stroke="url(#Gradient01)" />
</svg>

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?

Tech Version
Material-UI Next
React 16.0.0
Chrome 57
@oliviertassinari oliviertassinari added the component: CircularProgress The React component label Dec 14, 2017
@oliviertassinari oliviertassinari changed the title [Circular Progress ] Allow set a gradient stroke [CircularProgress] Allow set a gradient stroke Dec 16, 2017
@oliviertassinari
Copy link
Member

@aristidescata I'm not sure to understand your use case. What are you trying to accomplish?

@aristidescata
Copy link
Author

Sorry, i'll try to be more clear using the example you provide and modifying it a little bit:
https://codesandbox.io/s/ovoqq9mlly

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)'

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement and removed waiting for user information labels Dec 17, 2017
@oliviertassinari
Copy link
Member

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.

@mui mui deleted a comment from biomassives Dec 17, 2017
@mui mui deleted a comment from biomassives Dec 17, 2017
@ShamansCoding
Copy link

ShamansCoding commented Sep 26, 2020

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 url() function. We add this referred linear-gradient to the "stroke" property of that class.

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.

GradientCircularProgress

Запись экрана 2020-09-27 в 17 28 06

@mbrookes

This comment has been minimized.

@ShamansCoding

This comment has been minimized.

@vitalyaM
Copy link

vitalyaM commented Sep 7, 2021

@ShamansCoding,

Thank you bro, its work!

@antokhio
Copy link

antokhio commented Nov 3, 2021

Mui 5 way:

<svg>
    <defs>
        <linearGradient id='my_gradient' x1='0%' y1='0%' x2='0%' y2='100%'>
            <stop offset='0%' stopColor='rgba(184, 74, 202, 1)' />
            <stop offset='100%' stopColor='rgba(142, 66, 235, 1)' />
        </linearGradient>
    </defs>
</svg>
<CircularProgress sx={{'svg circle': { stroke: 'url(#my_gradient)' } }}/>

@oliviertassinari oliviertassinari added the component: progress This is the name of the generic UI component, not the React module! label Nov 28, 2021
@denvradiy
Copy link

thank you guys! @antokhio @ShamansCoding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: CircularProgress The React component component: progress This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

7 participants