forked from thinkcube/react-native-icon-checkbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CheckBox.js
78 lines (72 loc) · 1.83 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
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
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet,
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
export default function CheckBox(props) {
const iconName = props.checked ? props.checkedIconName : props.uncheckedIconName;
const styles = StyleSheet.create({
label: {
fontSize: 16,
},
icon: {
marginLeft: -10,
},
});
function onPress() {
props.onPress(!props.checked);
}
return (
<Icon.Button
{...props}
name={iconName}
size={props.size}
backgroundColor={props.backgroundColor}
color={props.color}
iconStyle={[styles.icon, props.iconStyle, props.checked && props.checkedIconStyle]}
onPress={onPress}
activeOpacity={props.activeOpacity}
underlayColor={props.underlayColor}
borderRadius={props.borderRadius}
>
<Text
style={[styles.label, props.labelStyle]}
>
{props.label}
</Text>
</Icon.Button>
);
}
CheckBox.propTypes = {
size: PropTypes.number,
checked: PropTypes.bool,
label: PropTypes.string,
labelStyle: Text.propTypes.style,
iconStyle: Text.propTypes.style,
checkedIconStyle: Text.propTypes.style,
color: PropTypes.string,
backgroundColor: PropTypes.string,
onPress: PropTypes.func,
underlayColor: PropTypes.string,
activeOpacity: PropTypes.number,
borderRadius: PropTypes.number,
uncheckedIconName: PropTypes.string,
checkedIconName: PropTypes.string,
};
CheckBox.defaultProps = {
size: 30,
checked: false,
labelStyle: {},
iconStyle: {},
checkedIconStyle: {},
color: '#000',
backgroundColor: 'rgba(0,0,0,0)',
underlayColor: 'rgba(0,0,0,0)',
activeOpacity: 1,
borderRadius: 5,
uncheckedIconName: 'check-box-outline-blank',
checkedIconName: 'check-box',
};