1- import classNames from 'classnames' ;
21import React , { PureComponent , ReactNode } from 'react' ;
3- import { CompactPicker } from 'react-color' ;
42
53import { DomainDesignerCheckbox } from '../DomainDesignerCheckbox' ;
64
@@ -22,6 +20,7 @@ import { LabelHelpTip } from '../../base/LabelHelpTip';
2220
2321import { Filters } from './Filters' ;
2422import { ValidatorModal } from './ValidatorModal' ;
23+ import { ColorPickerInput } from '../../forms/input/ColorPickerInput' ;
2524
2625interface ConditionalFormatOptionsProps {
2726 dataType : PropDescType ;
@@ -36,21 +35,7 @@ interface ConditionalFormatOptionsProps {
3635 validatorIndex : number ;
3736}
3837
39- interface ConditionalFormatState {
40- showFillColor : boolean ;
41- showTextColor : boolean ;
42- }
43-
44- export class ConditionalFormatOptions extends PureComponent < ConditionalFormatOptionsProps , ConditionalFormatState > {
45- constructor ( props ) {
46- super ( props ) ;
47-
48- this . state = {
49- showTextColor : false ,
50- showFillColor : false ,
51- } ;
52- }
53-
38+ export class ConditionalFormatOptions extends PureComponent < ConditionalFormatOptionsProps > {
5439 static isValid = ( validator : PropertyValidator ) : boolean => {
5540 return Filters . isValid ( validator . get ( 'formatFilter' ) , DOMAIN_CONDITIONAL_FORMAT_PREFIX ) ;
5641 } ;
@@ -91,7 +76,7 @@ export class ConditionalFormatOptions extends PureComponent<ConditionalFormatOpt
9176
9277 firstFilterTooltip = ( ) : ReactNode => {
9378 return (
94- < LabelHelpTip title = "First Condition" required >
79+ < LabelHelpTip required title = "First Condition" >
9580 Add a condition to this format rule that will be tested against the value for this field.
9681 </ LabelHelpTip >
9782 ) ;
@@ -104,9 +89,9 @@ export class ConditionalFormatOptions extends PureComponent<ConditionalFormatOpt
10489 < div className = "row" >
10590 < div className = "col-xs-12 domain-validation-display-checkbox-row" >
10691 < DomainDesignerCheckbox
92+ checked = { value }
10793 id = { createFormInputId ( name , domainIndex , validatorIndex ) }
10894 name = { createFormInputName ( name ) }
109- checked = { value }
11095 onChange = { this . onFieldChange }
11196 >
11297 { label }
@@ -116,68 +101,40 @@ export class ConditionalFormatOptions extends PureComponent<ConditionalFormatOpt
116101 ) ;
117102 } ;
118103
119- onColorShow = ( evt ) : void => {
120- const { showTextColor, showFillColor } = this . state ;
121- let name = getNameFromId ( evt . target . id ) ;
122-
123- // If click on caret icon
124- if ( ! name ) {
125- name = getNameFromId ( evt . target . parentElement . parentElement . id ) ;
126- }
127-
128- // Strange little border between icon and button
129- if ( ! name ) {
130- name = getNameFromId ( evt . target . parentElement . id ) ;
131- }
132-
133- if ( name === DOMAIN_CONDITION_FORMAT_TEXT_COLOR ) {
134- this . setState ( ( ) => ( { showTextColor : ! showTextColor , showFillColor : false } ) ) ;
135- }
136-
137- if ( name === DOMAIN_CONDITION_FORMAT_BACKGROUND_COLOR ) {
138- this . setState ( ( ) => ( { showFillColor : ! showFillColor , showTextColor : false } ) ) ;
139- }
140- } ;
141-
142- onColorChange = ( color ) : void => {
104+ onColorChange = ( name : string , hexValue : string ) : void => {
143105 const { onChange, validator, validatorIndex } = this . props ;
144- const { showTextColor } = this . state ;
145- const name = showTextColor ? DOMAIN_CONDITION_FORMAT_TEXT_COLOR : DOMAIN_CONDITION_FORMAT_BACKGROUND_COLOR ;
146- onChange ( validator . set ( name , color . hex . substring ( 1 ) ) , validatorIndex ) ;
106+ onChange ( validator . set ( name , hexValue . substring ( 1 ) ) , validatorIndex ) ;
147107 } ;
148108
149109 renderColorPickers = ( ) : ReactNode => {
150110 const { validator, validatorIndex } = this . props ;
151- const { showTextColor, showFillColor } = this . state ;
152111
153112 const textColor = validator . textColor ? '#' + validator . textColor : 'black' ;
154113 const fillColor = validator . backgroundColor ? '#' + validator . backgroundColor : 'white' ;
155114
156115 return (
157116 < div className = "row domain-validator-color-row" >
158- < div className = "col-xs-4 " >
159- { this . getColorPickerButton (
160- DOMAIN_CONDITION_FORMAT_TEXT_COLOR ,
161- 'Text Color' ,
162- textColor ,
163- showTextColor
164- ) }
117+ < div className = "col-xs-5 " >
118+ < ColorPickerInput
119+ name = { DOMAIN_CONDITION_FORMAT_TEXT_COLOR }
120+ onChange = { this . onColorChange }
121+ text = "Text Color"
122+ value = { textColor }
123+ />
165124 </ div >
166125 < div className = "col-xs-4" >
167- { this . getColorPickerButton (
168- DOMAIN_CONDITION_FORMAT_BACKGROUND_COLOR ,
169- 'Fill Color' ,
170- fillColor ,
171- showFillColor
172- ) }
126+ < ColorPickerInput
127+ name = { DOMAIN_CONDITION_FORMAT_BACKGROUND_COLOR }
128+ onChange = { this . onColorChange }
129+ text = "Fill Color"
130+ value = { fillColor }
131+ />
173132 </ div >
174- < div className = "col-xs-1" />
175133 < div className = "col-xs-3" >
176134 < input
177135 className = "form-control"
178- type = "text"
179- id = { 'domain-validator-preview-' + validatorIndex }
180136 defaultValue = "Preview Text"
137+ id = { 'domain-validator-preview-' + validatorIndex }
181138 style = { {
182139 fontSize : '12px' ,
183140 width : '100px' ,
@@ -187,47 +144,13 @@ export class ConditionalFormatOptions extends PureComponent<ConditionalFormatOpt
187144 fontStyle : validator . italic ? 'italic' : 'normal' ,
188145 textDecoration : validator . strikethrough ? 'line-through' : '' ,
189146 } }
147+ type = "text"
190148 />
191149 </ div >
192150 </ div >
193151 ) ;
194152 } ;
195153
196- getColorPickerButton = ( name : string , label : string , color : string , showColorPicker : boolean ) : ReactNode => {
197- const { validatorIndex, domainIndex } = this . props ;
198- const iconClassName = classNames ( 'domain-color-caret' , 'fa' , 'fa-lg' , {
199- 'fa-caret-up' : showColorPicker ,
200- 'fa-caret-down' : ! showColorPicker ,
201- } ) ;
202-
203- return (
204- < div style = { { width : '100%' } } >
205- < button
206- className = "domain-color-picker-btn btn btn-default"
207- id = { createFormInputId ( name , domainIndex , validatorIndex ) }
208- key = { createFormInputId ( name , domainIndex , validatorIndex ) }
209- name = { createFormInputName ( name ) }
210- onClick = { this . onColorShow }
211- type = "button"
212- >
213- { label }
214- < span className = { iconClassName } />
215- </ button >
216- { showColorPicker && (
217- < div className = "domain-validator-color-popover" >
218- < div
219- className = "domain-validator-color-cover"
220- id = { createFormInputId ( name , domainIndex , validatorIndex ) }
221- onClick = { this . onColorShow }
222- />
223- < CompactPicker onChangeComplete = { this . onColorChange } color = { color } />
224- </ div >
225- ) }
226- < div className = "domain-color-preview" style = { { backgroundColor : color } } />
227- </ div >
228- ) ;
229- } ;
230-
231154 render ( ) : ReactNode {
232155 const { validatorIndex, expanded, dataType, validator, mvEnabled, domainIndex } = this . props ;
233156
@@ -239,14 +162,14 @@ export class ConditionalFormatOptions extends PureComponent<ConditionalFormatOpt
239162 { expanded && (
240163 < div >
241164 < Filters
242- validatorIndex = { validatorIndex }
243165 domainIndex = { domainIndex }
244- onChange = { this . onFilterChange }
245- type = { type }
246- mvEnabled = { mvEnabled }
247166 expression = { validator . formatFilter }
248- prefix = { DOMAIN_CONDITIONAL_FORMAT_PREFIX }
249167 firstFilterTooltip = { this . firstFilterTooltip ( ) }
168+ mvEnabled = { mvEnabled }
169+ onChange = { this . onFilterChange }
170+ prefix = { DOMAIN_CONDITIONAL_FORMAT_PREFIX }
171+ type = { type }
172+ validatorIndex = { validatorIndex }
250173 />
251174 < div className = "domain-validation-subtitle" > Display Options</ div >
252175 { this . renderDisplayCheckbox ( DOMAIN_VALIDATOR_BOLD , 'Bold' , validator . bold ) }
0 commit comments