diff --git a/docs/src/pages/demos/app-bar/BottomAppBar.js b/docs/src/pages/demos/app-bar/BottomAppBar.js index 941122a26ee0dd..7e209a24623cff 100644 --- a/docs/src/pages/demos/app-bar/BottomAppBar.js +++ b/docs/src/pages/demos/app-bar/BottomAppBar.js @@ -9,6 +9,7 @@ import Paper from '@material-ui/core/Paper'; import Fab from '@material-ui/core/Fab'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import ListItemText from '@material-ui/core/ListItemText'; import ListSubheader from '@material-ui/core/ListSubheader'; import Avatar from '@material-ui/core/Avatar'; @@ -111,7 +112,9 @@ function BottomAppBar() { {id === 1 && Today} {id === 3 && Yesterday} - + + + diff --git a/docs/src/pages/demos/app-bar/BottomAppBar.tsx b/docs/src/pages/demos/app-bar/BottomAppBar.tsx index 5a8fe5ca431bba..970786f3107e9f 100644 --- a/docs/src/pages/demos/app-bar/BottomAppBar.tsx +++ b/docs/src/pages/demos/app-bar/BottomAppBar.tsx @@ -9,6 +9,7 @@ import Paper from '@material-ui/core/Paper'; import Fab from '@material-ui/core/Fab'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import ListItemText from '@material-ui/core/ListItemText'; import ListSubheader from '@material-ui/core/ListSubheader'; import Avatar from '@material-ui/core/Avatar'; @@ -113,7 +114,9 @@ function BottomAppBar() { {id === 1 && Today} {id === 3 && Yesterday} - + + + diff --git a/docs/src/pages/demos/dividers/InsetDividers.js b/docs/src/pages/demos/dividers/InsetDividers.js index 413268c9cacccf..173791e8592db9 100644 --- a/docs/src/pages/demos/dividers/InsetDividers.js +++ b/docs/src/pages/demos/dividers/InsetDividers.js @@ -4,6 +4,7 @@ import { withStyles } from '@material-ui/core/styles'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; import ImageIcon from '@material-ui/icons/Image'; import WorkIcon from '@material-ui/icons/Work'; @@ -23,25 +24,29 @@ function InsetDividers(props) { return ( - - - + + + + + -
  • - -
  • + - - - + + + + + - - - + + + + +
    diff --git a/docs/src/pages/demos/dividers/InsetDividers.tsx b/docs/src/pages/demos/dividers/InsetDividers.tsx index 5341c8084b2115..d59e034d88a2e7 100644 --- a/docs/src/pages/demos/dividers/InsetDividers.tsx +++ b/docs/src/pages/demos/dividers/InsetDividers.tsx @@ -4,6 +4,7 @@ import { withStyles, Theme, WithStyles, WithTheme, createStyles } from '@materia import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; import ImageIcon from '@material-ui/icons/Image'; import WorkIcon from '@material-ui/icons/Work'; @@ -26,25 +27,29 @@ function InsetDividers(props: Props) { return ( - - - + + + + + -
  • - -
  • + - - - + + + + + - - - + + + + +
    diff --git a/docs/src/pages/demos/dividers/SubheaderDividers.js b/docs/src/pages/demos/dividers/SubheaderDividers.js index 85b1eee9b92df5..0265a2861a3f9d 100644 --- a/docs/src/pages/demos/dividers/SubheaderDividers.js +++ b/docs/src/pages/demos/dividers/SubheaderDividers.js @@ -3,6 +3,7 @@ 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 ListItemAvatar from '@material-ui/core/ListItemAvatar'; import ListItemText from '@material-ui/core/ListItemText'; import Avatar from '@material-ui/core/Avatar'; import BeachAccessIcon from '@material-ui/icons/BeachAccess'; @@ -56,9 +57,11 @@ function SubheaderDividers(props) { - - - + + + + + diff --git a/docs/src/pages/demos/dividers/SubheaderDividers.tsx b/docs/src/pages/demos/dividers/SubheaderDividers.tsx index 030f8239ffdf1d..212025f13a0d73 100644 --- a/docs/src/pages/demos/dividers/SubheaderDividers.tsx +++ b/docs/src/pages/demos/dividers/SubheaderDividers.tsx @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { withStyles, WithStyles, WithTheme, Theme } from '@material-ui/core/styles'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import ListItemText from '@material-ui/core/ListItemText'; import Avatar from '@material-ui/core/Avatar'; import BeachAccessIcon from '@material-ui/icons/BeachAccess'; @@ -58,9 +59,11 @@ function SubheaderDividers(props: Props) { - - - + + + + + diff --git a/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.js b/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.js index 14810b683f17b4..3ec84239dd63e9 100644 --- a/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.js +++ b/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.js @@ -37,9 +37,7 @@ const ExpansionPanelSummary = withStyles({ }, }, expanded: {}, -})(props => ); - -ExpansionPanelSummary.muiName = 'ExpansionPanelSummary'; +})(MuiExpansionPanelSummary); const ExpansionPanelDetails = withStyles(theme => ({ root: { diff --git a/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.tsx b/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.tsx index 170ea9779e7176..b3d7d5ec285182 100644 --- a/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.tsx +++ b/docs/src/pages/demos/expansion-panels/CustomizedExpansionPanel.tsx @@ -1,9 +1,7 @@ import React from 'react'; import { withStyles } from '@material-ui/core/styles'; import MuiExpansionPanel from '@material-ui/core/ExpansionPanel'; -import MuiExpansionPanelSummary, { - ExpansionPanelSummaryProps, -} from '@material-ui/core/ExpansionPanelSummary'; +import MuiExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary'; import MuiExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'; import Typography from '@material-ui/core/Typography'; @@ -39,9 +37,7 @@ const ExpansionPanelSummary = withStyles({ }, }, expanded: {}, -})((props: ExpansionPanelSummaryProps) => ); - -(ExpansionPanelSummary as any).muiName = 'ExpansionPanelSummary'; +})(MuiExpansionPanelSummary); const ExpansionPanelDetails = withStyles(theme => ({ root: { diff --git a/docs/src/pages/demos/lists/AlignItemsList.js b/docs/src/pages/demos/lists/AlignItemsList.js index 28a55864b44810..e52e773c65d3d7 100644 --- a/docs/src/pages/demos/lists/AlignItemsList.js +++ b/docs/src/pages/demos/lists/AlignItemsList.js @@ -3,6 +3,7 @@ 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 Divider from '@material-ui/core/Divider'; import ListItemText from '@material-ui/core/ListItemText'; import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; @@ -44,6 +45,7 @@ function AlignItemsList(props) { } /> + @@ -65,6 +67,7 @@ function AlignItemsList(props) { } /> + diff --git a/docs/src/pages/demos/lists/AlignItemsList.tsx b/docs/src/pages/demos/lists/AlignItemsList.tsx index 5e3371f8e5925d..2303735ac82548 100644 --- a/docs/src/pages/demos/lists/AlignItemsList.tsx +++ b/docs/src/pages/demos/lists/AlignItemsList.tsx @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { createStyles, Theme, withStyles, WithStyles } from '@material-ui/core/styles'; import List from '@material-ui/core/List'; import ListItem, { ListItemProps } from '@material-ui/core/ListItem'; +import Divider from '@material-ui/core/Divider'; import ListItemText from '@material-ui/core/ListItemText'; import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; @@ -47,6 +48,7 @@ function AlignItemsList(props: AlignItemListProps) { } /> + @@ -68,6 +70,7 @@ function AlignItemsList(props: AlignItemListProps) { } /> + diff --git a/docs/src/pages/demos/lists/CheckboxList.js b/docs/src/pages/demos/lists/CheckboxList.js index 1101e84913a79a..293616e47ac2df 100644 --- a/docs/src/pages/demos/lists/CheckboxList.js +++ b/docs/src/pages/demos/lists/CheckboxList.js @@ -2,6 +2,7 @@ import React from 'react'; import { makeStyles } 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 ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import ListItemText from '@material-ui/core/ListItemText'; import Checkbox from '@material-ui/core/Checkbox'; @@ -37,10 +38,17 @@ function CheckboxList() { {[0, 1, 2, 3].map(value => ( - + + + - + diff --git a/docs/src/pages/demos/lists/CheckboxList.tsx b/docs/src/pages/demos/lists/CheckboxList.tsx index 5ee653e994800a..b012bfa623c3c0 100644 --- a/docs/src/pages/demos/lists/CheckboxList.tsx +++ b/docs/src/pages/demos/lists/CheckboxList.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { createStyles, makeStyles, Theme } 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 ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import ListItemText from '@material-ui/core/ListItemText'; import Checkbox from '@material-ui/core/Checkbox'; @@ -39,10 +40,17 @@ function CheckboxList() { {[0, 1, 2, 3].map(value => ( - + + + - + diff --git a/docs/src/pages/demos/lists/CheckboxListSecondary.js b/docs/src/pages/demos/lists/CheckboxListSecondary.js index b20bdbc90599d5..8b82e0bc1b8b89 100644 --- a/docs/src/pages/demos/lists/CheckboxListSecondary.js +++ b/docs/src/pages/demos/lists/CheckboxListSecondary.js @@ -42,7 +42,11 @@ function CheckboxListSecondary() { - + ))} diff --git a/docs/src/pages/demos/lists/CheckboxListSecondary.tsx b/docs/src/pages/demos/lists/CheckboxListSecondary.tsx index bd3c208821f4fb..a664145cd4cb85 100644 --- a/docs/src/pages/demos/lists/CheckboxListSecondary.tsx +++ b/docs/src/pages/demos/lists/CheckboxListSecondary.tsx @@ -44,7 +44,11 @@ function CheckboxListSecondary() { - + ))} diff --git a/docs/src/pages/demos/lists/FolderList.js b/docs/src/pages/demos/lists/FolderList.js index 94202e51b54fe6..1a27fb03e2632d 100644 --- a/docs/src/pages/demos/lists/FolderList.js +++ b/docs/src/pages/demos/lists/FolderList.js @@ -4,6 +4,7 @@ import { withStyles } from '@material-ui/core/styles'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; import ImageIcon from '@material-ui/icons/Image'; import WorkIcon from '@material-ui/icons/Work'; @@ -22,21 +23,27 @@ function FolderList(props) { return ( - - - + + + + + - - - + + + + + - - - + + + + + diff --git a/docs/src/pages/demos/lists/FolderList.tsx b/docs/src/pages/demos/lists/FolderList.tsx index 164b6528e0896a..f1c1a3bb2e06de 100644 --- a/docs/src/pages/demos/lists/FolderList.tsx +++ b/docs/src/pages/demos/lists/FolderList.tsx @@ -4,6 +4,7 @@ import { createStyles, Theme, withStyles, WithStyles } from '@material-ui/core/s import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; import ImageIcon from '@material-ui/icons/Image'; import WorkIcon from '@material-ui/icons/Work'; @@ -25,21 +26,27 @@ function FolderList(props: FolderListProps) { return ( - - - + + + + + - - - + + + + + - - - + + + + + diff --git a/docs/src/pages/demos/lists/InsetList.js b/docs/src/pages/demos/lists/InsetList.js index 7bc540957290e4..e4bd666edc324f 100644 --- a/docs/src/pages/demos/lists/InsetList.js +++ b/docs/src/pages/demos/lists/InsetList.js @@ -23,7 +23,7 @@ function InsetList(props) { - + diff --git a/docs/src/pages/demos/lists/InsetList.tsx b/docs/src/pages/demos/lists/InsetList.tsx index 4d7e5a1b5125f3..85ae73516c2959 100644 --- a/docs/src/pages/demos/lists/InsetList.tsx +++ b/docs/src/pages/demos/lists/InsetList.tsx @@ -26,7 +26,7 @@ function InsetList(props: InsetListProps) { - + diff --git a/docs/src/pages/demos/lists/InteractiveList.js b/docs/src/pages/demos/lists/InteractiveList.js index 18eb3df6165358..8e65394b3dbcd4 100644 --- a/docs/src/pages/demos/lists/InteractiveList.js +++ b/docs/src/pages/demos/lists/InteractiveList.js @@ -146,7 +146,7 @@ function InteractiveList() { secondary={secondary ? 'Secondary text' : null} /> - + diff --git a/docs/src/pages/demos/lists/NestedList.js b/docs/src/pages/demos/lists/NestedList.js index 7100c9b3dc35ae..d13dce2695e2cf 100644 --- a/docs/src/pages/demos/lists/NestedList.js +++ b/docs/src/pages/demos/lists/NestedList.js @@ -42,19 +42,19 @@ function NestedList() { - + - + - + {open ? : } @@ -63,7 +63,7 @@ function NestedList() { - + diff --git a/docs/src/pages/demos/lists/SwitchListSecondary.js b/docs/src/pages/demos/lists/SwitchListSecondary.js index e9fd99579a051f..8e8ca16becc9ce 100644 --- a/docs/src/pages/demos/lists/SwitchListSecondary.js +++ b/docs/src/pages/demos/lists/SwitchListSecondary.js @@ -43,7 +43,11 @@ function SwitchListSecondary() { - + @@ -53,6 +57,7 @@ function SwitchListSecondary() { diff --git a/docs/src/pages/demos/transfer-list/SelectAllTransferList.js b/docs/src/pages/demos/transfer-list/SelectAllTransferList.js index bddad4099400dd..e08e225a2fe9c4 100644 --- a/docs/src/pages/demos/transfer-list/SelectAllTransferList.js +++ b/docs/src/pages/demos/transfer-list/SelectAllTransferList.js @@ -6,6 +6,7 @@ import Card from '@material-ui/core/Card'; import CardHeader from '@material-ui/core/CardHeader'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; +import ListItemIcon from '@material-ui/core/ListItemIcon'; import Checkbox from '@material-ui/core/Checkbox'; import Button from '@material-ui/core/Button'; import Divider from '@material-ui/core/Divider'; @@ -23,10 +24,6 @@ const useStyles = makeStyles(theme => ({ backgroundColor: theme.palette.background.paper, overflow: 'auto', }, - listItem: { - paddingTop: 4, - paddingBottom: 4, - }, button: { margin: theme.spacing(0.5, 0), }, @@ -106,14 +103,10 @@ function TransferList() { {items.map(value => ( - - + + + + ))} diff --git a/docs/src/pages/demos/transfer-list/TransferList.js b/docs/src/pages/demos/transfer-list/TransferList.js index c4e9b9e61ebb9c..147fa176e85f81 100644 --- a/docs/src/pages/demos/transfer-list/TransferList.js +++ b/docs/src/pages/demos/transfer-list/TransferList.js @@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; 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 Checkbox from '@material-ui/core/Checkbox'; import Button from '@material-ui/core/Button'; @@ -17,10 +18,6 @@ const useStyles = makeStyles(theme => ({ height: 230, overflow: 'auto', }, - listItem: { - paddingTop: 4, - paddingBottom: 4, - }, button: { margin: theme.spacing(0.5, 0), }, @@ -82,14 +79,10 @@ function TransferList() { {items.map(value => ( - - + + + + ))} diff --git a/packages/material-ui/src/Divider/Divider.js b/packages/material-ui/src/Divider/Divider.js index ceffe787c8fe1b..6ea804f6ca2e18 100644 --- a/packages/material-ui/src/Divider/Divider.js +++ b/packages/material-ui/src/Divider/Divider.js @@ -38,6 +38,10 @@ export const styles = theme => ({ const Divider = React.forwardRef(function Divider(props, ref) { const { absolute, classes, className, component: Component, light, variant, ...other } = props; + if (Component === 'li' && !other.role) { + other.role = 'separator'; + } + return ( ({ dense }), [dense]); return ( - - + + {subheader} {children} - - + + ); }); @@ -85,8 +82,8 @@ List.propTypes = { component: PropTypes.elementType, /** * If `true`, compact vertical padding designed for keyboard and mouse input will be used for - * the list and list items. The property is available to descendant components as the - * `dense` context. + * the list and list items. + * The property is available to descendant components as the `dense` context. */ dense: PropTypes.bool, /** diff --git a/packages/material-ui/src/ListItem/ListItem.js b/packages/material-ui/src/ListItem/ListItem.js index 52c604074d1e2f..daa06ec919721a 100644 --- a/packages/material-ui/src/ListItem/ListItem.js +++ b/packages/material-ui/src/ListItem/ListItem.js @@ -5,7 +5,7 @@ import { chainPropTypes } from '@material-ui/utils'; import withStyles from '../styles/withStyles'; import ButtonBase from '../ButtonBase'; import { isMuiElement } from '../utils/reactHelpers'; -import MergeListContext from './MergeListContext'; +import ListContext from '../List/ListContext'; export const styles = theme => ({ /* Styles applied to the (normally root) `component` element. May be wrapped by a `container`. */ @@ -18,8 +18,8 @@ export const styles = theme => ({ width: '100%', boxSizing: 'border-box', textAlign: 'left', - paddingTop: 11, // To use 10px in v4 - paddingBottom: 11, // To use 10px in v4 + paddingTop: 8, + paddingBottom: 8, '&$selected, &$selected:hover': { backgroundColor: theme.palette.action.selected, }, @@ -33,12 +33,10 @@ export const styles = theme => ({ focusVisible: { backgroundColor: theme.palette.action.selected, }, - /* Legacy styles applied to the root element. Use `root` instead. */ - default: {}, - /* Styles applied to the `component` element if `dense={true}` or `children` includes `Avatar`. */ + /* Styles applied to the `component` element if dense. */ dense: { - paddingTop: 8, - paddingBottom: 8, + paddingTop: 4, + paddingBottom: 4, }, /* Styles applied to the `component` element if `alignItems="flex-start"`. */ alignItemsFlexStart: { @@ -76,7 +74,7 @@ export const styles = theme => ({ secondaryAction: { // Add some space to avoid collision as `ListItemSecondaryAction` // is absolutely positioned. - paddingRight: 32, + paddingRight: 48, }, /* Styles applied to the root element if `selected={true}`. */ selected: {}, @@ -91,11 +89,11 @@ const ListItem = React.forwardRef(function ListItem(props, ref) { button, children: childrenProp, classes, - className: classNameProp, + className, component: componentProp, ContainerComponent, ContainerProps: { className: ContainerClassName, ...ContainerProps } = {}, - dense: denseProp, + dense, disabled, disableGutters, divider, @@ -104,72 +102,75 @@ const ListItem = React.forwardRef(function ListItem(props, ref) { ...other } = props; - return ( - - {({ dense }) => { - const children = React.Children.toArray(childrenProp); - const hasAvatar = children.some(value => isMuiElement(value, ['ListItemAvatar'])); - const hasSecondaryAction = - children.length && - isMuiElement(children[children.length - 1], ['ListItemSecondaryAction']); + const context = React.useContext(ListContext); + const childContext = { + dense: dense || context.dense || false, + alignItems, + }; - const className = clsx( - classes.root, - classes.default, - { - [classes.dense]: dense || hasAvatar, - [classes.gutters]: !disableGutters, - [classes.divider]: divider, - [classes.disabled]: disabled, - [classes.button]: button, - [classes.alignItemsFlexStart]: alignItems === 'flex-start', - [classes.secondaryAction]: hasSecondaryAction, - [classes.selected]: selected, - }, - classNameProp, - ); + const children = React.Children.toArray(childrenProp); + const hasSecondaryAction = + children.length && isMuiElement(children[children.length - 1], ['ListItemSecondaryAction']); - const componentProps = { className, disabled, ...other }; - let Component = componentProp || 'li'; + const componentProps = { + className: clsx( + classes.root, + { + [classes.dense]: childContext.dense, + [classes.gutters]: !disableGutters, + [classes.divider]: divider, + [classes.disabled]: disabled, + [classes.button]: button, + [classes.alignItemsFlexStart]: alignItems === 'flex-start', + [classes.secondaryAction]: hasSecondaryAction, + [classes.selected]: selected, + }, + className, + ), + disabled, + ...other, + }; + let Component = componentProp || 'li'; - if (button) { - componentProps.component = componentProp || 'div'; - componentProps.focusVisibleClassName = clsx(classes.focusVisible, focusVisibleClassName); - Component = ButtonBase; - } + if (button) { + componentProps.component = componentProp || 'div'; + componentProps.focusVisibleClassName = clsx(classes.focusVisible, focusVisibleClassName); + Component = ButtonBase; + } - if (hasSecondaryAction) { - // Use div by default. - Component = !componentProps.component && !componentProp ? 'div' : Component; + if (hasSecondaryAction) { + // Use div by default. + Component = !componentProps.component && !componentProp ? 'div' : Component; - // Avoid nesting of li > li. - if (ContainerComponent === 'li') { - if (Component === 'li') { - Component = 'div'; - } else if (componentProps.component === 'li') { - componentProps.component = 'div'; - } - } + // Avoid nesting of li > li. + if (ContainerComponent === 'li') { + if (Component === 'li') { + Component = 'div'; + } else if (componentProps.component === 'li') { + componentProps.component = 'div'; + } + } - return ( - - {children} - {children.pop()} - - ); - } + return ( + + + {children} + {children.pop()} + + + ); + } - return ( - - {children} - - ); - }} - + return ( + + + {children} + + ); }); @@ -263,7 +264,6 @@ ListItem.defaultProps = { alignItems: 'center', button: false, ContainerComponent: 'li', - dense: false, disabled: false, disableGutters: false, divider: false, diff --git a/packages/material-ui/src/ListItem/ListItem.test.js b/packages/material-ui/src/ListItem/ListItem.test.js index b064d9e1d3d525..f8fb76f9df36ee 100644 --- a/packages/material-ui/src/ListItem/ListItem.test.js +++ b/packages/material-ui/src/ListItem/ListItem.test.js @@ -11,8 +11,6 @@ import consoleErrorMock from 'test/utils/consoleErrorMock'; import ListItemText from '../ListItemText'; import ListItemSecondaryAction from '../ListItemSecondaryAction'; import ListItem from './ListItem'; -import ListItemAvatar from '../ListItemAvatar'; -import Avatar from '../Avatar'; import ButtonBase from '../ButtonBase'; import ListContext from '../List/ListContext'; @@ -55,20 +53,6 @@ describe('', () => { assert.strictEqual(listItem.hasClass(classes.gutters), false); }); - it('should use dense class when ListItemAvatar is present', () => { - const wrapper = mount( - - - - - - - , - ); - const listItem = findOutermostIntrinsic(wrapper); - assert.strictEqual(listItem.hasClass(classes.dense), true); - }); - describe('prop: button', () => { it('renders a div', () => { const wrapper = mount(); diff --git a/packages/material-ui/src/ListItem/MergeListContext.d.ts b/packages/material-ui/src/ListItem/MergeListContext.d.ts deleted file mode 100644 index 4502151b2170e2..00000000000000 --- a/packages/material-ui/src/ListItem/MergeListContext.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as React from 'react'; - -export interface MergeWithListContextProps { - dense?: boolean; -} - -declare const MergeWithListContext: React.ComponentType; - -export default MergeWithListContext; diff --git a/packages/material-ui/src/ListItem/MergeListContext.js b/packages/material-ui/src/ListItem/MergeListContext.js deleted file mode 100644 index 49d839e6729f7c..00000000000000 --- a/packages/material-ui/src/ListItem/MergeListContext.js +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import ListContext from '../List/ListContext'; - -/** - * @ignore - internal component. - * - * Consumes a context and passes that context merged with its props. - */ -function MergeListContext(props) { - const { alignItems, children, dense } = props; - return ( - - {context => { - const childContext = { - dense: dense || context.dense || false, - alignItems, - }; - - return ( - {children(childContext)} - ); - }} - - ); -} - -MergeListContext.propTypes = { - alignItems: PropTypes.oneOf(['flex-start', 'center']).isRequired, - children: PropTypes.func.isRequired, - dense: PropTypes.bool.isRequired, -}; - -export default MergeListContext; diff --git a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js index cbfdde9963b83f..0609c9ad0d0875 100644 --- a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js +++ b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js @@ -4,55 +4,39 @@ import clsx from 'clsx'; import withStyles from '../styles/withStyles'; import ListContext from '../List/ListContext'; -export const styles = theme => ({ +export const styles = { /* Styles applied to the root element. */ root: { - width: 36, - height: 36, - fontSize: theme.typography.pxToRem(18), - marginRight: 4, + minWidth: 56, + flexShrink: 0, }, - /* Styles applied to the root element when. */ + /* Styles applied to the root element when the parent `ListItem` uses `alignItems="flex-start"`. */ alignItemsFlexStart: { - marginTop: 4, + marginTop: 8, }, - /* Styles applied to the children – typically the `Avatar` component. */ - icon: { - width: 20, - height: 20, - fontSize: theme.typography.pxToRem(20), - }, -}); +}; /** - * This is a simple wrapper to apply the `dense` - * and `align-items="flex-start"` mode styles to `Avatar`. + * A simple wrapper to apply `List` styles to an `Avatar`. */ -function ListItemAvatar(props) { - const { children, classes, className, ...other } = props; +const ListItemAvatar = React.forwardRef(function ListItemAvatar(props, ref) { + const { classes, className, ...other } = props; + const context = React.useContext(ListContext); return ( - - {context => - React.cloneElement(children, { - className: clsx( - { - [classes.root]: context.dense, - [classes.alignItemsFlexStart]: context.alignItems === 'flex-start', - }, - className, - children.props.className, - ), - childrenClassName: clsx( - { [classes.icon]: context.dense }, - children.props.childrenClassName, - ), - ...other, - }) - } - +
    ); -} +}); ListItemAvatar.propTypes = { /** @@ -70,6 +54,4 @@ ListItemAvatar.propTypes = { className: PropTypes.string, }; -ListItemAvatar.muiName = 'ListItemAvatar'; - export default withStyles(styles, { name: 'MuiListItemAvatar' })(ListItemAvatar); diff --git a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js index fed39a41bb8198..45b24d7ef65458 100644 --- a/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js +++ b/packages/material-ui/src/ListItemAvatar/ListItemAvatar.test.js @@ -1,9 +1,6 @@ import React from 'react'; -import { assert } from 'chai'; -import { createMount, getClasses } from '@material-ui/core/test-utils'; -import Avatar from '../Avatar'; +import { createMount, getClasses, describeConformance } from '@material-ui/core/test-utils'; import ListItemAvatar from './ListItemAvatar'; -import ListContext from '../List/ListContext'; describe('', () => { let mount; @@ -12,8 +9,8 @@ describe('', () => { before(() => { mount = createMount({ strict: true }); classes = getClasses( - - + +
    , ); }); @@ -22,17 +19,16 @@ describe('', () => { mount.cleanUp(); }); - it('should render with the user and root classes', () => { - const wrapper = mount( - - - - - , - ); - const avatar = wrapper.find(Avatar); - assert.strictEqual(avatar.hasClass('foo'), true); - assert.strictEqual(avatar.hasClass('bar'), true); - assert.strictEqual(avatar.hasClass(classes.root), true); - }); + describeConformance( + +
    + , + () => ({ + classes, + inheritComponent: 'div', + mount, + refInstanceof: window.HTMLDivElement, + skip: ['componentProp'], + }), + ); }); diff --git a/packages/material-ui/src/ListItemIcon/ListItemIcon.js b/packages/material-ui/src/ListItemIcon/ListItemIcon.js index b16d2018bb6146..89e61d727ce5af 100644 --- a/packages/material-ui/src/ListItemIcon/ListItemIcon.js +++ b/packages/material-ui/src/ListItemIcon/ListItemIcon.js @@ -6,7 +6,7 @@ import withStyles from '../styles/withStyles'; export const styles = theme => ({ /* Styles applied to the root element. */ root: { - marginRight: 16, + minWidth: 56, color: theme.palette.action.active, flexShrink: 0, display: 'inline-flex', @@ -17,13 +17,9 @@ export const styles = theme => ({ * A simple wrapper to apply `List` styles to an `Icon` or `SvgIcon`. */ const ListItemIcon = React.forwardRef(function ListItemIcon(props, ref) { - const { children, classes, className: classNameProp, ...other } = props; + const { classes, className, ...other } = props; - return ( -
    - {children} -
    - ); + return
    ; }); ListItemIcon.propTypes = { diff --git a/packages/material-ui/src/ListItemSecondaryAction/ListItemSecondaryAction.js b/packages/material-ui/src/ListItemSecondaryAction/ListItemSecondaryAction.js index 05be0938c8299a..0f67a2933a7b51 100644 --- a/packages/material-ui/src/ListItemSecondaryAction/ListItemSecondaryAction.js +++ b/packages/material-ui/src/ListItemSecondaryAction/ListItemSecondaryAction.js @@ -7,7 +7,7 @@ export const styles = { /* Styles applied to the root element. */ root: { position: 'absolute', - right: 4, + right: 16, top: '50%', transform: 'translateY(-50%)', }, @@ -17,13 +17,9 @@ export const styles = { * Must be used as the last child of ListItem to function properly. */ const ListItemSecondaryAction = React.forwardRef(function ListItemSecondaryAction(props, ref) { - const { children, classes, className, ...other } = props; + const { classes, className, ...other } = props; - return ( -
    - {children} -
    - ); + return
    ; }); ListItemSecondaryAction.propTypes = { diff --git a/packages/material-ui/src/ListItemText/ListItemText.js b/packages/material-ui/src/ListItemText/ListItemText.js index 22b709eb0eb6c4..3aca24cd174a69 100644 --- a/packages/material-ui/src/ListItemText/ListItemText.js +++ b/packages/material-ui/src/ListItemText/ListItemText.js @@ -5,109 +5,91 @@ import withStyles from '../styles/withStyles'; import Typography from '../Typography'; import ListContext from '../List/ListContext'; -export const styles = theme => ({ +export const styles = { /* Styles applied to the root element. */ root: { flex: '1 1 auto', minWidth: 0, - padding: '0 16px', - '&:first-child': { - paddingLeft: 0, - }, + marginTop: 4, + marginBottom: 4, }, + /* Styles applied to the `Typography` components if primary and secondary are set. */ + multiline: { + marginTop: 6, + marginBottom: 6, + }, + /* Styles applied to the `Typography` components if dense. */ + dense: {}, /* Styles applied to the root element if `inset={true}`. */ inset: { - '&:first-child': { - paddingLeft: 56, - }, - }, - /* Styles applied to the root element if `context.dense` is `true`. */ - dense: { - fontSize: theme.typography.pxToRem(13), + paddingLeft: 56, }, /* Styles applied to the primary `Typography` component. */ - primary: { - '&$textDense': { - fontSize: 'inherit', - }, - }, + primary: {}, /* Styles applied to the secondary `Typography` component. */ - secondary: { - '&$textDense': { - fontSize: 'inherit', - }, - }, - /* Styles applied to the `Typography` components if `context.dense` is `true`. */ - textDense: {}, -}); + secondary: {}, +}; const ListItemText = React.forwardRef(function ListItemText(props, ref) { const { children, classes, - className: classNameProp, + className, disableTypography, inset, primary: primaryProp, primaryTypographyProps, secondary: secondaryProp, secondaryTypographyProps, - theme, ...other } = props; + const { dense } = React.useContext(ListContext); - return ( - - {({ dense }) => { - let primary = primaryProp != null ? primaryProp : children; - if (primary != null && primary.type !== Typography && !disableTypography) { - primary = ( - - {primary} - - ); - } + let primary = primaryProp != null ? primaryProp : children; + if (primary != null && primary.type !== Typography && !disableTypography) { + primary = ( + + {primary} + + ); + } - let secondary = secondaryProp; - if (secondary != null && secondary.type !== Typography && !disableTypography) { - secondary = ( - - {secondary} - - ); - } + let secondary = secondaryProp; + if (secondary != null && secondary.type !== Typography && !disableTypography) { + secondary = ( + + {secondary} + + ); + } - return ( -
    - {primary} - {secondary} -
    - ); - }} -
    + return ( +
    + {primary} + {secondary} +
    ); }); @@ -155,10 +137,6 @@ ListItemText.propTypes = { * (as long as disableTypography is not `true`). */ secondaryTypographyProps: PropTypes.object, - /** - * @ignore - */ - theme: PropTypes.object.isRequired, }; ListItemText.defaultProps = { @@ -166,4 +144,4 @@ ListItemText.defaultProps = { inset: false, }; -export default withStyles(styles, { name: 'MuiListItemText', withTheme: true })(ListItemText); +export default withStyles(styles, { name: 'MuiListItemText' })(ListItemText); diff --git a/packages/material-ui/src/ListSubheader/ListSubheader.js b/packages/material-ui/src/ListSubheader/ListSubheader.js index 220a1d393f74de..f2fcd0fb2a4278 100644 --- a/packages/material-ui/src/ListSubheader/ListSubheader.js +++ b/packages/material-ui/src/ListSubheader/ListSubheader.js @@ -116,6 +116,4 @@ ListSubheader.defaultProps = { inset: false, }; -ListSubheader.muiName = 'ListSubheader'; - export default withStyles(styles, { name: 'MuiListSubheader' })(ListSubheader); diff --git a/packages/material-ui/src/Switch/Switch.js b/packages/material-ui/src/Switch/Switch.js index cc2e2a5c2303ce..c979714ea6ff0c 100644 --- a/packages/material-ui/src/Switch/Switch.js +++ b/packages/material-ui/src/Switch/Switch.js @@ -22,6 +22,14 @@ export const styles = theme => ({ zIndex: 0, // Reset the stacking context. verticalAlign: 'middle', // For correct alignment with the text. }, + /* Styles applied to the root element if `edge="start"`. */ + edgeStart: { + marginLeft: -8, + }, + /* Styles applied to the root element if `edge="end"`. */ + edgeEnd: { + marginRight: -8, + }, /* Styles applied to the internal `SwitchBase` component's `root` class. */ switchBase: { position: 'absolute', @@ -116,11 +124,20 @@ export const styles = theme => ({ }); const Switch = React.forwardRef(function Switch(props, ref) { - const { classes, className, color, ...other } = props; + const { classes, className, color, edge, ...other } = props; const icon = ; return ( - + { @@ -21,7 +21,6 @@ describe('utils/reactHelpers.js', () => { it('should be truthy for matching components', () => { [ [Input, 'Input'], - [ListItemAvatar, 'ListItemAvatar'], [ListItemSecondaryAction, 'ListItemSecondaryAction'], [SvgIcon, 'SvgIcon'], ].forEach(([Component, muiName]) => { diff --git a/pages/api/icon-button.md b/pages/api/icon-button.md index 337bc8ccd21401..dd9bec99625311 100644 --- a/pages/api/icon-button.md +++ b/pages/api/icon-button.md @@ -23,7 +23,7 @@ regarding the available icon options. | classes | object | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. | | color | enum: 'default' |
     'inherit' |
     'primary' |
     'secondary'
    | 'default' | The color of the component. It supports those theme colors that make sense for this component. | | disabled | bool | false | If `true`, the button will be disabled. | -| edge | enum: 'start' |
     'end' |
     false
    | | If given, uses a negative margin to counteract the padding on one side (this is often helpful for aligning the left or right side of the icon with content above or below, without ruining the border size and shape). | +| edge | enum: 'start' |
     'end' |
     false
    | false | If given, uses a negative margin to counteract the padding on one side (this is often helpful for aligning the left or right side of the icon with content above or below, without ruining the border size and shape). | | size | enum: 'small' |
     'medium'
    | 'medium' | The size of the button. `small` is equivalent to the dense button styling. | The `ref` is forwarded to the root element. diff --git a/pages/api/list-item-avatar.md b/pages/api/list-item-avatar.md index 3bfa0160c0b2e3..979d602d291dd8 100644 --- a/pages/api/list-item-avatar.md +++ b/pages/api/list-item-avatar.md @@ -12,8 +12,7 @@ filename: /packages/material-ui/src/ListItemAvatar/ListItemAvatar.js import ListItemAvatar from '@material-ui/core/ListItemAvatar'; ``` -This is a simple wrapper to apply the `dense` -and `align-items="flex-start"` mode styles to `Avatar`. +A simple wrapper to apply `List` styles to an `Avatar`. ## Props @@ -22,7 +21,7 @@ and `align-items="flex-start"` mode styles to `Avatar`. | children * | element | | The content of the component – normally `Avatar`. | | classes | object | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. | -The component cannot hold a ref. +The `ref` is forwarded to the root element. Any other properties supplied will be spread to the root element (native element). @@ -35,8 +34,7 @@ This property accepts the following keys: | Name | Description | |:-----|:------------| | root | Styles applied to the root element. -| alignItemsFlexStart | Styles applied to the root element when. -| icon | Styles applied to the children – typically the `Avatar` component. +| alignItemsFlexStart | Styles applied to the root element when the parent `ListItem` uses `alignItems="flex-start"`. Have a look at [overriding with classes](/customization/overrides/#overriding-with-classes) section and the [implementation of the component](https://github.com/mui-org/material-ui/blob/next/packages/material-ui/src/ListItemAvatar/ListItemAvatar.js) diff --git a/pages/api/list-item-text.md b/pages/api/list-item-text.md index 9caddfe933c431..9555c44e0f0a48 100644 --- a/pages/api/list-item-text.md +++ b/pages/api/list-item-text.md @@ -40,11 +40,11 @@ This property accepts the following keys: | Name | Description | |:-----|:------------| | root | Styles applied to the root element. +| multiline | Styles applied to the `Typography` components if primary and secondary are set. +| dense | Styles applied to the `Typography` components if dense. | inset | Styles applied to the root element if `inset={true}`. -| dense | Styles applied to the root element if `context.dense` is `true`. | primary | Styles applied to the primary `Typography` component. | secondary | Styles applied to the secondary `Typography` component. -| textDense | Styles applied to the `Typography` components if `context.dense` is `true`. Have a look at [overriding with classes](/customization/overrides/#overriding-with-classes) section and the [implementation of the component](https://github.com/mui-org/material-ui/blob/next/packages/material-ui/src/ListItemText/ListItemText.js) diff --git a/pages/api/list-item.md b/pages/api/list-item.md index 1415ddc5473423..22488cb8144f35 100644 --- a/pages/api/list-item.md +++ b/pages/api/list-item.md @@ -25,7 +25,7 @@ Uses an additional container component if `ListItemSecondaryAction` is the last | component | elementType | | The component used for the root node. Either a string to use a DOM element or a component. By default, it's a `li` when `button` is `false` and a `div` when `button` is `true`. | | ContainerComponent | elementType | 'li' | The container component used when a `ListItemSecondaryAction` is the last child. | | ContainerProps | object | | Properties applied to the container component if used. | -| dense | bool | false | If `true`, compact vertical padding designed for keyboard and mouse input will be used. | +| dense | bool | | If `true`, compact vertical padding designed for keyboard and mouse input will be used. | | disabled | bool | false | If `true`, the list item will be disabled. | | disableGutters | bool | false | If `true`, the left and right padding is removed. | | divider | bool | false | If `true`, a 1px light border is added to the bottom of the list item. | @@ -46,8 +46,7 @@ This property accepts the following keys: | root | Styles applied to the (normally root) `component` element. May be wrapped by a `container`. | container | Styles applied to the `container` element if `children` includes `ListItemSecondaryAction`. | focusVisible | Styles applied to the `component`'s `focusVisibleClassName` property if `button={true}`. -| default | Legacy styles applied to the root element. Use `root` instead. -| dense | Styles applied to the `component` element if `dense={true}` or `children` includes `Avatar`. +| dense | Styles applied to the `component` element if dense. | alignItemsFlexStart | Styles applied to the `component` element if `alignItems="flex-start"`. | disabled | Styles applied to the inner `component` element if `disabled={true}`. | divider | Styles applied to the inner `component` element if `divider={true}`. diff --git a/pages/api/list.md b/pages/api/list.md index 19607b35570142..b5d63ebe100365 100644 --- a/pages/api/list.md +++ b/pages/api/list.md @@ -39,7 +39,7 @@ This property accepts the following keys: |:-----|:------------| | root | Styles applied to the root element. | padding | Styles applied to the root element if `disablePadding={false}`. -| dense | Styles applied to the root element if `dense={true}` & `disablePadding={false}`. +| dense | Styles applied to the root element if dense. | subheader | Styles applied to the root element if a `subheader` is provided. Have a look at [overriding with classes](/customization/overrides/#overriding-with-classes) section diff --git a/pages/api/switch.md b/pages/api/switch.md index 093e669edea5f9..ea3fc1931fc2fe 100644 --- a/pages/api/switch.md +++ b/pages/api/switch.md @@ -24,6 +24,7 @@ import Switch from '@material-ui/core/Switch'; | color | enum: 'primary' |
     'secondary' |
     'default'
    | 'secondary' | The color of the component. It supports those theme colors that make sense for this component. | | disabled | bool | | If `true`, the switch will be disabled. | | disableRipple | bool | | If `true`, the ripple effect will be disabled. | +| edge | enum: 'start' |
     'end' |
     false
    | false | If given, uses a negative margin to counteract the padding on one side (this is often helpful for aligning the left or right side of the icon with content above or below, without ruining the border size and shape). | | icon | node | | The icon to display when the component is unchecked. | | id | string | | The id of the `input` element. | | inputProps | object | | [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element. | @@ -45,6 +46,8 @@ This property accepts the following keys: | Name | Description | |:-----|:------------| | root | Styles applied to the root element. +| edgeStart | Styles applied to the root element if `edge="start"`. +| edgeEnd | Styles applied to the root element if `edge="end"`. | switchBase | Styles applied to the internal `SwitchBase` component's `root` class. | colorPrimary | Styles applied to the internal SwitchBase component's root element if `color="primary"`. | colorSecondary | Styles applied to the internal SwitchBase component's root element if `color="secondary"`. diff --git a/test/regressions/tests/List/AvatarListItem.js b/test/regressions/tests/List/AvatarListItem.js deleted file mode 100644 index f319ca0c270955..00000000000000 --- a/test/regressions/tests/List/AvatarListItem.js +++ /dev/null @@ -1,39 +0,0 @@ -import React from 'react'; -import Avatar from '@material-ui/core/Avatar'; -import Icon from '@material-ui/core/Icon'; -import List from '@material-ui/core/List'; -import ListItem from '@material-ui/core/ListItem'; -import ListItemText from '@material-ui/core/ListItemText'; - -export default function AvatarListItem() { - return ( -
    - - - folder - - - - - - folder - - - - - - - folder - - - - - - folder - - - - -
    - ); -} diff --git a/test/regressions/tests/List/PrimaryActionCheckboxListItem.js b/test/regressions/tests/List/PrimaryActionCheckboxListItem.js deleted file mode 100644 index 134f63bd0fb94a..00000000000000 --- a/test/regressions/tests/List/PrimaryActionCheckboxListItem.js +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react'; -import List from '@material-ui/core/List'; -import ListItem from '@material-ui/core/ListItem'; -import ListItemText from '@material-ui/core/ListItemText'; -import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; -import Checkbox from '@material-ui/core/Checkbox'; -import IconButton from '@material-ui/core/IconButton'; -import Icon from '@material-ui/core/Icon'; - -export default function PrimaryActionCheckboxListItem() { - return ( -
    - - - - - - - comment - - - - - - - - - comment - - - - - - - - - comment - - - - -
    - ); -}