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

[Drawer] Add support for CSS variables #32565

Merged
merged 1 commit into from
May 4, 2022
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
84 changes: 84 additions & 0 deletions docs/pages/experiments/material-ui/drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import * as React from 'react';

import Moon from '@mui/icons-material/DarkMode';
import Sun from '@mui/icons-material/LightMode';
import MailIcon from '@mui/icons-material/Mail';
import InboxIcon from '@mui/icons-material/MoveToInbox';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Container from '@mui/material/Container';
import CssBaseline from '@mui/material/CssBaseline';
import Drawer from '@mui/material/Drawer';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import {
Experimental_CssVarsProvider as CssVarsProvider,
useColorScheme,
} from '@mui/material/styles';

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={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(256px, 1fr))',
gridAutoRows: 'minmax(160px, auto)',
gap: 2,
'& > div': {
placeSelf: 'center',
},
}}
>
<Drawer anchor="left" open className="1111">
<Box sx={{ width: 250 }} role="presentation">
<List>
<ListItem>
<ColorSchemePicker />
</ListItem>
</List>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
<ListItem button key={text}>
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
</Box>
</Drawer>
</Box>
</Container>
</CssVarsProvider>
);
}
12 changes: 6 additions & 6 deletions packages/mui-material/src/Drawer/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DrawerRoot = styled(Modal, {
slot: 'Root',
overridesResolver,
})(({ theme }) => ({
zIndex: theme.zIndex.drawer,
zIndex: (theme.vars || theme).zIndex.drawer,
}));

const DrawerDockedRoot = styled('div', {
Expand Down Expand Up @@ -76,7 +76,7 @@ const DrawerPaper = styled(Paper, {
flexDirection: 'column',
height: '100%',
flex: '1 0 auto',
zIndex: theme.zIndex.drawer,
zIndex: (theme.vars || theme).zIndex.drawer,
// Add iOS momentum scrolling for iOS < 13.0
WebkitOverflowScrolling: 'touch',
// temporary style
Expand Down Expand Up @@ -109,19 +109,19 @@ const DrawerPaper = styled(Paper, {
}),
...(ownerState.anchor === 'left' &&
ownerState.variant !== 'temporary' && {
borderRight: `1px solid ${theme.palette.divider}`,
borderRight: `1px solid ${(theme.vars || theme).palette.divider}`,
}),
...(ownerState.anchor === 'top' &&
ownerState.variant !== 'temporary' && {
borderBottom: `1px solid ${theme.palette.divider}`,
borderBottom: `1px solid ${(theme.vars || theme).palette.divider}`,
}),
...(ownerState.anchor === 'right' &&
ownerState.variant !== 'temporary' && {
borderLeft: `1px solid ${theme.palette.divider}`,
borderLeft: `1px solid ${(theme.vars || theme).palette.divider}`,
}),
...(ownerState.anchor === 'bottom' &&
ownerState.variant !== 'temporary' && {
borderTop: `1px solid ${theme.palette.divider}`,
borderTop: `1px solid ${(theme.vars || theme).palette.divider}`,
}),
}));

Expand Down