-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
112 lines (96 loc) · 2.46 KB
/
index.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
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
108
109
110
111
112
import React, { Component } from 'react';
import { View, TouchableOpacity, StyleSheet } from 'react-native';
import ScalableText from 'react-native-text';
import PropTypes from 'prop-types';
// Default Colors
const TOUCH_COLOR = '#97a0b1';
const ACTIVE_COLOR = '#016bd8';
const ACTIVE_TEXT_COLOR = '#FFFFFF';
const DISABLED_COLOR = '#EDEDED';
const DISABLED_TEXT_COLOR = '#8a8ca3';
class RadioButtons extends Component {
render() {
const {
selected,
options,
touchableStyle,
activeStyle,
disableStyle,
activeTextStyle,
disableTextStyle
} = this.props;
return (
<View style={Styles.container}>
{options.map(({ label, value, disabled }, i) => {
const isSelected = selected === value;
const touchStyle = disabled
? disableStyle
: isSelected && activeStyle;
const textStyle = disabled
? disableTextStyle
: isSelected && activeTextStyle;
return (
<TouchableOpacity
key={i}
style={[Styles.touchable, touchableStyle, touchStyle]}
onPress={() => this.props.onPress(value)}
disabled={disabled}
>
<ScalableText style={[Styles.touchableText, textStyle]}>
{label}
</ScalableText>
</TouchableOpacity>
);
})}
</View>
);
}
}
RadioButtons.propTypes = {
selected: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
options: PropTypes.array,
// Styles
touchableStyle: PropTypes.object,
activeStyle: PropTypes.object,
disableStyle: PropTypes.object,
activeTextStyle: PropTypes.object,
disableTextStyle: PropTypes.object
};
RadioButtons.defaultProps = {
selected: null,
options: [],
activeStyle: {
backgroundColor: ACTIVE_COLOR,
borderColor: ACTIVE_COLOR
},
disableStyle: {
backgroundColor: DISABLED_COLOR,
borderColor: DISABLED_COLOR
},
activeTextStyle: {
color: ACTIVE_TEXT_COLOR
},
disableTextStyle: {
color: DISABLED_TEXT_COLOR
}
};
const Styles = StyleSheet.create({
container: {
flexDirection: 'row'
},
touchable: {
borderWidth: 1,
borderColor: TOUCH_COLOR,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 15,
paddingVertical: 10,
borderRadius: 3,
minWidth: 75,
marginRight: 10
},
touchableText: {
color: TOUCH_COLOR
}
});
export default RadioButtons;