Skip to content

Commit 92b64e8

Browse files
author
vikasrohit
authored
Merge pull request #512 from appirio-tech/feature/color-remove-option
Feature/color remove option
2 parents dd3d230 + 6c7e4d7 commit 92b64e8

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/components/ColorSelector/ColorSelector.jsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {PropTypes} from 'react'
22
import './ColorSelector.scss'
33
import { SketchPicker } from 'react-color'
4-
import _ from 'lodash'
54
import { HOC as hoc } from 'formsy-react'
65
import {PROJECT_MAX_COLORS} from '../../config/constants'
76
import { 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

Comments
 (0)