Skip to content

Instantly share code, notes, and snippets.

@RealSGII2
Created May 14, 2020 01:15
Show Gist options
  • Save RealSGII2/78187d5740917782ce237e85187c7cf8 to your computer and use it in GitHub Desktop.
Save RealSGII2/78187d5740917782ce237e85187c7cf8 to your computer and use it in GitHub Desktop.
RSGUI-REACT progress ring component for ReactJS.
import * as React from 'react'
import styles from './index.module.css'
import classNames from 'classnames'
interface Props {
active?: boolean,
radius?: number,
width?: number,
style?: any,
color?: string
}
interface State {
styles: {
width?: number,
height?: number,
display?: string
},
stroke: number
}
export class ProgressRing extends React.Component<Props, {}> {
public state: State = {
styles: {
height: (this.props.radius as number) || 30,
width: (this.props.radius as number) || 30,
display: this.props.active ? "inline-block" : "none"
},
stroke: (this.props.width as number) || 5
}
public oldState: any = { styles: {} }
componentDidUpdate (oldProps: Props) {
if (oldProps.active == this.props.active && oldProps.width == this.props.width) return;
this.oldState.styles.display = this.state.styles.display
this.oldState.stroke = this.state.stroke
let newState: State = {
styles: {
display: this.props.active ? "inline-block" : "none",
height: (this.props.radius as number) || 30,
width: (this.props.radius as number) || 30
},
stroke: (this.props.width as number) || 5,
}
this.setState(newState)
}
render () {
let classes = classNames({
[styles["spinner"]]: true,
[styles[`color-${this.props.color || "brand"}`]]: true
})
return (
<div className={classes} style={{...this.props.style, ...this.state.styles}}>
<svg viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg" strokeWidth={this.props.width || 4}>
<circle cx="33" cy="33" r="28" fill="none" />
</svg>
<svg viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg" strokeWidth={this.props.width || 4}>
<circle cx="33" cy="33" r="28" fill="none" />
</svg>
<svg viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg" strokeWidth={this.props.width || 4}>
<circle cx="33" cy="33" r="28" fill="none" />
</svg>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment