Skip to content

Instantly share code, notes, and snippets.

@adammark
Last active May 18, 2021 11:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adammark/b9e0992dc6afaa72babdf52e38f228d4 to your computer and use it in GitHub Desktop.
Save adammark/b9e0992dc6afaa72babdf52e38f228d4 to your computer and use it in GitHub Desktop.
var Meter = function (props) {
var {
percent = 0, // a number between 0 and 1, inclusive
width = 100, // the overall width
height = 10, // the overall height
rounded = true, // if true, use rounded corners
color = "#0078bc", // the fill color
animate = false, // if true, animate when the percent changes
label = null // a label to describe the contents (for accessibility)
} = props;
var r = rounded ? Math.ceil(height / 2) : 0;
var w = percent ? Math.max(height, width * Math.min(percent, 1)) : 0;
var style = animate ? { "transition": "width 500ms, fill 250ms" } : null;
return (
<svg width={width} height={height} aria-label={label} data-tooltip={label}>
<rect width={width} height={height} fill="#ccc" rx={r} ry={r}/>
<rect width={w} height={height} fill={color} rx={r} ry={r} style={style}/>
</svg>
);
};
module.exports = Meter;
@meetajhu
Copy link

meetajhu commented Dec 1, 2018

Animation progress animation isn't smooth. But Good job anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment