forked from vincentsylo/react-native-checkbox-field
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckbox.js
46 lines (38 loc) · 1.19 KB
/
Checkbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* @flow */
'use strict';
import React from 'react';
import PropTypes from 'prop-types';
import { TouchableOpacity, StyleSheet } from 'react-native';
import Styles from './Styles';
const Checkbox = (props) => {
let backgroundColor = {
backgroundColor: props.disabled ? props.disabledColor :
props.selected ? props.selectedColor : props.defaultColor
};
return (
<TouchableOpacity disabled={props.disabled} style={[props.checkboxStyle, backgroundColor, styles.center]} onPress={props.onSelect}>
{ props.children }
</TouchableOpacity>
)
};
const styles = StyleSheet.create({
center: {
justifyContent: 'center',
alignItems: 'center'
}
});
Checkbox.propTypes = {
children: PropTypes.element,
defaultColor: PropTypes.string,
selectedColor: PropTypes.string,
selected: PropTypes.bool,
disabled: PropTypes.bool,
onSelect: PropTypes.func.isRequired,
checkboxStyle: PropTypes.oneOfType([ PropTypes.number, PropTypes.object, PropTypes.array ])
};
Checkbox.defaultProps = {
checkboxStyle: Styles.checkboxStyle,
defaultColor: Styles.defaultColor,
selectedColor: Styles.selectedColor
};
export default Checkbox;