diff --git a/components/BackgroundSelect.js b/components/BackgroundSelect.js index b43c2ff..e39634a 100644 --- a/components/BackgroundSelect.js +++ b/components/BackgroundSelect.js @@ -1,23 +1,15 @@ 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 ColorPicker from './ColorPicker' +import Popout from './Popout' import { COLORS, DEFAULT_BG_COLOR } from '../lib/constants' import { validateColor } from '../lib/colors' - -const stringifyRGBA = obj => `rgba(${obj.r},${obj.g},${obj.b},${obj.a})` -const capitalizeFirstLetter = s => s.charAt(0).toUpperCase() + s.slice(1) +import { toggle, capitalize, stringifyRGBA } 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) - } + state = { isVisible: false, mounted: false } componentDidMount() { this.setState({ mounted: true }) @@ -31,23 +23,18 @@ class BackgroundSelect extends React.Component { ].some(Boolean) } - toggle() { - this.setState({ isVisible: !this.state.isVisible }) + toggle = e => { + e.stopPropagation() + this.setState(toggle('isVisible')) } - selectTab(name) { + selectTab = name => { if (this.props.mode !== name) { this.props.onChange({ backgroundMode: name }) } } - handleClickOutside() { - this.setState({ isVisible: false }) - } - - handlePickColor(color) { - this.props.onChange({ backgroundColor: stringifyRGBA(color.rgb) }) - } + handlePickColor = ({ rgb }) => this.props.onChange({ backgroundColor: stringifyRGBA(rgb) }) render() { const { color, mode, image, onChange, aspectRatio } = this.props @@ -76,8 +63,12 @@ class BackgroundSelect extends React.Component {
-