diff --git a/docs/pages/api-docs/list-subheader.json b/docs/pages/api-docs/list-subheader.json index ee0962199fab10..e6a21e2f31cf64 100644 --- a/docs/pages/api-docs/list-subheader.json +++ b/docs/pages/api-docs/list-subheader.json @@ -12,7 +12,8 @@ "component": { "type": { "name": "elementType" } }, "disableGutters": { "type": { "name": "bool" } }, "disableSticky": { "type": { "name": "bool" } }, - "inset": { "type": { "name": "bool" } } + "inset": { "type": { "name": "bool" } }, + "sx": { "type": { "name": "object" } } }, "name": "ListSubheader", "styles": { @@ -25,6 +26,6 @@ "filename": "/packages/material-ui/src/ListSubheader/ListSubheader.js", "inheritance": null, "demos": "
", - "styledComponent": false, + "styledComponent": true, "cssComponent": false } diff --git a/docs/translations/api-docs/list-subheader/list-subheader.json b/docs/translations/api-docs/list-subheader/list-subheader.json index cb169074213da3..96ce291bdb72bd 100644 --- a/docs/translations/api-docs/list-subheader/list-subheader.json +++ b/docs/translations/api-docs/list-subheader/list-subheader.json @@ -7,7 +7,8 @@ "component": "The component used for the root node. Either a string to use a HTML element or a component.", "disableGutters": "Iftrue
, the List Subheader will not have gutters.",
"disableSticky": "If true
, the List Subheader will not stick to the top during scroll.",
- "inset": "If true
, the List Subheader is indented."
+ "inset": "If true
, the List Subheader is indented.",
+ "sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details."
},
"classDescriptions": {
"root": { "description": "Styles applied to the root element." },
diff --git a/packages/material-ui/src/List/List.test.js b/packages/material-ui/src/List/List.test.js
index d551f15b7c0ea3..6da9700b54ce04 100644
--- a/packages/material-ui/src/List/List.test.js
+++ b/packages/material-ui/src/List/List.test.js
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { getClasses, createMount, describeConformance, createClientRender } from 'test/utils';
-import ListSubheader from '../ListSubheader';
+import ListSubheader, { listSubheaderClasses } from '../ListSubheader';
import List from './List';
import ListItem, { listItemClasses } from '../ListItem';
@@ -42,7 +42,6 @@ describe('{ @@ -44,6 +46,10 @@ export interface ListSubheaderTypeMap
;
};
defaultComponent: D;
}
diff --git a/packages/material-ui/src/ListSubheader/ListSubheader.js b/packages/material-ui/src/ListSubheader/ListSubheader.js
index 0c8c94279b9252..385a1e284930ac 100644
--- a/packages/material-ui/src/ListSubheader/ListSubheader.js
+++ b/packages/material-ui/src/ListSubheader/ListSubheader.js
@@ -1,71 +1,112 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
-import withStyles from '../styles/withStyles';
+import { deepmerge } from '@material-ui/utils';
+import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
+import experimentalStyled from '../styles/experimentalStyled';
+import useThemeProps from '../styles/useThemeProps';
import capitalize from '../utils/capitalize';
+import { getListSubheaderUtilityClass } from './listSubheaderClasses';
-export const styles = (theme) => ({
- /* Styles applied to the root element. */
- root: {
- boxSizing: 'border-box',
- lineHeight: '48px',
- listStyle: 'none',
- color: theme.palette.text.secondary,
- fontFamily: theme.typography.fontFamily,
- fontWeight: theme.typography.fontWeightMedium,
- fontSize: theme.typography.pxToRem(14),
+const overridesResolver = (props, styles) => {
+ const { styleProps } = props;
+
+ return deepmerge(styles.root || {}, {
+ ...(styleProps.color !== 'default' && styles[`color${capitalize(styleProps.color)}`]),
+ ...(!styleProps.disableGutters && styles.gutters),
+ ...(styleProps.inset && styles.inset),
+ ...(!styleProps.disableSticky && styles.sticky),
+ });
+};
+
+const useUtilityClasses = (styleProps) => {
+ const { classes, color, disableGutters, inset, disableSticky } = styleProps;
+
+ const slots = {
+ root: [
+ 'root',
+ color !== 'default' && `color${capitalize(color)}`,
+ !disableGutters && 'gutters',
+ inset && 'inset',
+ !disableSticky && 'sticky',
+ ],
+ };
+
+ return composeClasses(slots, getListSubheaderUtilityClass, classes);
+};
+
+const ListSubheaderRoot = experimentalStyled(
+ 'li',
+ {},
+ {
+ name: 'MuiListSubheader',
+ slot: 'Root',
+ overridesResolver,
},
+)(({ theme, styleProps }) => ({
+ /* Styles applied to the root element. */
+ boxSizing: 'border-box',
+ lineHeight: '48px',
+ listStyle: 'none',
+ color: theme.palette.text.secondary,
+ fontFamily: theme.typography.fontFamily,
+ fontWeight: theme.typography.fontWeightMedium,
+ fontSize: theme.typography.pxToRem(14),
/* Styles applied to the root element if `color="primary"`. */
- colorPrimary: {
+ ...(styleProps.color === 'primary' && {
color: theme.palette.primary.main,
- },
+ }),
/* Styles applied to the root element if `color="inherit"`. */
- colorInherit: {
+ ...(styleProps.color === 'inherit' && {
color: 'inherit',
- },
- /* Styles applied to the inner `component` element unless `disableGutters={true}`. */
- gutters: {
+ }),
+ /* Styles applied to the root element unless `disableGutters={true}`. */
+ ...(!styleProps.disableGutters && {
paddingLeft: 16,
paddingRight: 16,
- },
+ }),
/* Styles applied to the root element if `inset={true}`. */
- inset: {
+ ...(styleProps.inset && {
paddingLeft: 72,
- },
+ }),
/* Styles applied to the root element unless `disableSticky={true}`. */
- sticky: {
+ ...(!styleProps.disableSticky && {
position: 'sticky',
top: 0,
zIndex: 1,
backgroundColor: 'inherit',
- },
-});
+ }),
+}));
-const ListSubheader = React.forwardRef(function ListSubheader(props, ref) {
+const ListSubheader = React.forwardRef(function ListSubheader(inProps, ref) {
+ const props = useThemeProps({ props: inProps, name: 'MuiListSubheader' });
const {
- classes,
className,
color = 'default',
- component: Component = 'li',
+ component = 'li',
disableGutters = false,
disableSticky = false,
inset = false,
...other
} = props;
+ const styleProps = {
+ ...props,
+ color,
+ component,
+ disableGutters,
+ disableSticky,
+ inset,
+ };
+
+ const classes = useUtilityClasses(styleProps);
+
return (
-