-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathSection.js
71 lines (58 loc) · 2.2 KB
/
Section.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
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import Text from './Text';
import styles from '../styles/styles';
import MenuItemList from './MenuItemList';
import Icon from './Icon';
import menuItemPropTypes from './menuItemPropTypes';
const propTypes = {
/** An array of props that are pass to individual MenuItem components */
menuItems: PropTypes.arrayOf(PropTypes.shape(menuItemPropTypes)),
/** The text to display in the title of the section */
title: PropTypes.string.isRequired,
/** The icon to display along with the title */
icon: PropTypes.func,
/** Icon component */
IconComponent: PropTypes.func,
/** Contents to display inside the section */
children: PropTypes.node,
/** Customize the Section container */
// eslint-disable-next-line react/forbid-prop-types
containerStyles: PropTypes.arrayOf(PropTypes.object),
};
const defaultProps = {
menuItems: null,
children: null,
icon: null,
IconComponent: null,
containerStyles: [],
};
const Section = (props) => {
const IconComponent = props.IconComponent;
return (
<>
<View style={[styles.pageWrapper, styles.cardSection, ...props.containerStyles]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.w100]}>
<View style={[styles.flexShrink1]}>
<Text style={[styles.textHeadline]}>{props.title}</Text>
</View>
<View style={[styles.flexGrow1, styles.flexRow, styles.justifyContentEnd]}>
{props.icon && <Icon src={props.icon} height={68} width={68} />}
{IconComponent && <IconComponent />}
</View>
</View>
<View style={[styles.w100]}>
{props.children}
</View>
<View style={[styles.w100]}>
{props.menuItems && <MenuItemList menuItems={props.menuItems} />}
</View>
</View>
</>
);
};
Section.displayName = 'Section';
Section.propTypes = propTypes;
Section.defaultProps = defaultProps;
export default Section;