Skip to content

Commit

Permalink
add CSS variable support
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mba committed May 3, 2022
1 parent 0c5a0b0 commit dac2805
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions docs/pages/experiments/material-ui/list-item-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 ListItem from '@mui/material/ListItem';
import ListItemButton from '@mui/material/ListItemButton';
import ListItemIcon from '@mui/material/ListItemIcon';
import CommentIcon from '@mui/icons-material/Comment';
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>
<ListItem>
<ListItemButton>
<ListItemIcon>
<CommentIcon />
</ListItemIcon>
<ListItemText primary="Test" />
</ListItemButton>
</ListItem>
</List>
</Box>
</Container>
</CssVarsProvider>
);
}
2 changes: 1 addition & 1 deletion packages/mui-material/src/ListItemIcon/ListItemIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ListItemIconRoot = styled('div', {
},
})(({ theme, ownerState }) => ({
minWidth: 56,
color: theme.palette.action.active,
color: (theme.vars || theme).palette.action.active,
flexShrink: 0,
display: 'inline-flex',
...(ownerState.alignItems === 'flex-start' && {
Expand Down

0 comments on commit dac2805

Please sign in to comment.