11import React from "react" ;
22import PropTypes from "prop-types" ;
33import { Button , Col , Form , Icon , Input , Modal , Row , Tooltip } from "antd" ;
4+ import { SliderPicker } from "react-color" ;
45import "antd/lib/button/style/index.less" ;
56import "antd/lib/checkbox/style/index.less" ;
67import "antd/lib/col/style/css" ;
@@ -18,7 +19,7 @@ import "./TagModal.less";
1819 */
1920const ManagedForm = Form . create ( ) (
2021 ( props ) => {
21- const { administrationMode , tag, creationMode, form} = props ;
22+ const { tag, creationMode, form, colorPicker } = props ;
2223 const { getFieldDecorator} = form ;
2324
2425 return (
@@ -34,26 +35,11 @@ const ManagedForm = Form.create()(
3435 } ) (
3536 < Input
3637 addonBefore = "Name"
37- readOnly = { ! administrationMode }
3838 />
3939 ) }
4040 </ Form . Item >
41- < Form . Item
42- { ...managedFormItemLayout }
43- validateStatus = { form . getFieldError ( "color" ) ? "error" : "" }
44- colon = { false }
45- >
46- { getFieldDecorator ( "color" , {
47- initialValue : tag . name ,
48- rules : [ { required : true , message : "Color is required" } ]
49- } ) (
50- < Input
51- addonBefore = "Color"
52- readOnly = { ! administrationMode }
53- />
54- ) }
55- </ Form . Item >
56- { ! creationMode && administrationMode &&
41+ { colorPicker ( ) }
42+ { ! creationMode &&
5743 < div >
5844 < Form . Item { ...managedFormItemLayout } >
5945 < Input
@@ -136,6 +122,7 @@ class TagModal extends React.Component {
136122 constructor ( props ) {
137123 super ( props ) ;
138124 this . state = {
125+ color : props . tag . color ? props . tag . color : "#2ad127"
139126 } ;
140127 }
141128
@@ -144,6 +131,7 @@ class TagModal extends React.Component {
144131 */
145132 handleActionButtonOnClick = ( ) => this . form . validateFields ( ( errors , payload ) => {
146133 if ( ! errors ) {
134+ payload . color = this . state . color ;
147135 this . props . onSave ( payload ) ;
148136 this . form . resetFields ( ) ;
149137 }
@@ -164,9 +152,19 @@ class TagModal extends React.Component {
164152 */
165153 saveManagedFormRef = ( form ) => this . form = form ;
166154
155+ /**
156+ * Gets the color from the color picker
157+ *
158+ * @param color - The color picked by the user
159+ */
160+ handleChangeComplete = ( color ) => {
161+ this . setState ( {
162+ color : color . hex
163+ } ) ;
164+ } ;
165+
167166 render ( ) {
168167 const {
169- administrationMode,
170168 creationMode,
171169 loading,
172170 locked,
@@ -189,7 +187,7 @@ class TagModal extends React.Component {
189187 < Row type = "flex" align = "middle" >
190188 < Col span = { 8 } >
191189 < div className = "operations" >
192- { ! creationMode && administrationMode &&
190+ { ! creationMode &&
193191 < Button . Group >
194192 < Button disabled = { locked } key = "delete" type = "danger" ghost = { true } size = "large" icon = "delete" onClick = { onDelete } />
195193 </ Button . Group >
@@ -208,6 +206,15 @@ class TagModal extends React.Component {
208206 </ div >
209207 ) ;
210208
209+ const colorPicker = ( ) => (
210+ < Form . Item { ...managedFormItemLayout } colon = { false } >
211+ < SliderPicker
212+ color = { this . state . color }
213+ onChangeComplete = { this . handleChangeComplete }
214+ />
215+ </ Form . Item >
216+ ) ;
217+
211218 return (
212219 < Modal
213220 id = "cckey-components-data-views-tag-modal"
@@ -222,24 +229,19 @@ class TagModal extends React.Component {
222229 < ManagedForm
223230 ref = { this . saveManagedFormRef }
224231 tag = { tag }
225- administrationMode = { administrationMode }
226232 creationMode = { creationMode }
233+ colorPicker = { colorPicker }
227234 />
228235 </ Col >
229236 </ Row >
230- { ! creationMode && administrationMode && < Row span = { 4 } > { lockStatusButton ( ) } </ Row > }
237+ { ! creationMode && < Row span = { 4 } > { lockStatusButton ( ) } </ Row > }
231238 < Row > < Col > { footer ( ) } </ Col > </ Row >
232239 </ Modal >
233240 ) ;
234241 }
235242}
236243
237244TagModal . propTypes = {
238- /**
239- * Indicates if the user group modal is in administration mode.
240- */
241- administrationMode : PropTypes . bool ,
242-
243245 /**
244246 * Indicates if the user group modal is in creation mode.
245247 *
@@ -298,7 +300,6 @@ TagModal.propTypes = {
298300} ;
299301
300302TagModal . defaultProps = {
301- administrationMode : false ,
302303 creationMode : false ,
303304 loading : false
304305} ;
0 commit comments