Skip to content

Commit bfbe8be

Browse files
committed
improved the Tow Row AppBar
1 parent 0569fe7 commit bfbe8be

File tree

2 files changed

+97
-15
lines changed

2 files changed

+97
-15
lines changed

src/templates/AppBar/TwoRowsAppBar/TwoRowsAppBar.jsx

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ import PropTypes from 'prop-types';
33
import Toolbar from 'material-ui/Toolbar';
44
import Grid from 'material-ui/Grid';
55
import { withStyles } from 'material-ui/styles';
6+
import withWidth, { isWidthDown } from 'material-ui/utils/withWidth';
7+
import classNames from 'classnames';
8+
import compose from 'recompose/compose';
69

710
import styles from './styles';
811

9-
const contentPropType = PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]);
12+
const contentPropType = PropTypes.oneOfType([
13+
PropTypes.element,
14+
PropTypes.arrayOf(PropTypes.element),
15+
]);
16+
17+
// TODO find a way to better overwrite the items styles
18+
const style = {
19+
item: {
20+
padding: '0px',
21+
},
22+
};
1023

1124
class TwoRowsAppBar extends PureComponent {
1225
static propTypes = {
@@ -17,6 +30,8 @@ class TwoRowsAppBar extends PureComponent {
1730
bottomLeftContent: contentPropType,
1831
bottomCenterContent: contentPropType,
1932
bottomRightContent: contentPropType,
33+
width: PropTypes.string,
34+
smallScreenWidth: PropTypes.string,
2035
};
2136

2237
static defaultProps = {
@@ -27,9 +42,9 @@ class TwoRowsAppBar extends PureComponent {
2742
bottomLeftContent: null,
2843
bottomCenterContent: null,
2944
bottomRightContent: null,
45+
smallScreenWidth: 'xs',
3046
};
3147

32-
3348
render() {
3449
const {
3550
classes,
@@ -39,29 +54,94 @@ class TwoRowsAppBar extends PureComponent {
3954
bottomLeftContent,
4055
bottomCenterContent,
4156
bottomRightContent,
57+
width,
58+
smallScreenWidth = 'xs',
4259
} = this.props;
60+
61+
const smallScreen = isWidthDown(smallScreenWidth, width);
62+
4363
return (
4464
<Toolbar>
4565
<Grid container direction="column" className={classes.wrapper}>
46-
<Grid container className={classes.topRow} justify={'space-between'}>
47-
<Grid item xs={2} className={classes.left}>
66+
<Grid
67+
container
68+
className={classNames(classes.row, classes.topRow)}
69+
justify={'space-between'}
70+
>
71+
<Grid
72+
item
73+
style={style.item}
74+
xs={2}
75+
sm={4}
76+
md={3}
77+
lg={2}
78+
className={classes.left}
79+
>
4880
{topLeftContent}
4981
</Grid>
50-
<Grid item xs={8} className={classes.topCenter}>
82+
<Grid
83+
item
84+
style={style.item}
85+
xs={8}
86+
sm={4}
87+
md={6}
88+
lg={8}
89+
className={classNames(classes.topCenter, {
90+
[`${classes.centerBig}`]: !smallScreen,
91+
})}
92+
>
5193
{topCenterContent}
5294
</Grid>
53-
<Grid item xs={2} className={classes.right}>
95+
<Grid
96+
item
97+
style={style.item}
98+
xs={2}
99+
sm={4}
100+
md={3}
101+
lg={2}
102+
className={classes.right}
103+
>
54104
{topRightContent}
55105
</Grid>
56106
</Grid>
57-
<Grid container className={classes.bottomRow} justify={'space-between'}>
58-
<Grid item xs={2} className={classes.left}>
107+
<Grid
108+
container
109+
className={classNames(classes.row, classes.bottomRow)}
110+
justify={'space-between'}
111+
>
112+
<Grid
113+
item
114+
style={style.item}
115+
xs={2}
116+
sm={4}
117+
md={3}
118+
lg={2}
119+
className={classes.left}
120+
>
59121
{bottomLeftContent}
60122
</Grid>
61-
<Grid item xs={8} className={classes.bottomCenter}>
123+
<Grid
124+
item
125+
style={style.item}
126+
xs={8}
127+
sm={4}
128+
md={6}
129+
lg={8}
130+
className={classNames(classes.bottomCenter, {
131+
[`${classes.centerBig}`]: !smallScreen,
132+
})}
133+
>
62134
{bottomCenterContent}
63135
</Grid>
64-
<Grid item xs={2} className={classes.right}>
136+
<Grid
137+
item
138+
style={style.item}
139+
xs={2}
140+
sm={4}
141+
md={3}
142+
lg={2}
143+
className={classes.right}
144+
>
65145
{bottomRightContent}
66146
</Grid>
67147
</Grid>
@@ -71,4 +151,4 @@ class TwoRowsAppBar extends PureComponent {
71151
}
72152
}
73153

74-
export default withStyles(styles)(TwoRowsAppBar);
154+
export default compose(withStyles(styles), withWidth())(TwoRowsAppBar);

src/templates/AppBar/TwoRowsAppBar/styles.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
export default {
1+
export default theme => ({
22
wrapper: {
33
marginTop: '0',
44
marginBottom: '0',
55
},
6+
row: theme.mixins.toolbar,
67
topRow: {
7-
height: '64px',
88
marginTop: '0',
99
marginBottom: '0',
1010
},
1111
bottomRow: {
12-
height: '56px',
1312
marginTop: '0',
1413
marginBottom: '0',
1514
},
@@ -25,6 +24,9 @@ export default {
2524
justifyContent: 'center',
2625
alignItems: 'center',
2726
},
27+
centerBig: {
28+
justifyContent: theme.direction === 'ltr' ? 'flex-start' : 'flex-end',
29+
},
2830
right: {
2931
justifyContent: 'flex-end',
3032
display: 'flex',
@@ -35,4 +37,4 @@ export default {
3537
display: 'flex',
3638
alignItems: 'center',
3739
},
38-
};
40+
});

0 commit comments

Comments
 (0)