2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
2018-02-13 19:32:59 +00:00
|
|
|
const percent = require('../../utils').percent;
|
2017-08-24 21:54:02 +00:00
|
|
|
|
|
|
|
const radius = 73;
|
|
|
|
const oRadius = radius + 10;
|
|
|
|
const oDiameter = oRadius * 2;
|
|
|
|
const circumference = 2 * Math.PI * radius;
|
|
|
|
|
2018-02-21 21:59:06 +00:00
|
|
|
module.exports = function(progressRatio, indefinite = false) {
|
2018-03-12 19:24:09 +00:00
|
|
|
// HACK - never indefinite for MS Edge
|
|
|
|
if (/edge/i.test(navigator.userAgent)) {
|
|
|
|
indefinite = false;
|
|
|
|
}
|
2018-02-21 21:59:06 +00:00
|
|
|
const p = indefinite ? 0.2 : progressRatio;
|
|
|
|
const dashOffset = (1 - p) * circumference;
|
|
|
|
const progressPercent = html`
|
|
|
|
<text class="progress__percent" text-anchor="middle" x="50%" y="98">
|
|
|
|
${percent(progressRatio)}
|
|
|
|
</text>`;
|
|
|
|
|
2018-02-16 20:56:53 +00:00
|
|
|
return html`
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="progress">
|
2018-01-24 18:23:13 +00:00
|
|
|
<svg
|
|
|
|
width="${oDiameter}"
|
|
|
|
height="${oDiameter}"
|
|
|
|
viewPort="0 0 ${oDiameter} ${oDiameter}"
|
|
|
|
version="1.1">
|
|
|
|
<circle
|
2018-02-13 19:32:59 +00:00
|
|
|
class="progress__bg"
|
2018-01-24 18:23:13 +00:00
|
|
|
r="${radius}"
|
|
|
|
cx="${oRadius}"
|
|
|
|
cy="${oRadius}"
|
|
|
|
fill="transparent"/>
|
|
|
|
<circle
|
2018-02-28 16:57:35 +00:00
|
|
|
class="progress__indefinite ${indefinite ? '' : 'progress--invisible'}"
|
|
|
|
r="${radius}"
|
|
|
|
cx="${oRadius}"
|
|
|
|
cy="${oRadius}"
|
|
|
|
fill="transparent"
|
|
|
|
transform="rotate(-90 ${oRadius} ${oRadius})"
|
|
|
|
stroke-dasharray="${circumference}"
|
|
|
|
stroke-dashoffset="${dashOffset}"/>
|
|
|
|
<circle
|
|
|
|
class="progress__bar ${indefinite ? 'progress--invisible' : ''}"
|
2018-01-24 18:23:13 +00:00
|
|
|
r="${radius}"
|
|
|
|
cx="${oRadius}"
|
|
|
|
cy="${oRadius}"
|
|
|
|
fill="transparent"
|
|
|
|
transform="rotate(-90 ${oRadius} ${oRadius})"
|
|
|
|
stroke-dasharray="${circumference}"
|
|
|
|
stroke-dashoffset="${dashOffset}"/>
|
2018-02-21 21:59:06 +00:00
|
|
|
${indefinite ? '' : progressPercent}
|
2017-08-24 21:54:02 +00:00
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
};
|