I want a progressbar, which is a multibar. Looks like this:
[----------][----50% ][ ]
[---20% ][ ][ ]
[----------][-----------][---80% ]
It has three distinctive part, RED-GREEN-RED:
[ RED RED ][GREEN GREEN][ RED RED]
It is realtime, the value comes from a remote json api, if the value is in the green zone, everything is fine, otherwise action required from colleagues (if its under the desired zone, or above it).
So far I implemented the html+css, works fine in Firefox and Chrome. Here is the demo project on jsfiddle:
- 20% - https://jsfiddle.net/jws0jh6w/1/
- 50% - https://jsfiddle.net/0458cbgw/1/
- 80% - https://jsfiddle.net/4cLa8kra/
Now I need to "reactify" the code, to be alive:)
The problem is, I can not inline style the following CSS rule:
progress[value]::-webkit-progress-value { /* Chrome */
background-image:
-webkit-linear-gradient(
135deg,
transparent 33%,
rgba(0, 0, 0, 0.1) 33%,
rgba(0, 0, 0, 0.1) 66%,
transparent 66%
),
-webkit-linear-gradient(
top,
rgba(255, 255, 255, 0.25),
rgba(0, 0, 0, 0.25)
),
-webkit-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%
);
}
The reactified Progressbar.js is rather simple:
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>
);
};
I can set the faint backround (so min and max is always visible), but not the actual progressbar.
Does anyone has any idea, how to make dynamic css selectors with React?
ps: Only Chrome and Firefox support is required, as it will end up as a TV in a control room (Kiosk mode).
So no IE support is needed at all.
The html5 <progress>
element would be the right solution imho.
Update: Here is a demo react project: https://jsfiddle.net/ave0x0nb/3/
The progressbar is either single colored (red 0-30%), has two colors (red 0-30%, green 30-70%), or tricolored (red 0-30%, green 30-70%, red 70-100%) depending the actual value. So if the value is 50% it is two colored (0-30% red and 30-50% green).
The problem right now (and hence the question), that it is always tricolored (the above react demo project), and do not respect the background progressbar's limits. See the 20%,50%,80% jsfiddle demo projects for reference.