Skip to content

Commit

Permalink
[StepLabel, StepIcon] Add support for CSS variables (#32609)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicasas authored May 5, 2022
1 parent f6f6726 commit 27a09c8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 9 deletions.
84 changes: 84 additions & 0 deletions docs/pages/experiments/material-ui/step.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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 SettingsIcon from '@mui/icons-material/Settings';
import { Step, StepIcon, StepLabel, Stepper } from '@mui/material';

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>
);
};

const steps = ['Step 1', 'Step 2', 'Step 3'];

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 sx={{ width: '100%' }}>
<Stepper activeStep={1} alternativeLabel>
{steps.map((label) => (
<Step key={label}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
</Box>
<Box sx={{ width: '100%' }}>
<Stepper activeStep={1} alternativeLabel>
{steps.map((label) => (
<Step key={label}>
<StepLabel icon={<StepIcon icon={<SettingsIcon />} />}>{label}</StepLabel>
</Step>
))}
</Stepper>
</Box>
</Box>
</Container>
</CssVarsProvider>
);
}
10 changes: 5 additions & 5 deletions packages/mui-material/src/StepIcon/StepIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const StepIconRoot = styled(SvgIcon, {
transition: theme.transitions.create('color', {
duration: theme.transitions.duration.shortest,
}),
color: theme.palette.text.disabled,
color: (theme.vars || theme).palette.text.disabled,
[`&.${stepIconClasses.completed}`]: {
color: theme.palette.primary.main,
color: (theme.vars || theme).palette.primary.main,
},
[`&.${stepIconClasses.active}`]: {
color: theme.palette.primary.main,
color: (theme.vars || theme).palette.primary.main,
},
[`&.${stepIconClasses.error}`]: {
color: theme.palette.error.main,
color: (theme.vars || theme).palette.error.main,
},
}));

Expand All @@ -46,7 +46,7 @@ const StepIconText = styled('text', {
slot: 'Text',
overridesResolver: (props, styles) => styles.text,
})(({ theme }) => ({
fill: theme.palette.primary.contrastText,
fill: (theme.vars || theme).palette.primary.contrastText,
fontSize: theme.typography.caption.fontSize,
fontFamily: theme.typography.fontFamily,
}));
Expand Down
8 changes: 4 additions & 4 deletions packages/mui-material/src/StepLabel/StepLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ const StepLabelLabel = styled('span', {
duration: theme.transitions.duration.shortest,
}),
[`&.${stepLabelClasses.active}`]: {
color: theme.palette.text.primary,
color: (theme.vars || theme).palette.text.primary,
fontWeight: 500,
},
[`&.${stepLabelClasses.completed}`]: {
color: theme.palette.text.primary,
color: (theme.vars || theme).palette.text.primary,
fontWeight: 500,
},
[`&.${stepLabelClasses.alternativeLabel}`]: {
textAlign: 'center',
marginTop: 16,
},
[`&.${stepLabelClasses.error}`]: {
color: theme.palette.error.main,
color: (theme.vars || theme).palette.error.main,
},
}));

Expand All @@ -104,7 +104,7 @@ const StepLabelLabelContainer = styled('span', {
overridesResolver: (props, styles) => styles.labelContainer,
})(({ theme }) => ({
width: '100%',
color: theme.palette.text.secondary,
color: (theme.vars || theme).palette.text.secondary,
}));

const StepLabel = React.forwardRef(function StepLabel(inProps, ref) {
Expand Down

0 comments on commit 27a09c8

Please sign in to comment.