import React from 'react' import enhanceWithClickOutside from 'react-click-outside' import { SketchPicker } from 'react-color' import shallowCompare from 'react-addons-shallow-compare' import WindowPointer from './WindowPointer' import ImagePicker from './ImagePicker' import { COLORS, DEFAULT_BG_COLOR } from '../lib/constants' import { validateColor } from '../lib/colors' import { parseRGBA, capitalizeFirstLetter } from '../lib/util' class BackgroundSelect extends React.Component { constructor(props) { super(props) this.state = { isVisible: false, mounted: false } this.toggle = this.toggle.bind(this) this.selectTab = this.selectTab.bind(this) this.handlePickColor = this.handlePickColor.bind(this) } componentDidMount() { this.setState({ mounted: true }) } shouldComponentUpdate(prevProps, prevState) { return ( prevState.isVisible !== this.state.isVisible || (prevState.isVisible && shallowCompare(this, prevProps, prevState)) ) } toggle() { this.setState({ isVisible: !this.state.isVisible }) } selectTab(name) { if (this.props.mode !== name) { this.props.onChange({ backgroundMode: name }) } } handleClickOutside() { this.setState({ isVisible: false }) } handlePickColor(color) { this.props.onChange({ backgroundColor: parseRGBA(color.rgb) }) } render() { let background = this.props.color background = typeof background === 'string' ? background .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, ''') .replace(/\//g, '/') : background if (!validateColor(background)) { background = DEFAULT_BG_COLOR } const { mode, image } = this.props return (
BG
) } } export default enhanceWithClickOutside(BackgroundSelect)