@@ -15,6 +15,9 @@ const DEFAULT_COLOR = Colors.blue30;
1515const DEFAULT_ICON_COLOR = Colors . white ;
1616const DEFAULT_DISABLED_COLOR = Colors . grey50 ;
1717
18+ const DEFAULT_BORDER_WIDTH = 2 ;
19+ const DEFAULT_BORDER_RADIUS = 8 ;
20+
1821export interface CheckboxProps extends TouchableOpacityProps {
1922 /**
2023 * 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 {
3235 * The Checkbox color
3336 */
3437 color ?: string ;
38+ /**
39+ * alternative Checkbox outline style
40+ */
41+ outline ?: boolean ;
3542 /**
3643 * The size of the checkbox. affect both width and height
3744 */
@@ -158,14 +165,24 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
158165 }
159166 } ;
160167
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+ } ;
165182
166183 getBorderStyle ( ) {
167184 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 ] ;
169186
170187 return borderStyle ;
171188 }
@@ -185,14 +202,17 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
185202 >
186203 {
187204 < 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+ ] }
189210 >
190211 < Animated . Image
191212 style = { [
192213 this . styles . selectedIcon ,
193- color && { tintColor : iconColor } ,
194214 { transform : this . animationStyle . transform } ,
195- disabled && { tintColor : DEFAULT_ICON_COLOR }
215+ { tintColor : this . getTintColor ( ) }
196216 ] }
197217 source = { selectedIcon || Assets . icons . checkSmall }
198218 testID = { `${ testID } .selected` }
@@ -219,13 +239,18 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
219239}
220240
221241function 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 ;
223248
224249 return StyleSheet . create ( {
225250 container : {
226251 width : size ,
227252 height : size ,
228- borderRadius : borderRadius || 8 ,
253+ borderRadius : borderRadius ,
229254 alignItems : 'center' ,
230255 justifyContent : 'center' ,
231256 borderColor : color
0 commit comments