-
-
Save DonKoko/bce09863ce65f5ff25eedec6fbe9b2e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment