forked from react-native-elements/react-native-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckBox.js
More file actions
107 lines (101 loc) · 2.6 KB
/
CheckBox.js
File metadata and controls
107 lines (101 loc) · 2.6 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React from 'react'
import { StyleSheet, TouchableOpacity, View, Platform } from 'react-native'
import Text from '../text/Text'
import fonts from '../config/fonts'
import colors from '../config/colors'
import FAIcon from 'react-native-vector-icons/FontAwesome'
import getIconType from '../helpers/getIconType'
let styles = {}
const CheckBox = ({component, checked, iconRight, title, center, right, containerStyle, textStyle, onPress, onLongPress, checkedIcon, uncheckedIcon, iconType, checkedColor, uncheckedColor, checkedTitle, fontFamily}) => {
let Icon = FAIcon
if (iconType) {
Icon = getIconType(iconType)
}
const Component = component || TouchableOpacity
let iconName = uncheckedIcon
if (checked) {
iconName = checkedIcon
}
return (
<Component
onLongPress={onLongPress}
onPress={onPress}
style={[
styles.container,
containerStyle && containerStyle
]}>
<View style={[
styles.wrapper,
right && {justifyContent: 'flex-end'},
center && {justifyContent: 'center'}
]}>
{
!iconRight && (
<Icon
color={checked ? checkedColor : uncheckedColor}
name={iconName}
size={24} />
)
}
<Text style={[
styles.text,
textStyle && textStyle,
fontFamily && {fontFamily}
]}>
{checked ? checkedTitle || title : title}
</Text>
{
iconRight && (
<Icon
color={checked ? checkedColor : uncheckedColor}
name={iconName}
size={24} />
)
}
</View>
</Component>
)
}
CheckBox.defaultProps = {
checked: false,
iconRight: false,
right: false,
center: false,
checkedColor: 'green',
uncheckedColor: '#bfbfbf',
checkedIcon: 'check-square-o',
uncheckedIcon: 'square-o'
}
// CheckBox.propTypes = {
// component, checked, iconRight, title, center, containerStyle, textStyle, onPress, checkedIcon, uncheckedIcon, iconType, checkedColor, uncheckedColor, checkedTitle
// }
styles = StyleSheet.create({
wrapper: {
flexDirection: 'row',
alignItems: 'center'
},
container: {
margin: 5,
marginLeft: 10,
marginRight: 10,
backgroundColor: '#fafafa',
borderColor: '#ededed',
borderWidth: 1,
padding: 10,
borderRadius: 3
},
text: {
marginLeft: 10,
marginRight: 10,
color: colors.grey1,
...Platform.select({
ios: {
fontWeight: 'bold'
},
android: {
fontFamily: fonts.android.bold
}
})
}
})
export default CheckBox