const MamiPingIndicator = function(initialStrength) {
const bars = [];
const html =
;
for(let i = 1; i <= 3; ++i)
bars.push(html.appendChild());
const setStrength = strength => {
if(typeof strength !== 'number')
throw 'strength must be a number';
for(const i in bars)
bars[i].classList.toggle('ping-bar-on', i < strength);
html.classList.toggle('ping-state-good', strength > 1);
html.classList.toggle('ping-state-warn', strength === 1);
html.classList.toggle('ping-state-poor', strength < 1);
};
if(typeof initialStrength !== 'number')
initialStrength = bars.length;
setStrength(initialStrength);
return {
getElement: () => html,
setStrength: setStrength,
};
};