From 583e4ece736561aa508b2e29c52cfdf68618a9de Mon Sep 17 00:00:00 2001 From: raboid Date: Mon, 7 Jan 2019 17:23:05 -0500 Subject: [PATCH] Update BackgroundSelect to use Popout & ColorPicker --- components/BackgroundSelect.js | 83 ++++++++-------------------------- lib/util.js | 4 ++ 2 files changed, 24 insertions(+), 63 deletions(-) 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 {
- + @@ -209,4 +166,4 @@ class BackgroundSelect extends React.Component { } } -export default enhanceWithClickOutside(BackgroundSelect) +export default BackgroundSelect diff --git a/lib/util.js b/lib/util.js index 9f72689..dc4bc83 100644 --- a/lib/util.js +++ b/lib/util.js @@ -74,3 +74,7 @@ export const formatCode = async code => { } export const omit = (object, keys) => omitBy(object, (_, k) => keys.indexOf(k) > -1) + +export const stringifyRGBA = obj => `rgba(${obj.r},${obj.g},${obj.b},${obj.a})` + +export const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1)