|
|
@ -1,33 +1,19 @@
|
|
|
|
import React from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
import shallowCompare from 'react-addons-shallow-compare'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ImagePicker from './ImagePicker'
|
|
|
|
import ImagePicker from './ImagePicker'
|
|
|
|
import ColorPicker from './ColorPicker'
|
|
|
|
import ColorPicker from './ColorPicker'
|
|
|
|
import Popout from './Popout'
|
|
|
|
import Popout, { managePopout } from './Popout'
|
|
|
|
import { COLORS, DEFAULT_BG_COLOR } from '../lib/constants'
|
|
|
|
import { COLORS, DEFAULT_BG_COLOR } from '../lib/constants'
|
|
|
|
import { validateColor } from '../lib/colors'
|
|
|
|
import { validateColor } from '../lib/colors'
|
|
|
|
import { toggle, capitalize, stringifyRGBA } from '../lib/util'
|
|
|
|
import { capitalize, stringifyRGBA } from '../lib/util'
|
|
|
|
|
|
|
|
|
|
|
|
class BackgroundSelect extends React.Component {
|
|
|
|
class BackgroundSelect extends React.PureComponent {
|
|
|
|
state = { isVisible: false, mounted: false }
|
|
|
|
state = { mounted: false }
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
componentDidMount() {
|
|
|
|
this.setState({ mounted: true })
|
|
|
|
this.setState({ mounted: true })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
shouldComponentUpdate(prevProps, prevState) {
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
prevState.isVisible !== this.state.isVisible,
|
|
|
|
|
|
|
|
prevProps.color !== this.props.color,
|
|
|
|
|
|
|
|
prevState.isVisible && shallowCompare(this, prevProps, prevState)
|
|
|
|
|
|
|
|
].some(Boolean)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toggle = e => {
|
|
|
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
|
|
|
this.setState(toggle('isVisible'))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectTab = name => {
|
|
|
|
selectTab = name => {
|
|
|
|
if (this.props.mode !== name) {
|
|
|
|
if (this.props.mode !== name) {
|
|
|
|
this.props.onChange({ backgroundMode: name })
|
|
|
|
this.props.onChange({ backgroundMode: name })
|
|
|
@ -37,8 +23,8 @@ class BackgroundSelect extends React.Component {
|
|
|
|
handlePickColor = ({ rgb }) => this.props.onChange({ backgroundColor: stringifyRGBA(rgb) })
|
|
|
|
handlePickColor = ({ rgb }) => this.props.onChange({ backgroundColor: stringifyRGBA(rgb) })
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
render() {
|
|
|
|
const { color, mode, image, onChange, aspectRatio } = this.props
|
|
|
|
const { color, mode, image, onChange, aspectRatio, isVisible, toggleVisibility } = this.props
|
|
|
|
const { isVisible, mounted } = this.state
|
|
|
|
const { mounted } = this.state
|
|
|
|
|
|
|
|
|
|
|
|
let background =
|
|
|
|
let background =
|
|
|
|
typeof color === 'string'
|
|
|
|
typeof color === 'string'
|
|
|
@ -58,17 +44,12 @@ class BackgroundSelect extends React.Component {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="bg-select-container">
|
|
|
|
<div className="bg-select-container">
|
|
|
|
<div className={`bg-select-display ${isVisible ? 'is-visible' : ''}`}>
|
|
|
|
<div className={`bg-select-display ${isVisible ? 'is-visible' : ''}`}>
|
|
|
|
<div className="bg-color-container" onClick={this.toggle}>
|
|
|
|
<div className="bg-color-container" onClick={toggleVisibility}>
|
|
|
|
<div className="bg-color-alpha" />
|
|
|
|
<div className="bg-color-alpha" />
|
|
|
|
<div className="bg-color" />
|
|
|
|
<div className="bg-color" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Popout
|
|
|
|
<Popout pointerLeft="15px" hidden={!isVisible} style={{ width: '222px' }}>
|
|
|
|
pointerLeft="15px"
|
|
|
|
|
|
|
|
onClickOutside={this.toggle}
|
|
|
|
|
|
|
|
hidden={!isVisible}
|
|
|
|
|
|
|
|
style={{ width: '222px' }}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<div className="picker-tabs">
|
|
|
|
<div className="picker-tabs">
|
|
|
|
{['color', 'image'].map(tab => (
|
|
|
|
{['color', 'image'].map(tab => (
|
|
|
|
<div
|
|
|
|
<div
|
|
|
@ -166,4 +147,4 @@ class BackgroundSelect extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default BackgroundSelect
|
|
|
|
export default managePopout(BackgroundSelect)
|
|
|
|