Skip to content

Commit b144071

Browse files
juanlopez1navarroaxel
authored andcommitted
feat(components): add Grid component (#7)
1 parent ee54dd2 commit b144071

5 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/components/Col/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {View} from 'react-native';
55
import styles from './styles';
66

77
const Col = ({children, style, size}) => (
8-
<View style={[{flex: size || 1}, styles.col, style]}>
8+
<View style={[{flex: size}, styles.col, style]}>
99
{children}
1010
</View>
1111
);
@@ -21,7 +21,7 @@ Col.propTypes = {
2121
};
2222

2323
Col.defaultProps = {
24-
size: null,
24+
size: 1,
2525
style: {}
2626
};
2727

src/components/Grid/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, {Component} from 'react';
2+
import PropTypes from 'prop-types';
3+
import {View} from 'react-native';
4+
import {some} from 'lodash';
5+
6+
import Row from '../Row';
7+
import styles from './styles';
8+
9+
const isRow = children => some(children, child => child.type === Row);
10+
11+
const Grid = ({children, style}) => (
12+
<View
13+
style={[
14+
isRow(children) ? styles.col : styles.row,
15+
style
16+
]}
17+
>
18+
{children}
19+
</View>
20+
);
21+
22+
Grid.propTypes = {
23+
children: PropTypes.oneOfType([
24+
PropTypes.instanceOf(Component),
25+
PropTypes.func,
26+
PropTypes.array
27+
]).isRequired,
28+
style: PropTypes.shape({})
29+
};
30+
31+
Grid.defaultProps = {
32+
style: {}
33+
};
34+
35+
export default Grid;

src/components/Grid/styles.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {StyleSheet} from 'react-native';
2+
3+
export default StyleSheet.create({
4+
col: {
5+
flex: 1,
6+
flexDirection: 'column'
7+
},
8+
row: {
9+
flex: 1,
10+
flexDirection: 'row'
11+
}
12+
});

src/components/Row/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {View} from 'react-native';
55
import styles from './styles';
66

77
const Row = ({children, style, size}) => (
8-
<View style={[{flex: size || 1}, styles.row, style]}>
8+
<View style={[{flex: size}, styles.row, style]}>
99
{children}
1010
</View>
1111
);
@@ -21,7 +21,7 @@ Row.propTypes = {
2121
};
2222

2323
Row.defaultProps = {
24-
size: null,
24+
size: 1,
2525
style: {}
2626
};
2727

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Button from './components/Button';
22
import Col from './components/Col';
3+
import Grid from './components/Grid';
34
import Header from './components/Header';
45
import LoadingIndicator from './components/LoadingIndicator';
56
import Row from './components/Row';
@@ -12,6 +13,7 @@ export const getFontAwesome = (name, color, size) => ({
1213
});
1314
export {Button};
1415
export {Col};
16+
export {Grid};
1517
export {Header};
1618
export {LoadingIndicator};
1719
export {Row};

0 commit comments

Comments
 (0)