@@ -19,15 +19,22 @@ import Text from '../text';
19
19
import TouchableOpacity from '../touchableOpacity' ;
20
20
21
21
const DEFAULT_COLOR_BY_STATE = {
22
- default : Colors . dark40 ,
23
- focus : Colors . blue30 ,
24
- error : Colors . red30
22
+ default : Colors . grey10 ,
23
+ focus : Colors . grey10 ,
24
+ error : Colors . grey10 ,
25
+ disabled : Colors . grey50
25
26
} ;
26
27
const DEFAULT_UNDERLINE_COLOR_BY_STATE = {
27
- default : Colors . dark70 ,
28
+ default : Colors . grey50 ,
28
29
focus : Colors . blue30 ,
29
30
error : Colors . red30
30
31
} ;
32
+
33
+ const DEFAULT_PLACEHOLDER_COLOR_BY_STATE = {
34
+ default : Colors . grey30 ,
35
+ focus : Colors . blue30
36
+ } ;
37
+
31
38
const LABEL_TYPOGRAPHY = Typography . text80 ;
32
39
const ICON_SIZE = 24 ;
33
40
const ICON_RIGHT_PADDING = 3 ;
@@ -52,7 +59,7 @@ export default class TextField extends BaseInput {
52
59
*/
53
60
floatingPlaceholder : PropTypes . bool ,
54
61
/**
55
- * floating placeholder color as a string or object of states, ex. {default: 'black', error: 'red', focus: 'blue'}
62
+ * floating placeholder color as a string or object of states, ex. {default: 'black', error: 'red', focus: 'blue', disabled: 'grey' }
56
63
*/
57
64
floatingPlaceholderColor : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
58
65
/**
@@ -65,7 +72,7 @@ export default class TextField extends BaseInput {
65
72
*/
66
73
hideUnderline : PropTypes . bool ,
67
74
/**
68
- * underline color as a string or object of states, ex. {default: 'black', error: 'red', focus: 'blue'}
75
+ * underline color as a string or object of states, ex. {default: 'black', error: 'red', focus: 'blue', disabled: 'grey' }
69
76
*/
70
77
underlineColor : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
71
78
/**
@@ -115,7 +122,7 @@ export default class TextField extends BaseInput {
115
122
*/
116
123
title : PropTypes . string ,
117
124
/**
118
- * The title's color as a string or object of states, ex. {default: 'black', error: 'red', focus: 'blue'}
125
+ * The title's color as a string or object of states, ex. {default: 'black', error: 'red', focus: 'blue', disabled: 'grey' }
119
126
*/
120
127
titleColor : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
121
128
/**
@@ -225,34 +232,28 @@ export default class TextField extends BaseInput {
225
232
return text ;
226
233
}
227
234
228
- getStateColor ( colorProp , isUnderline ) {
235
+ getStateColor ( colorProp = { } ) {
229
236
const { focused} = this . state ;
230
- const { disabledColor} = this . getThemeProps ( ) ;
231
237
const error = this . getErrorMessage ( ) ;
232
- const colorByState = _ . cloneDeep ( isUnderline ? DEFAULT_UNDERLINE_COLOR_BY_STATE : DEFAULT_COLOR_BY_STATE ) ;
233
-
234
- if ( this . isDisabled ( ) && disabledColor ) {
235
- return disabledColor ;
236
- }
238
+ const { disabledColor} = this . getThemeProps ( ) ;
237
239
238
- if ( colorProp ) {
239
- if ( _ . isString ( colorProp ) ) {
240
- // use given color for any state
241
- return colorProp ;
242
- } else if ( _ . isObject ( colorProp ) ) {
243
- // set given colors by states
244
- _ . merge ( colorByState , colorProp ) ;
240
+ if ( _ . isString ( colorProp ) ) {
241
+ return colorProp || Colors . dark10 ;
242
+ } else if ( _ . isPlainObject ( colorProp ) ) {
243
+ const mergedColorState = { ...DEFAULT_COLOR_BY_STATE , ...colorProp } ;
244
+
245
+ if ( this . isDisabled ( ) ) {
246
+ return disabledColor || mergedColorState . disabled ;
247
+ } else if ( error ) {
248
+ return mergedColorState . error ;
249
+ } else if ( focused ) {
250
+ return mergedColorState . focus ;
251
+ } else {
252
+ return mergedColorState . default ;
245
253
}
246
254
}
247
255
248
- // return the right color for the current state
249
- let color = colorByState . default ;
250
- if ( error && isUnderline ) {
251
- color = colorByState . error ;
252
- } else if ( focused ) {
253
- color = colorByState . focus ;
254
- }
255
- return color ;
256
+ return colorProp || Colors . dark10 ;
256
257
}
257
258
258
259
getCharCount ( ) {
@@ -330,7 +331,7 @@ export default class TextField extends BaseInput {
330
331
const { expandable, placeholder, placeholderTextColor, floatingPlaceholderColor, multiline}
331
332
= this . getThemeProps ( ) ;
332
333
const typography = this . getTypography ( ) ;
333
- const placeholderColor = this . getStateColor ( placeholderTextColor || DEFAULT_COLOR_BY_STATE . default ) ;
334
+ const placeholderColor = this . getStateColor ( placeholderTextColor || DEFAULT_PLACEHOLDER_COLOR_BY_STATE . default ) ;
334
335
335
336
if ( this . shouldFakePlaceholder ( ) ) {
336
337
return (
@@ -351,7 +352,7 @@ export default class TextField extends BaseInput {
351
352
} ) ,
352
353
color : floatingPlaceholderState . interpolate ( {
353
354
inputRange : [ 0 , 1 ] ,
354
- outputRange : [ placeholderColor , this . getStateColor ( floatingPlaceholderColor ) ]
355
+ outputRange : [ placeholderColor , this . getStateColor ( floatingPlaceholderColor || DEFAULT_PLACEHOLDER_COLOR_BY_STATE ) ]
355
356
} ) ,
356
357
lineHeight : this . shouldFloatPlaceholder ( ) ? LABEL_TYPOGRAPHY . lineHeight : typography . lineHeight
357
358
}
@@ -369,7 +370,7 @@ export default class TextField extends BaseInput {
369
370
370
371
renderTitle ( ) {
371
372
const { floatingPlaceholder, title, titleColor, titleStyle} = this . getThemeProps ( ) ;
372
- const color = this . getStateColor ( titleColor ) ;
373
+ const color = this . getStateColor ( titleColor || DEFAULT_PLACEHOLDER_COLOR_BY_STATE ) ;
373
374
374
375
if ( ! floatingPlaceholder && title ) {
375
376
return < Text style = { [ { color} , this . styles . topLabel , this . styles . label , titleStyle ] } > { title } </ Text > ;
@@ -501,7 +502,7 @@ export default class TextField extends BaseInput {
501
502
] ;
502
503
503
504
const placeholderText = this . getPlaceholderText ( ) ;
504
- const placeholderColor = this . getStateColor ( placeholderTextColor || DEFAULT_COLOR_BY_STATE . default ) ;
505
+ const placeholderColor = this . getStateColor ( placeholderTextColor || DEFAULT_PLACEHOLDER_COLOR_BY_STATE . default ) ;
505
506
const isEditable = ! this . isDisabled ( ) && ! expandable ;
506
507
507
508
return (
@@ -562,7 +563,7 @@ export default class TextField extends BaseInput {
562
563
563
564
render ( ) {
564
565
const { expandable, containerStyle, underlineColor, useTopErrors, hideUnderline} = this . getThemeProps ( ) ;
565
- const underlineStateColor = this . getStateColor ( underlineColor , true ) ;
566
+ const underlineStateColor = this . getStateColor ( underlineColor || DEFAULT_UNDERLINE_COLOR_BY_STATE ) ;
566
567
567
568
return (
568
569
< View style = { [ this . styles . container , containerStyle ] } collapsable = { false } >
0 commit comments