-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathAccordion.js
78 lines (73 loc) · 1.79 KB
/
Accordion.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 React, {Component} from 'react';
import {View, TouchableOpacity, Text, StyleSheet} from 'react-native';
import colors from 'assets/colors';
import Icon from 'react-native-vector-icons/MaterialIcons';
import Checkbox from './Checkbox';
class Accordion extends Component {
constructor(props) {
super(props);
this.state = {
data: props.data,
expanded: false,
};
}
toggleExpand = () => {
this.setState({expanded: !this.state.expanded});
};
render() {
return (
<View>
<TouchableOpacity
style={styles.row}
onPress={() => this.toggleExpand()}>
<View style={styles.checkbox_wrapper}>
{this.props.withCheckbox && (
<Checkbox
text={''}
onPress={this.props.onPress}
selected={this.props.checkboxSelected}
/>
)}
<Text style={[styles.title, styles.font]}>{this.props.title}</Text>
</View>
<Icon
name={
this.state.expanded ? 'keyboard-arrow-up' : 'keyboard-arrow-down'
}
color={colors.gray_icon}
size={24}
/>
</TouchableOpacity>
<View style={styles.parentHr} />
{this.state.expanded && (
<View style={styles.child}>{this.props.children}</View>
)}
</View>
);
}
}
const styles = StyleSheet.create({
title: {
fontSize: 16,
lineHeight: 24,
},
checkbox_wrapper: {
flexDirection: 'row',
},
row: {
flexDirection: 'row',
justifyContent: 'space-between',
height: 56,
paddingLeft: 20,
paddingRight: 18,
alignItems: 'center',
},
parentHr: {
height: 1,
width: '100%',
},
child: {
paddingHorizontal: 25,
},
});
export default Accordion;