import React from 'react' import colornames from 'colornames' import ImagePicker from './ImagePicker' import ColorPicker from './ColorPicker' import Popout, { managePopout } from './Popout' import { COLORS, DEFAULT_BG_COLOR } from '../lib/constants' import { capitalize, stringifyRGBA } from '../lib/util' function validateColor(str) { if (/#\d{3,6}|rgba{0,1}\(.*?\)/gi.test(str) || colornames(str)) { return str } } class BackgroundSelect extends React.PureComponent { selectTab = name => { if (this.props.mode !== name) { this.props.onChange({ backgroundMode: name }) } } handlePickColor = ({ rgb }) => this.props.onChange({ backgroundColor: stringifyRGBA(rgb) }) render() { const { color, mode, image, onChange, isVisible, toggleVisibility, carbonRef } = this.props const background = validateColor(color) ? color : DEFAULT_BG_COLOR const aspectRatio = carbonRef ? carbonRef.clientWidth / carbonRef.clientHeight : 1 return (