Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                 <h2>React Round Progress Bar</h2>

<div id="root"></div>
<p><strong>Referenced Pen:</strong> <a href="https://codepen.io/bbrady/pen/ozrjKE">https://codepen.io/bbrady/pen/ozrjKE</a></p>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Varela+Round');

body {
  font-family: 'Varela Round', sans-serif;
}
              
            
!

JS

              
                function RoundProgressBar(props) {
  const size = props.size;
  const radius = (props.size - props.strokeWidth) / 2;
  const viewBox = `0 0 ${size} ${size}`;
  const dashArray = radius * Math.PI * 2;
  const dashOffset = dashArray - dashArray * props.value / props.max;
  const percentage = (props.value / props.max * 100).toFixed();
  return (
    <svg
      width = {props.size}
      height = {props.size}
      viewBox = {viewBox}
    >
      <circle
        fill = {'none'}
        stroke = {'#ddd'}
        cx = { props.size / 2 }
        cy = { props.size / 2 }
        r = { radius }
        strokeWidth = {`${props.strokeWidth}px`} />
      <circle
        fill = {'none'}
        stroke = {props.stroke}
        strokeLinecap = "round"
        strokeLinejoin = "round"
        strokeDasharray = {dashArray}
        strokeDashoffset = {dashOffset}
        cx={props.size / 2}
        cy={props.size / 2}
        r={radius}
        strokeWidth={`${props.strokeWidth}px`}
        transform={`rotate(-90 ${props.size / 2} ${props.size / 2})`}
      />
      <text
        x="55%"
        y="50%"
        dy="0.4rem"
        textAnchor="end"
        fill={props.stroke}
        style={{
          fontSize:'2.5rem',
          fontFamily:'Varela Round',
          fontWeight: 'bold',
        }}
      >
        {`${props.value}`}
      </text>
      <text
        x="55%"
        y="50%"
        dy=".4rem"
        textAnchor="start"
        fill={props.stroke}
        style={
          {
            fontSize:'1.4rem',
            fontFamily:'Varela Round',
            fontWeight: 'bold'   
          }
        }
      > 
        {`/${props.max}`}
      </text>
      <text
        x="50%"
        y="50%"
        dy="1.5rem"
        textAnchor="middle"
        fill={props.stroke}
        style={
          {
            fontSize:'1rem',
            fontFamily:'Varela Round',
            fontWeight: 'bold',
          }
        }
      >
        {props.text}
      </text>
      <text
        x="50%"
        y="50%"
        dy="2.7rem"
        textAnchor="middle"
        fill={props.stroke}
        style={
          {
            fontSize:'1rem',
            fontFamily:'Varela Round',
          }
        }
        >
        {`${percentage}%`}
      </text>
    </svg>
  );
}

RoundProgressBar.defaultProps = {
  size: 200,
  value: 25,
  max: 100,
  strokeWidth: 10,
  stroke: 'red',
  text: ""
}

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      percentage: 25
    };

    this.handleChangeEvent = this.handleChangeEvent.bind(this);
  }

  handleChangeEvent(event) {
    this.setState({
      percentage: event.target.value
    });
  }

  render() {
    return (
      <div>
        <div style={{display:'flex',justifyContent:'space-around'}}>
          <RoundProgressBar
            value={this.state.percentage}
            stroke = {'#b9332f'}
            max = {210}
            text = "UNAVAILABLE"
            />
            <div>
              <h3>Click Me! &darr;</h3>
              <input 
                id="progressInput" 
                type="range" 
                min="0" 
                max="210"
                step="1"
                value={this.state.percentage}
                onChange={this.handleChangeEvent}/>
          </div>
          <RoundProgressBar
            value={210-this.state.percentage}
            stroke = {'#73bc8d'}
            max = {210}
            text = "AVAILABLE"
            />
        </div>
        </div>
    );
  }
}

ReactDOM.render(
  <App/>,
  document.querySelector('#root')
);
              
            
!
999px

Console