Last active
January 13, 2020 02:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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