CSS
.wrapper-progressbar {
flex: 1;
}
progress {
width: 100%;
background-image:
linear-gradient(
90deg,
rgba(255,0,0,0.1),
rgba(255,0,0,0.1) 30%,
rgba(0,255,0,0.1) 30%,
rgba(0,255,0,0.1) 70%,
rgba(255,0,0,0.1) 70%);
border: 0;
height: 2em;
border-radius: 9px;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-bar {
width: 100%;
background: transparent;
background-image:
-webkit-linear-gradient(
left,
rgba(255,0,0,0.1),
rgba(255,0,0,0.1) 30%,
rgba(0,255,0,0.1) 30%,
rgba(0,255,0,0.1) 70%,
rgba(255,0,0,0.1) 70%);
border: 0;
height: 2em;
border-radius: 9px;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25) inset;
}
progress[value] {
background-color: transparent;
border-radius: 5px;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25) inset;
position: relative;
/* Reset the default appearance */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* Get rid of default border in Firefox. */
/*border: none;*/
}
progress[value]::-moz-progress-bar { /* Firefox */
border-radius: 2px;
background-size: 65px, 100%, 100%;
background-color: transparent;
background-image:
-moz-linear-gradient(
135deg,
transparent 33%,
rgba(0, 0, 0, 0.1) 33%,
rgba(0, 0, 0, 0.1) 66%,
transparent 66%
),
-moz-linear-gradient(
top,
rgba(255, 255, 255, 0.25),
rgba(0, 0, 0, 0.25)
),
-moz-linear-gradient(
left,
rgba(255,0,0,0.8),
rgba(255,0,0,0.8) 37.5%,
rgba(0,255,0,0.8) 37.5%,
rgba(0,255,0,0.8) 87.5%,
rgba(255,0,0,0.8) 87.5%
);
}
progress[value]::-webkit-progress-value { /* Chrome */
border-radius: 2px;
background-size: 65px, 100%, 100%;
background-color: transparent;
background-image:
-webkit-linear-gradient(
135deg,
transparent 33%,
rgba(0, 0, 0, 0.1) 33%,
rgba(0, 0, 0, 0.1) 66%,
...
Babel + JSX
const Progressbar = ({percent, min, max}) => {
let styleProgress = { backgroundImage:
`linear-gradient(
90deg,
rgba(255,0,0,0.1),
rgba(255,0,0,0.1) ${min}%,
rgba(0,255,0,0.1) ${min}%,
rgba(0,255,0,0.1) ${max}%,
rgba(255,0,0,0.1) ${max}%)`
};
return(
<div className="wrapper-progressbar">
<progress style={styleProgress} max="100" value={percent}>
</progress>
</div>
);
};
class Hello extends React.Component {
constructor (props) {
super(props);
this.state = {percent: "80"};
this.handleRefreshTimeout = this.handleRefreshTimeout.bind(this);
}
componentDidMount() {
// after render()
setTimeout(() => {
this.handleRefreshTimeout(1000);
}, 1000);
}
handleRefreshTimeout(timeout = 1000) {
switch(this.state.percent) {
case '80':
this.setState({percent: '50'});
break;
case '50':
this.setState({percent: '20'});
break;
case '20':
this.setState({percent: '80'});
break;
default:
this.setState({percent: '20'});
}
setTimeout(() => {
this.handleRefreshTimeout(timeout);
}, timeout)
}
render() {
return (
<div>The value is: {this.state.percent}
<Progressbar min="30" max="70" percent={this.state.percent} /></div>
);
}
}
ReactDOM.render(
<Hello />,
document.getElementById('container')
);