Skip to content

Commit

Permalink
[SpeedDial] Add support for CSS variables (#32613)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisasanib authored May 4, 2022
1 parent 8944bfc commit 3c86459
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
87 changes: 87 additions & 0 deletions docs/pages/experiments/material-ui/speed-dial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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 SpeedDial from '@mui/material/SpeedDial';
import SpeedDialIcon from '@mui/material/SpeedDialIcon';
import SpeedDialAction from '@mui/material/SpeedDialAction';
import FileCopyIcon from '@mui/icons-material/FileCopyOutlined';
import SaveIcon from '@mui/icons-material/Save';
import PrintIcon from '@mui/icons-material/Print';
import ShareIcon from '@mui/icons-material/Share';

const actions = [
{ icon: <FileCopyIcon />, name: 'Copy' },
{ icon: <SaveIcon />, name: 'Save' },
{ icon: <PrintIcon />, name: 'Print' },
{ icon: <ShareIcon />, name: 'Share' },
];

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 SpeedDialActionCssVars() {
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',
},
}}
>
<Box sx={{ height: 320, transform: 'translateZ(0px)', flexGrow: 1 }}>
<SpeedDial
ariaLabel="SpeedDial basic example"
sx={{ position: 'absolute', bottom: 16, right: 16 }}
icon={<SpeedDialIcon />}
>
{actions.map((action) => (
<SpeedDialAction key={action.name} icon={action.icon} tooltipTitle={action.name} />
))}
</SpeedDial>
</Box>
</Box>
</Container>
</CssVarsProvider>
);
}
2 changes: 1 addition & 1 deletion packages/mui-material/src/SpeedDial/SpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SpeedDialRoot = styled('div', {
return [styles.root, styles[`direction${capitalize(ownerState.direction)}`]];
},
})(({ theme, ownerState }) => ({
zIndex: theme.zIndex.speedDial,
zIndex: (theme.vars || theme).zIndex.speedDial,
display: 'flex',
alignItems: 'center',
pointerEvents: 'none',
Expand Down

0 comments on commit 3c86459

Please sign in to comment.