2016-09-18 22:47:33 -08:00
|
|
|
const Color = require('color');
|
|
|
|
|
|
|
|
|
|
// returns a background color that's in hex
|
|
|
|
|
// format including the alpha channel (e.g.: `#00000050`)
|
|
|
|
|
// input can be any css value (rgb, hsl, string…)
|
2016-10-12 17:35:44 -08:00
|
|
|
module.exports = bgColor => {
|
2016-09-18 22:47:33 -08:00
|
|
|
const color = Color(bgColor);
|
2016-09-21 06:27:11 -08:00
|
|
|
if (color.alpha() === 1) {
|
2016-09-18 22:47:33 -08:00
|
|
|
return color.hexString();
|
|
|
|
|
}
|
2016-12-21 17:31:30 -09:00
|
|
|
|
|
|
|
|
// http://stackoverflow.com/a/11019879/1202488
|
|
|
|
|
const alphaHex = Math.round(color.alpha() * 255).toString(16);
|
|
|
|
|
return '#' + alphaHex + color.hexString().substr(1);
|
2016-09-18 22:47:33 -08:00
|
|
|
};
|