UNPKG

react-color

Version:

A Collection of Color Pickers from Sketch, Photoshop, Chrome & more

66 lines (61 loc) 1.55 kB
import React from 'react'; import reactCSS from 'reactcss'; import * as colorUtils from '../../helpers/color'; import { Swatch } from '../common'; export var CompactColor = function CompactColor(_ref) { var color = _ref.color, _ref$onClick = _ref.onClick, onClick = _ref$onClick === undefined ? function () {} : _ref$onClick, onSwatchHover = _ref.onSwatchHover, active = _ref.active; var styles = reactCSS({ 'default': { color: { background: color, width: '15px', height: '15px', float: 'left', marginRight: '5px', marginBottom: '5px', position: 'relative', cursor: 'pointer' }, dot: { absolute: '5px 5px 5px 5px', background: colorUtils.getContrastingColor(color), borderRadius: '50%', opacity: '0' } }, 'active': { dot: { opacity: '1' } }, 'color-#FFFFFF': { color: { boxShadow: 'inset 0 0 0 1px #ddd' }, dot: { background: '#000' } }, 'transparent': { dot: { background: '#000' } } }, { active: active, 'color-#FFFFFF': color === '#FFFFFF', 'transparent': color === 'transparent' }); return React.createElement( Swatch, { style: styles.color, color: color, onClick: onClick, onHover: onSwatchHover, focusStyle: { boxShadow: '0 0 4px ' + color } }, React.createElement('div', { style: styles.dot }) ); }; export default CompactColor;