forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.js
More file actions
100 lines (91 loc) · 2.79 KB
/
Checkbox.js
File metadata and controls
100 lines (91 loc) · 2.79 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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TouchableOpacity } from 'react-native';
import IconNB from 'react-native-vector-icons/Ionicons';
import { connectStyle } from 'native-base-shoutem-theme';
import mapPropsToStyleNames from '../utils/mapPropsToStyleNames';
import variable from '../theme/variables/platform';
import { PLATFORM } from '../theme/variables/commonColor';
import computeProps from '../utils/computeProps';
class CheckBox extends Component {
static contextTypes = {
theme: PropTypes.object
};
getInitialStyle(variables) {
const { color, checked, checkboxType, borderColor } = this.props;
return {
checkStyle: {
borderRadius: this.getBorderRadius(checkboxType, variables),
borderColor: borderColor || color || variables.checkboxBgColor,
backgroundColor:
checked === true
? color || variables.checkboxBgColor
: variables.checkboxDefaultColor
}
};
}
// eslint-disable-next-line class-methods-use-this
getBorderRadius(checkboxType, variables) {
if (checkboxType === 'rounded') {
return 13;
}
if (checkboxType === 'square') {
return 0;
}
return variables.CheckboxRadius;
}
prepareRootProps(variables) {
const defaultProps = {
style: this.getInitialStyle(variables).checkStyle
};
return computeProps(this.props, defaultProps);
}
render() {
const { checked, tickColor } = this.props;
const variables = this.context.theme
? this.context.theme['@@shoutem.theme/themeStyle'].variables
: variable;
const platformStyle = variables.platformStyle;
const platform = variables.platform;
return (
<TouchableOpacity
ref={c => (this._root = c)}
{...this.prepareRootProps(variables)}
>
<IconNB
style={{
color:
checked === true
? tickColor || variables.checkboxTickColor
: variables.checkboxDefaultColor,
fontSize: variables.CheckboxFontSize,
lineHeight: variables.CheckboxIconSize,
marginTop: variables.CheckboxIconMarginTop,
textShadowRadius: variables.checkboxTextShadowRadius
}}
name={
platform === PLATFORM.IOS && platformStyle !== PLATFORM.MATERIAL
? 'ios-checkmark'
: 'md-checkmark'
}
/>
</TouchableOpacity>
);
}
}
CheckBox.propTypes = {
...TouchableOpacity.propTypes,
style: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
PropTypes.array
]),
checked: PropTypes.bool,
onPress: PropTypes.func
};
const StyledCheckBox = connectStyle(
'NativeBase.CheckBox',
{},
mapPropsToStyleNames
)(CheckBox);
export { StyledCheckBox as CheckBox };