Skip to content

Commit

Permalink
[ListSubheader] Add support for CSS variables (#32584)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mba authored May 4, 2022
1 parent ca0c119 commit 9b83b90
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
71 changes: 71 additions & 0 deletions docs/pages/experiments/material-ui/list-subheader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as React from 'react';
import {
Experimental_CssVarsProvider as CssVarsProvider,
useColorScheme,
} from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Container from '@mui/material/Container';
import Moon from '@mui/icons-material/DarkMode';
import Sun from '@mui/icons-material/LightMode';
import List from '@mui/material/List';
import ListSubheader from '@mui/material/ListSubheader';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';

const ColorSchemePicker = () => {
const { mode, setMode } = useColorScheme();
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}

return (
<Button
variant="outlined"
onClick={() => {
if (mode === 'light') {
setMode('dark');
} else {
setMode('light');
}
}}
>
{mode === 'light' ? <Moon /> : <Sun />}
</Button>
);
};

export default function CssVarsTemplate() {
return (
<CssVarsProvider>
<CssBaseline />
<Container sx={{ my: 5 }}>
<Box sx={{ pb: 2 }}>
<ColorSchemePicker />
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(256px, 1fr))',
gridAutoRows: 'minmax(160px, auto)',
gap: 2,
'& > div': {
placeSelf: 'center',
},
}}
>
<List subheader={<ListSubheader>Subheader</ListSubheader>}>
<ListItem>
<ListItemText primary="Test" />
</ListItem>
</List>
</Box>
</Container>
</CssVarsProvider>
);
}
6 changes: 3 additions & 3 deletions packages/mui-material/src/ListSubheader/ListSubheader.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const ListSubheaderRoot = styled('li', {
boxSizing: 'border-box',
lineHeight: '48px',
listStyle: 'none',
color: theme.palette.text.secondary,
color: (theme.vars || theme).palette.text.secondary,
fontFamily: theme.typography.fontFamily,
fontWeight: theme.typography.fontWeightMedium,
fontSize: theme.typography.pxToRem(14),
...(ownerState.color === 'primary' && {
color: theme.palette.primary.main,
color: (theme.vars || theme).palette.primary.main,
}),
...(ownerState.color === 'inherit' && {
color: 'inherit',
Expand All @@ -62,7 +62,7 @@ const ListSubheaderRoot = styled('li', {
position: 'sticky',
top: 0,
zIndex: 1,
backgroundColor: theme.palette.background.paper,
backgroundColor: (theme.vars || theme).palette.background.paper,
}),
}));

Expand Down

0 comments on commit 9b83b90

Please sign in to comment.