Skip to content

Commit 39474ac

Browse files
authored
Merge pull request #11 from Zetoff/feature/making-layout-more-flexible
- improved API - added templates
2 parents 91845fa + 937211d commit 39474ac

File tree

12 files changed

+135
-22
lines changed

12 files changed

+135
-22
lines changed

src/components/NavBar/NavBar.jsx renamed to src/components/AppBar/AppBar.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33
import React from 'react';
44
import PropTypes from 'prop-types';
55
import { withStyles } from 'material-ui/styles';
6-
import AppBar from 'material-ui/AppBar';
6+
import DefaultAppBar from 'material-ui/AppBar';
77

88
import styles from './styles';
99

10-
class NavBar extends React.PureComponent {
10+
class AppBar extends React.PureComponent {
1111
static propTypes = {
12-
classes: PropTypes.shape({}),
1312
children: PropTypes.element,
1413
navbarPostion: PropTypes.string,
1514
color: PropTypes.string,
1615
};
1716

1817
render() {
19-
const { children, navbarPostion, classes, color, ...other } = this.props;
18+
const { children, navbarPostion, color, ...other } = this.props;
2019
return (
21-
<AppBar position={navbarPostion} color={color}>
20+
<DefaultAppBar position={navbarPostion} color={color}>
2221
{React.cloneElement(children, { ...other })}
23-
</AppBar>
22+
</DefaultAppBar>
2423
);
2524
}
2625
}
2726

28-
export default withStyles(styles)(NavBar);
27+
export default withStyles(styles)(AppBar);

src/components/AppBar/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AppBar from './AppBar';
2+
3+
export default AppBar;
File renamed without changes.

src/components/Layout/Layout.jsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ import controllable from 'react-controllables';
77

88
import styles from './styles';
99

10-
import NavBar from '../NavBar';
10+
import AppBar from '../AppBar';
1111
import Footer from '../Footer';
1212

1313
// TODO create Layout Library
1414

1515
class Layout extends React.PureComponent {
1616
static propTypes = {
1717
classes: PropTypes.shape({}),
18+
overrideClasses: PropTypes.shape({}),
1819
children: PropTypes.element.isRequired,
1920
navbarPostion: PropTypes.string,
2021
stickyFooter: PropTypes.bool,
2122
footerContent: PropTypes.element,
22-
navBarContent: PropTypes.element,
23+
appBarContent: PropTypes.element,
2324
drawerOpen: PropTypes.bool.isRequired,
2425
onDrawerOpenChange: PropTypes.func,
2526
drawerContent: PropTypes.element,
26-
navBarProps: PropTypes.shape({}),
27+
appBarProps: PropTypes.shape({}),
2728
drawerProps: PropTypes.shape({}),
2829
footerProps: PropTypes.shape({}),
2930
};
@@ -49,19 +50,22 @@ class Layout extends React.PureComponent {
4950

5051
render() {
5152
const {
52-
classes,
53+
classes: defaultClasses,
54+
overrideClasses,
5355
children,
5456
navbarPostion,
5557
stickyFooter,
5658
footerContent,
57-
navBarContent,
59+
appBarContent,
5860
drawerContent,
5961
drawerOpen,
60-
navBarProps,
62+
appBarProps,
6163
drawerProps,
6264
footerProps,
6365
} = this.props;
6466

67+
const classes = { ...defaultClasses, ...overrideClasses };
68+
6569
const mainClassnames = classNames(
6670
classes.main,
6771
{ [`${classes.mainFixedNavbar}`]: navbarPostion === 'fixed' },
@@ -70,9 +74,9 @@ class Layout extends React.PureComponent {
7074

7175
return (
7276
<div className={classes.layout}>
73-
<NavBar {...navBarProps} onIconClick={this.toggleDrawer}>
74-
{navBarContent}
75-
</NavBar>
77+
<AppBar {...appBarProps} onIconClick={this.toggleDrawer}>
78+
{appBarContent}
79+
</AppBar>
7680
{drawerContent ? (
7781
<Drawer {...drawerProps} open={drawerOpen} onRequestClose={this.handleDrawerClose}>
7882
{drawerContent}

src/components/NavBar/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Layout from './components/Layout';
22

3-
export { default as AppBar } from './components/NavBar';
3+
export { default as AppBar } from './components/AppBar';
44
export { default as Footer } from './components/Footer';
55

6-
// I am changing the name from NavBar to AppBar
7-
export { default as BasicAppBar } from './templates/NavBar/BasicNavBar';
6+
export { default as BasicAppBar } from './templates/AppBar/BasicNavBar';
7+
export { default as TwoRowsAppBar } from './templates/AppBar/TwoRowsAppBar';
88
export { default as BasicFooter } from './templates/Footer/BasicFooter';
99
export { default as BasicDrawer } from './templates/Drawer/BasicDrawer';
1010

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React, { PureComponent } from 'react';
2+
import PropTypes from 'prop-types';
3+
import Toolbar from 'material-ui/Toolbar';
4+
import Grid from 'material-ui/Grid';
5+
import { withStyles } from 'material-ui/styles';
6+
7+
import styles from './styles';
8+
9+
class TwoRowsAppBar extends PureComponent {
10+
static propTypes = {
11+
classes: PropTypes.shape({}),
12+
topLeftContent: PropTypes.oneOf(PropTypes.element, PropTypes.arrayOf(PropTypes.element)),
13+
topCenterContent: PropTypes.oneOf(PropTypes.element, PropTypes.arrayOf(PropTypes.element)),
14+
topRightContent: PropTypes.oneOf(PropTypes.element, PropTypes.arrayOf(PropTypes.element)),
15+
bottomLeftContent: PropTypes.oneOf(PropTypes.element, PropTypes.arrayOf(PropTypes.element)),
16+
bottomCenterContent: PropTypes.oneOf(PropTypes.element, PropTypes.arrayOf(PropTypes.element)),
17+
bottomRightContent: PropTypes.oneOf(PropTypes.element, PropTypes.arrayOf(PropTypes.element)),
18+
};
19+
20+
static defaultProps = {
21+
classes: {},
22+
topLeftContent: null,
23+
topCenterContent: null,
24+
topRightContent: null,
25+
bottomLeftContent: null,
26+
bottomCenterContent: null,
27+
bottomRightContent: null,
28+
}
29+
30+
render() {
31+
const {
32+
classes,
33+
topLeftContent,
34+
topCenterContent,
35+
topRightContent,
36+
bottomLeftContent,
37+
bottomCenterContent,
38+
bottomRightContent,
39+
} = this.props;
40+
return (
41+
<Toolbar>
42+
<Grid container direction="column" className={classes.wrapper}>
43+
<Grid container className={classes.topRow} justify={'space-between'}>
44+
<Grid item xs={2} className={classes.left}>
45+
{topLeftContent}
46+
</Grid>
47+
<Grid item xs={8} className={classes.topCenter}>
48+
{topCenterContent}
49+
</Grid>
50+
<Grid item xs={2} className={classes.right}>
51+
{topRightContent}
52+
</Grid>
53+
</Grid>
54+
<Grid container className={classes.bottomRow} justify={'space-between'}>
55+
<Grid item xs={2} className={classes.left}>
56+
{bottomLeftContent}
57+
</Grid>
58+
<Grid item xs={8} className={classes.bottomCenter}>
59+
{bottomCenterContent}
60+
</Grid>
61+
<Grid item xs={2} className={classes.right}>
62+
{bottomRightContent}
63+
</Grid>
64+
</Grid>
65+
</Grid>
66+
</Toolbar>
67+
);
68+
}
69+
}
70+
71+
export default withStyles(styles)(TwoRowsAppBar);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import TwoRowsAppBar from './TwoRowsAppBar';
2+
3+
export default TwoRowsAppBar;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export default {
2+
wrapper: {
3+
marginTop: '0',
4+
marginBottom: '0',
5+
},
6+
topRow: {
7+
height: '64px',
8+
marginTop: '0',
9+
marginBottom: '0',
10+
},
11+
bottomRow: {
12+
height: '56px',
13+
marginTop: '0',
14+
marginBottom: '0',
15+
},
16+
topCenter:{
17+
textAlign: 'center',
18+
display: 'flex',
19+
justifyContent: 'center',
20+
alignItems: 'center',
21+
},
22+
bottomCenter:{
23+
textAlign: 'center',
24+
display: 'flex',
25+
justifyContent: 'center',
26+
alignItems: 'center',
27+
},
28+
right:{
29+
justifyContent: 'flex-end',
30+
display: 'flex',
31+
},
32+
left:{
33+
justifyContent: 'flex-start',
34+
display: 'flex',
35+
}
36+
};

0 commit comments

Comments
 (0)