Skip to content

Instantly share code, notes, and snippets.

@ever-dev
Last active January 13, 2020 02:56
Show Gist options
  • Save ever-dev/48552c86872b158e559b88bd17281824 to your computer and use it in GitHub Desktop.
Save ever-dev/48552c86872b158e559b88bd17281824 to your computer and use it in GitHub Desktop.
Customize the Circular Progress of the component from Material UI to accept color and size and put it the center of the screen.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { CircularProgress } from '@material-ui/core';
const defaultSize = 50;
class ColoredCircularProgressComponent extends Component {
render() {
const { classes, size } = this.props;
return <CircularProgress {...this.props} classes={classes} size={size} />;
}
}
class ColoredCircularProgress extends Component {
render() {
const WithStylesComponent = withStyles(theme => ({
colorPrimary: {
color: this.props.foreColor
},
root: {
top: `calc(50% - ${this.props.size / 2}px)`,
left: `calc(50% - ${this.props.size / 2}px)`,
position: 'absolute'
}
}))(ColoredCircularProgressComponent);
return <WithStylesComponent {...this.props} />;
}
}
ColoredCircularProgress.propTypes = {
classes: PropTypes.object,
size: PropTypes.number,
foreColor: PropTypes.string
};
ColoredCircularProgress.defaultProps = {
size: defaultSize,
foreColor: 'green'
};
export default ColoredCircularProgress;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment