Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ListItemAvatar] Fix & refactor #6540

Merged
merged 1 commit into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions docs/src/pages/component-demos/lists/InteractiveList.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,11 @@ class InteractiveList extends Component {
<List dense={dense}>
{generate((
<ListItem button>
{dense ? (
<ListItemAvatar>
<Avatar>
<FolderIcon />
</Avatar>
</ListItemAvatar>
) : (
<ListItemAvatar>
<Avatar>
<FolderIcon />
</Avatar>
)}
</ListItemAvatar>
<ListItemText
primary="Single-line item"
secondary={secondary ? 'Secondary text' : null}
Expand All @@ -145,17 +139,11 @@ class InteractiveList extends Component {
<List dense={dense}>
{generate((
<ListItem button>
{dense ? (
<ListItemAvatar>
<Avatar>
<FolderIcon />
</Avatar>
</ListItemAvatar>
) : (
<ListItemAvatar>
<Avatar>
<FolderIcon />
</Avatar>
)}
</ListItemAvatar>
<ListItemText
primary="Single-line item"
secondary={secondary ? 'Secondary text' : null}
Expand Down
2 changes: 1 addition & 1 deletion src/Avatar/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Avatar.propTypes = {
/**
* @ignore
* The className of the child element.
* Used by Chip to style the Avatar icon.
* Used by Chip and ListItemIcon to style the Avatar icon.
*/
childrenClassName: PropTypes.string,
/**
Expand Down
27 changes: 20 additions & 7 deletions src/List/ListItemAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import customPropTypes from '../utils/customPropTypes';

export const styleSheet = createStyleSheet('MuiListItemAvatar', () => {
return {
dense: {
height: 32,
marginRight: 8,
width: 32,
denseAvatar: {
width: 36,
height: 36,
fontSize: 18,
marginRight: 4,
},
denseAvatarIcon: {
width: 20,
height: 20,
},
};
});
Expand All @@ -26,9 +31,9 @@ export const styleSheet = createStyleSheet('MuiListItemAvatar', () => {
* ```
*/
export default function ListItemAvatar(props, context) {
if (!context.dense) {
if (context.dense === undefined) {
warning(false, `Material-UI: <ListItemAvatar> is a simple wrapper to apply the dense styles
to Avatar. You do not need it.`);
to <Avatar>. You do not need it unless you are controlling the <List> dense property.`);
return props.children;
}

Expand All @@ -40,7 +45,15 @@ export default function ListItemAvatar(props, context) {
const classes = context.styleManager.render(styleSheet);

return React.cloneElement(children, {
className: classNames(classes.dense, classNameProp, children.props.className),
className: classNames(
{ [classes.denseAvatar]: context.dense },
classNameProp,
children.props.className,
),
childrenClassName: classNames(
{ [classes.denseAvatarIcon]: context.dense },
children.props.childrenClassName,
),
...other,
});
}
Expand Down
12 changes: 7 additions & 5 deletions src/List/ListItemAvatar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
import { assert } from 'chai';
import { createShallow } from 'src/test-utils';
import ListItemAvatar, { styleSheet } from './ListItemAvatar';
import Avatar from '../Avatar';

describe('<ListItemAvatar />', () => {
let shallow;
Expand All @@ -15,23 +16,23 @@ describe('<ListItemAvatar />', () => {
classes = shallow.context.styleManager.render(styleSheet);
});

it('should render a span', () => {
it('should render an Avatar', () => {
const wrapper = shallow((
<ListItemAvatar>
<span />
<Avatar />
</ListItemAvatar>
), {
context: {
dense: true,
},
});
assert.strictEqual(wrapper.is('span'), true, 'should be a span');
assert.strictEqual(wrapper.is('Avatar'), true, 'should be an Avatar');
});

it('should render with the user and root classes', () => {
const wrapper = shallow((
<ListItemAvatar className="foo">
<span className="bar" />
<Avatar className="bar" />
</ListItemAvatar>
), {
context: {
Expand All @@ -40,6 +41,7 @@ describe('<ListItemAvatar />', () => {
});
assert.strictEqual(wrapper.hasClass('foo'), true, 'should have the "foo" class');
assert.strictEqual(wrapper.hasClass('bar'), true, 'should have the "bar" class');
assert.strictEqual(wrapper.hasClass(classes.dense), true, 'should have the dense class');
assert.strictEqual(wrapper.hasClass(classes.denseAvatar), true,
'should have the denseAvatar class');
});
});
4 changes: 2 additions & 2 deletions src/styles/MuiThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const MUI_SHEET_ORDER = [
'MuiAppBar',
'MuiDrawer',

'MuiAvatar',

'MuiListItem',
'MuiListItemText',
'MuiListItemSecondaryAction',
Expand All @@ -71,8 +73,6 @@ export const MUI_SHEET_ORDER = [
'MuiMenu',
'MuiMenuItem',

'MuiAvatar',

'MuiCardContent',
'MuiCardMedia',
'MuiCardActions',
Expand Down