Skip to content

Commit afa4b03

Browse files
authored
Merge pull request #61 from OrigenStudio/develop
new release
2 parents e98866c + c6bbe4d commit afa4b03

File tree

6 files changed

+69
-27
lines changed

6 files changed

+69
-27
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "material-ui-layout",
3-
"version": "0.1.0-rc.5",
3+
"version": "0.1.0-rc.6",
44
"description": "Layout components for material-ui",
55
"main": "./lib/index.js",
66
"scripts": {

src/components/Layout/Layout.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import LayoutActions from './LayoutActions';
1616
// FIXME remove once material-ui drawer style is fixed
1717
const isDocked = type => type === 'permanent' || type === 'persistent';
1818

19+
// TODO refactor all smallScreen logic
20+
// TODO smallScreen logic should be named xSmallScreen logic
21+
1922
class Layout extends React.PureComponent {
2023
static propTypes = {
2124
classes: PropTypes.shape({}),
@@ -171,11 +174,15 @@ class Layout extends React.PureComponent {
171174
const leftDrawerContentWithProps = leftDrawerContent
172175
? React.cloneElement(leftDrawerContent, {
173176
closeDrawer: this.handleLeftDrawerClose,
177+
closeDrawerOnClick: smallScreen || leftDrawerType === 'temporary',
178+
...leftDrawerContent.props, // This feels a bit of an antipattern, investigate
174179
})
175180
: leftDrawerContent;
176181
const rightDrawerContentWithProps = rightDrawerContent
177182
? React.cloneElement(rightDrawerContent, {
178183
closeDrawer: this.handleRightDrawerClose,
184+
closeDrawerOnClick: smallScreen || rightDrawerType === 'temporary',
185+
...rightDrawerContent.props, // This feels a bit of an antipattern, investigate
179186
})
180187
: rightDrawerContent;
181188

src/templates/Drawer/BasicDrawer/BasicDrawer.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ class BasicDrawer extends React.PureComponent {
1212
classes: PropTypes.shape({}),
1313
};
1414
render() {
15-
const { links, classes } = this.props;
15+
const {
16+
links,
17+
classes,
18+
closeDrawer,
19+
closeDrawerOnClick = false,
20+
} = this.props;
1621
return (
1722
<div className={classes.wrapper}>
18-
<DrawerItemsList items={links} />
23+
<DrawerItemsList
24+
items={links}
25+
closeDrawer={closeDrawer}
26+
closeDrawerOnClick={closeDrawerOnClick}
27+
/>
1928
</div>
2029
);
2130
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @flow
2+
3+
import React, { PureComponent } from 'react';
4+
import ListItem from '@material-ui/core/ListItem';
5+
import ListItemIcon from '@material-ui/core/ListItemIcon';
6+
import ListItemText from '@material-ui/core/ListItemText';
7+
import Icon from '@material-ui/core/Icon';
8+
9+
type P = {};
10+
11+
class DrawerItem extends PureComponent<P> {
12+
handleClick = () => {
13+
this.props.item.onClick();
14+
this.props.closeDrawer();
15+
};
16+
17+
renderIcon = item => {
18+
if (item.icon) {
19+
return <item.icon />;
20+
} else if (item.iconName) {
21+
return <Icon>{item.iconName}</Icon>;
22+
}
23+
return <Icon>arrow_right</Icon>;
24+
};
25+
26+
render() {
27+
const { item } = this.props;
28+
return (
29+
<ListItem
30+
button
31+
onClick={item.onClick ? this.handleClick : null}
32+
href={item.href || null}
33+
component={item.href ? 'a' : undefined}
34+
>
35+
<ListItemIcon>{this.renderIcon(item)}</ListItemIcon>
36+
<ListItemText primary={item.label} />
37+
</ListItem>
38+
);
39+
}
40+
}
41+
42+
export default DrawerItem;

src/templates/Drawer/DrawerItemsList/DrawerItemsList.jsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import React from 'react';
33
import PropTypes from 'prop-types';
44
import { withStyles } from '@material-ui/core/styles';
55
import List from '@material-ui/core/List';
6-
import ListItem from '@material-ui/core/ListItem';
7-
import ListItemIcon from '@material-ui/core/ListItemIcon';
8-
import ListItemText from '@material-ui/core/ListItemText';
9-
import Icon from '@material-ui/core/Icon';
6+
7+
import DrawerItem from './DrawerItem';
108

119
import styles from './styles';
1210

@@ -16,30 +14,16 @@ class DrawerItemsList extends React.PureComponent {
1614
classes: PropTypes.shape({}),
1715
};
1816

19-
renderIcon = item => {
20-
if (item.icon) {
21-
return <item.icon />;
22-
} else if (item.iconName) {
23-
return <Icon>{item.iconName}</Icon>;
24-
}
25-
return <Icon>arrow_right</Icon>;
26-
};
27-
2817
render() {
29-
const { items, classes } = this.props;
18+
const { items, classes, closeDrawer, closeDrawerOnClick } = this.props;
3019
return (
3120
<List className={classes.list}>
3221
{map(items, item => (
33-
<ListItem
34-
button
22+
<DrawerItem
3523
key={`item-${item.label}`}
36-
onClick={item.onClick || null}
37-
href={item.href || null}
38-
component={item.href ? 'a' : undefined}
39-
>
40-
<ListItemIcon>{this.renderIcon(item)}</ListItemIcon>
41-
<ListItemText primary={item.label} />
42-
</ListItem>
24+
item={item}
25+
closeDrawer={closeDrawerOnClick ? closeDrawer : () => {}}
26+
/>
4327
))}
4428
</List>
4529
);

0 commit comments

Comments
 (0)