Skip to content

Commit

Permalink
Merge pull request #61 from OrigenStudio/develop
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
PolGuixe authored Jun 16, 2018
2 parents e98866c + c6bbe4d commit afa4b03
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "material-ui-layout",
"version": "0.1.0-rc.5",
"version": "0.1.0-rc.6",
"description": "Layout components for material-ui",
"main": "./lib/index.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/components/Layout/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import LayoutActions from './LayoutActions';
// FIXME remove once material-ui drawer style is fixed
const isDocked = type => type === 'permanent' || type === 'persistent';

// TODO refactor all smallScreen logic
// TODO smallScreen logic should be named xSmallScreen logic

class Layout extends React.PureComponent {
static propTypes = {
classes: PropTypes.shape({}),
Expand Down Expand Up @@ -171,11 +174,15 @@ class Layout extends React.PureComponent {
const leftDrawerContentWithProps = leftDrawerContent
? React.cloneElement(leftDrawerContent, {
closeDrawer: this.handleLeftDrawerClose,
closeDrawerOnClick: smallScreen || leftDrawerType === 'temporary',
...leftDrawerContent.props, // This feels a bit of an antipattern, investigate
})
: leftDrawerContent;
const rightDrawerContentWithProps = rightDrawerContent
? React.cloneElement(rightDrawerContent, {
closeDrawer: this.handleRightDrawerClose,
closeDrawerOnClick: smallScreen || rightDrawerType === 'temporary',
...rightDrawerContent.props, // This feels a bit of an antipattern, investigate
})
: rightDrawerContent;

Expand Down
13 changes: 11 additions & 2 deletions src/templates/Drawer/BasicDrawer/BasicDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ class BasicDrawer extends React.PureComponent {
classes: PropTypes.shape({}),
};
render() {
const { links, classes } = this.props;
const {
links,
classes,
closeDrawer,
closeDrawerOnClick = false,
} = this.props;
return (
<div className={classes.wrapper}>
<DrawerItemsList items={links} />
<DrawerItemsList
items={links}
closeDrawer={closeDrawer}
closeDrawerOnClick={closeDrawerOnClick}
/>
</div>
);
}
Expand Down
42 changes: 42 additions & 0 deletions src/templates/Drawer/DrawerItemsList/DrawerItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @flow

import React, { PureComponent } from 'react';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Icon from '@material-ui/core/Icon';

type P = {};

class DrawerItem extends PureComponent<P> {
handleClick = () => {
this.props.item.onClick();
this.props.closeDrawer();
};

renderIcon = item => {
if (item.icon) {
return <item.icon />;
} else if (item.iconName) {
return <Icon>{item.iconName}</Icon>;
}
return <Icon>arrow_right</Icon>;
};

render() {
const { item } = this.props;
return (
<ListItem
button
onClick={item.onClick ? this.handleClick : null}
href={item.href || null}
component={item.href ? 'a' : undefined}
>
<ListItemIcon>{this.renderIcon(item)}</ListItemIcon>
<ListItemText primary={item.label} />
</ListItem>
);
}
}

export default DrawerItem;
30 changes: 7 additions & 23 deletions src/templates/Drawer/DrawerItemsList/DrawerItemsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Icon from '@material-ui/core/Icon';

import DrawerItem from './DrawerItem';

import styles from './styles';

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

renderIcon = item => {
if (item.icon) {
return <item.icon />;
} else if (item.iconName) {
return <Icon>{item.iconName}</Icon>;
}
return <Icon>arrow_right</Icon>;
};

render() {
const { items, classes } = this.props;
const { items, classes, closeDrawer, closeDrawerOnClick } = this.props;
return (
<List className={classes.list}>
{map(items, item => (
<ListItem
button
<DrawerItem
key={`item-${item.label}`}
onClick={item.onClick || null}
href={item.href || null}
component={item.href ? 'a' : undefined}
>
<ListItemIcon>{this.renderIcon(item)}</ListItemIcon>
<ListItemText primary={item.label} />
</ListItem>
item={item}
closeDrawer={closeDrawerOnClick ? closeDrawer : () => {}}
/>
))}
</List>
);
Expand Down

0 comments on commit afa4b03

Please sign in to comment.