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

[Accordion] Add support for CSS variables #32542

Merged
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
108 changes: 108 additions & 0 deletions docs/pages/experiments/material-ui/accordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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 Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import Typography from '@mui/material/Typography';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';

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',
},
}}
>
<Box>
<Accordion>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography>Accordion 1</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse malesuada
lacus ex, sit amet blandit leo lobortis eget.
</Typography>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel2a-content"
id="panel2a-header"
>
<Typography>Accordion 2</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse malesuada
lacus ex, sit amet blandit leo lobortis eget.
</Typography>
</AccordionDetails>
</Accordion>
<Accordion disabled>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel3a-content"
id="panel3a-header"
>
<Typography>Disabled Accordion</Typography>
</AccordionSummary>
</Accordion>
</Box>
</Box>
</Container>
</CssVarsProvider>
);
}
12 changes: 6 additions & 6 deletions packages/mui-material/src/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const AccordionRoot = styled(Paper, {
height: 1,
content: '""',
opacity: 1,
backgroundColor: theme.palette.divider,
backgroundColor: (theme.vars || theme).palette.divider,
transition: theme.transitions.create(['opacity', 'background-color'], transition),
},
'&:first-of-type': {
Expand All @@ -85,20 +85,20 @@ const AccordionRoot = styled(Paper, {
},
},
[`&.${accordionClasses.disabled}`]: {
backgroundColor: theme.palette.action.disabledBackground,
backgroundColor: (theme.vars || theme).palette.action.disabledBackground,
},
};
},
({ theme, ownerState }) => ({
...(!ownerState.square && {
borderRadius: 0,
'&:first-of-type': {
borderTopLeftRadius: theme.shape.borderRadius,
borderTopRightRadius: theme.shape.borderRadius,
borderTopLeftRadius: (theme.vars || theme).shape.borderRadius,
borderTopRightRadius: (theme.vars || theme).shape.borderRadius,
},
'&:last-of-type': {
borderBottomLeftRadius: theme.shape.borderRadius,
borderBottomRightRadius: theme.shape.borderRadius,
borderBottomLeftRadius: (theme.vars || theme).shape.borderRadius,
borderBottomRightRadius: (theme.vars || theme).shape.borderRadius,
// Fix a rendering issue on Edge
'@supports (-ms-ime-align: auto)': {
borderBottomLeftRadius: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const AccordionSummaryRoot = styled(ButtonBase, {
padding: theme.spacing(0, 2),
transition: theme.transitions.create(['min-height', 'background-color'], transition),
[`&.${accordionSummaryClasses.focusVisible}`]: {
backgroundColor: theme.palette.action.focus,
backgroundColor: (theme.vars || theme).palette.action.focus,
},
[`&.${accordionSummaryClasses.disabled}`]: {
opacity: theme.palette.action.disabledOpacity,
opacity: (theme.vars || theme).palette.action.disabledOpacity,
},
[`&:hover:not(.${accordionSummaryClasses.disabled})`]: {
cursor: 'pointer',
Expand Down Expand Up @@ -78,7 +78,7 @@ const AccordionSummaryExpandIconWrapper = styled('div', {
overridesResolver: (props, styles) => styles.expandIconWrapper,
})(({ theme }) => ({
display: 'flex',
color: theme.palette.action.active,
color: (theme.vars || theme).palette.action.active,
transform: 'rotate(0deg)',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shortest,
Expand Down