ColorIndicator.js (737B)
1 import React, { Component } from 'react' 2 import { rgb } from './Utils' 3 4 function toHex(n) { 5 var s = Number(n).toString(16) 6 if (s.length === 1) { 7 s = "0" + s 8 } 9 return s 10 } 11 12 export default class ColorIndicator extends Component { 13 render() { 14 let { r, g, b } = rgb(this.props.color) 15 let colorDesc = `#${toHex(r)}${toHex(g)}${toHex(b)}` 16 var foreground = "black" 17 if (r < 133 && g < 133 && b < 133) { 18 foreground = "white" 19 } 20 21 return <div 22 className="paintCol" 23 style={{ 24 background: `rgb(${r},${g},${b})`, 25 color: foreground 26 }}> 27 <span>{colorDesc}</span> 28 </div> 29 } 30 }