Skip to content

Commit

Permalink
[CardActionArea] Add support for CSS variables (#32554)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicasas committed May 4, 2022
1 parent f7cb3b9 commit 15a2e11
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
86 changes: 86 additions & 0 deletions docs/pages/experiments/material-ui/card-action-area.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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 Card from '@mui/material/Card';
import CardActionArea from '@mui/material/CardActionArea';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Container from '@mui/material/Container';
import Typography from '@mui/material/Typography';
import Moon from '@mui/icons-material/DarkMode';
import Sun from '@mui/icons-material/LightMode';

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 CardActionAreaCssVars() {
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',
},
}}
>
<Card>
<CardActionArea>
<CardMedia
component="img"
height="140"
image="/static/images/cards/contemplative-reptile.jpg"
alt="green iguana"
/>
<CardContent>
<Typography gutterBottom variant="h5" component="div">
Lizard
</Typography>
<Typography variant="body2" color="text.secondary">
Lizards are a widespread group of squamate reptiles, with over 6,000 species,
ranging across all continents except Antarctica
</Typography>
</CardContent>
</CardActionArea>
</Card>
</Box>
</Container>
</CssVarsProvider>
);
}
4 changes: 2 additions & 2 deletions packages/mui-material/src/CardActionArea/CardActionArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const CardActionAreaRoot = styled(ButtonBase, {
textAlign: 'inherit',
width: '100%',
[`&:hover .${cardActionAreaClasses.focusHighlight}`]: {
opacity: theme.palette.action.hoverOpacity,
opacity: (theme.vars || theme).palette.action.hoverOpacity,
'@media (hover: none)': {
opacity: 0,
},
},
[`&.${cardActionAreaClasses.focusVisible} .${cardActionAreaClasses.focusHighlight}`]: {
opacity: theme.palette.action.focusOpacity,
opacity: (theme.vars || theme).palette.action.focusOpacity,
},
}));

Expand Down

0 comments on commit 15a2e11

Please sign in to comment.