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

              
                <div class="container">
  <h1 class="text-center" style="color: red">Click on the dot to trigger. Click on it again to stop.</h1>
  <div class="text-center" id="app">
      
  </div>
		
</div>
              
            
!

CSS

              
                #app {
  margin-top: 40px;
}

.circle-background,
.circle-progress {
    fill: none;
}

.circle-progress {
    stroke: rgb(151, 151, 151);
    stroke-linecap: butt;
    stroke-linejoin: butt;
}

.circle-center {
    stroke:black;
    stroke-width: 2 ;
    fill:black;
} 

.circle-text {
    font-size: 5px;
    font-weight: bold;
    fill: red;
  }
              
            
!

JS

              
                class ProgressBar extends React.Component {

    state = {
        sqSize: 30,
        percentage: 0,
        strokeWidth: 3,
        propsTeste: false,
        barIndex: 0
    }

    
    barTriggerHandler = () => {
        const test = this.state.propsTeste
        this.setState({propsTeste: !test})
        console.log('works')
    }



    render () {
        
        let bars = Array(4).fill(1)

        let timer = 5000

        
        if (this.state.propsTeste) {
            setTimeout(() => {
                let percentage = this.state.percentage
                
                percentage < 99 ? this.setState({percentage: percentage + 1}) : this.setState({percentage: 0})

            }, timer / 100);
            // console.log('teste2')
            setTimeout(() => {
                let barIndex = this.state.barIndex
                
                barIndex < bars.length - 1 ? this.setState({barIndex: barIndex + 1}) : this.setState({barIndex: 0})
            }, timer);
            
        }

        // SVG centers the stroke width on the radius, subtract out so circle fits in square
        const radius = (this.state.sqSize - this.state.strokeWidth) / 2;
        // Enclose cicle in a circumscribing square
        const viewBox = `0 0 ${this.state.sqSize} ${this.state.sqSize}`;
        // Arc length at 100% coverage is the circle circumference
        const dashArray = radius * Math.PI * 2;
        // Scale 100% coverage overlay with the actual percent
        const dashOffset = dashArray - dashArray * this.state.percentage / 100;
        // console.log(dashOffset)

        return (
            <React.Fragment>
                { bars.map((bar, i) => {
                    return <svg
                                key={i}
    
                                width={this.state.sqSize}
                                height={this.state.sqSize}
                                viewBox={viewBox}
    
                                onClick={this.barTriggerHandler}
                            >
                                { i === this.state.barIndex ?  
                                    <circle
                                        className="circle-progress"
                                        cx={this.state.sqSize / 2}
                                        cy={this.state.sqSize / 2}
                                        r={radius}
                                        strokeWidth={`${this.state.strokeWidth}px`}
                                        // Start progress marker at 12 O'Clock
                                        transform={`rotate(-90 ${this.state.sqSize / 2} ${this.state.sqSize / 2})`}
                                        style={{
                                            strokeDasharray: dashArray,
                                            strokeDashoffset: dashOffset
                                        }} 
                                    /> 
                                : null }
                                <circle
                                    className="circle-center"
                                    cx="50%"
                                    cy="50%"
                                    r="3"
                                />
                                
                            </svg>
                }) }
                {/* <button onClick={this.barTriggerHandler}>Trigger</button> */}
            </React.Fragment>
        );
    }
    
}

ReactDOM.render(
  <ProgressBar/>,
  document.getElementById('app')
);
              
            
!
999px

Console