@@ -15,6 +15,9 @@ const DEFAULT_COLOR = Colors.blue30;
15
15
const DEFAULT_ICON_COLOR = Colors . white ;
16
16
const DEFAULT_DISABLED_COLOR = Colors . grey50 ;
17
17
18
+ const DEFAULT_BORDER_WIDTH = 2 ;
19
+ const DEFAULT_BORDER_RADIUS = 8 ;
20
+
18
21
export interface CheckboxProps extends TouchableOpacityProps {
19
22
/**
20
23
* The value of the Checkbox. If true the switch will be turned on. Default value is false.
@@ -32,6 +35,10 @@ export interface CheckboxProps extends TouchableOpacityProps {
32
35
* The Checkbox color
33
36
*/
34
37
color ?: string ;
38
+ /**
39
+ * alternative Checkbox outline style
40
+ */
41
+ outline ?: boolean ;
35
42
/**
36
43
* The size of the checkbox. affect both width and height
37
44
*/
@@ -158,14 +165,24 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
158
165
}
159
166
} ;
160
167
161
- getColor ( ) {
162
- const { color, disabled} = this . props ;
163
- return disabled ? DEFAULT_DISABLED_COLOR : color || DEFAULT_COLOR ;
164
- }
168
+ getColor = ( ) => ( this . props . disabled ? DEFAULT_DISABLED_COLOR : this . props . color || DEFAULT_COLOR ) ;
169
+
170
+ getBackgroundColor = ( ) => ( this . props . outline ? 'transparent' : this . getColor ( ) ) ;
171
+
172
+ getTintColor = ( ) => {
173
+ const { outline, disabled, iconColor} = this . props ;
174
+ if ( outline ) {
175
+ if ( disabled ) return DEFAULT_DISABLED_COLOR ;
176
+ else return iconColor || DEFAULT_COLOR ;
177
+ } else {
178
+ if ( disabled ) return Colors . white ;
179
+ else return iconColor || Colors . white ;
180
+ }
181
+ } ;
165
182
166
183
getBorderStyle ( ) {
167
184
const borderColor = { borderColor : this . getColor ( ) } ;
168
- const borderStyle = [ this . styles . container , { borderWidth : 2 } , borderColor ] ;
185
+ const borderStyle = [ this . styles . container , { borderWidth : DEFAULT_BORDER_WIDTH } , borderColor ] ;
169
186
170
187
return borderStyle ;
171
188
}
@@ -185,14 +202,17 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
185
202
>
186
203
{
187
204
< Animated . View
188
- style = { [ this . styles . container , { backgroundColor : this . getColor ( ) } , { opacity : this . animationStyle . opacity } ] }
205
+ style = { [
206
+ this . styles . container ,
207
+ { opacity : this . animationStyle . opacity } ,
208
+ { backgroundColor : this . getBackgroundColor ( ) }
209
+ ] }
189
210
>
190
211
< Animated . Image
191
212
style = { [
192
213
this . styles . selectedIcon ,
193
- color && { tintColor : iconColor } ,
194
214
{ transform : this . animationStyle . transform } ,
195
- disabled && { tintColor : DEFAULT_ICON_COLOR }
215
+ { tintColor : this . getTintColor ( ) }
196
216
] }
197
217
source = { selectedIcon || Assets . icons . checkSmall }
198
218
testID = { `${ testID } .selected` }
@@ -219,13 +239,18 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
219
239
}
220
240
221
241
function createStyles ( props : CheckboxProps ) {
222
- const { color = DEFAULT_COLOR , iconColor = DEFAULT_ICON_COLOR , size = DEFAULT_SIZE , borderRadius} = props ;
242
+ const {
243
+ color = DEFAULT_COLOR ,
244
+ iconColor = DEFAULT_ICON_COLOR ,
245
+ size = DEFAULT_SIZE ,
246
+ borderRadius = DEFAULT_BORDER_RADIUS
247
+ } = props ;
223
248
224
249
return StyleSheet . create ( {
225
250
container : {
226
251
width : size ,
227
252
height : size ,
228
- borderRadius : borderRadius || 8 ,
253
+ borderRadius : borderRadius ,
229
254
alignItems : 'center' ,
230
255
justifyContent : 'center' ,
231
256
borderColor : color
0 commit comments