11import React , { PropTypes } from 'react'
22import './ColorSelector.scss'
33import { SketchPicker } from 'react-color'
4- import _ from 'lodash'
54import { HOC as hoc } from 'formsy-react'
65import { PROJECT_MAX_COLORS } from '../../config/constants'
76import { Icons } from 'appirio-tech-react-components'
@@ -13,15 +12,14 @@ class ColorSelector extends React.Component {
1312
1413 this . state = {
1514 isPickerVisible : false ,
16- newColor : '#fff' ,
17- colors : _ . uniq ( [ ...props . defaultColors , ...props . value ] )
15+ newColor : '#fff'
1816 }
1917 }
2018
2119 render ( ) {
22- const { getValue, name, onChange, setValue} = this . props
23- const value = getValue ( ) || [ ]
24- const { isPickerVisible, colors , newColor} = this . state
20+ const { getValue, name, onChange, setValue, defaultColors } = this . props
21+ const value = getValue ( ) || defaultColors
22+ const { isPickerVisible, newColor} = this . state
2523
2624 const onColorToggle = ( color ) => {
2725 const index = value . indexOf ( color )
@@ -54,7 +52,7 @@ class ColorSelector extends React.Component {
5452 </ a >
5553 ) }
5654
57- { colors . length < PROJECT_MAX_COLORS &&
55+ { value . length < PROJECT_MAX_COLORS &&
5856 < a
5957 href = "javascript:"
6058 onClick = { ( ) => this . setState ( { isPickerVisible : true } ) }
@@ -72,11 +70,6 @@ class ColorSelector extends React.Component {
7270 < button type = "button" className = "tc-btn tc-btn-primary tc-btn-md"
7371 onClick = { ( ) => {
7472 this . setState ( { isPickerVisible : false } )
75- if ( colors . indexOf ( newColor ) === - 1 ) {
76- this . setState ( { colors : [ ...colors , newColor ] , newColor : '#fff' } )
77- } else {
78- this . setState ( { newColor : '#fff' } )
79- }
8073 const newValue = [ ...value , newColor ]
8174 setValue ( newValue )
8275 onChange ( name , newValue )
0 commit comments