UNPKG

react-color

Version:

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

87 lines (82 loc) 1.86 kB
import React from 'react'; import reactCSS from 'reactcss'; import * as colorUtils from '../../helpers/color'; import { Swatch } from '../common'; import CheckIcon from '@icons/material/CheckIcon'; export var SwatchesColor = function SwatchesColor(_ref) { var color = _ref.color, _ref$onClick = _ref.onClick, onClick = _ref$onClick === undefined ? function () {} : _ref$onClick, onSwatchHover = _ref.onSwatchHover, first = _ref.first, last = _ref.last, active = _ref.active; var styles = reactCSS({ 'default': { color: { width: '40px', height: '24px', cursor: 'pointer', background: color, marginBottom: '1px' }, check: { color: colorUtils.getContrastingColor(color), marginLeft: '8px', display: 'none' } }, 'first': { color: { overflow: 'hidden', borderRadius: '2px 2px 0 0' } }, 'last': { color: { overflow: 'hidden', borderRadius: '0 0 2px 2px' } }, 'active': { check: { display: 'block' } }, 'color-#FFFFFF': { color: { boxShadow: 'inset 0 0 0 1px #ddd' }, check: { color: '#333' } }, 'transparent': { check: { color: '#333' } } }, { first: first, last: last, active: active, 'color-#FFFFFF': color === '#FFFFFF', 'transparent': color === 'transparent' }); return React.createElement( Swatch, { color: color, style: styles.color, onClick: onClick, onHover: onSwatchHover, focusStyle: { boxShadow: '0 0 4px ' + color } }, React.createElement( 'div', { style: styles.check }, React.createElement(CheckIcon, null) ) ); }; export default SwatchesColor;