-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MobileStepper] Add support for CSS vars (#32606)
- Loading branch information
1 parent
040538b
commit f614491
Showing
2 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import * as React from 'react'; | ||
import { | ||
Experimental_CssVarsProvider as CssVarsProvider, | ||
useColorScheme, | ||
useTheme, | ||
} from '@mui/material/styles'; | ||
import CssBaseline from '@mui/material/CssBaseline'; | ||
import Box from '@mui/material/Box'; | ||
import Container from '@mui/material/Container'; | ||
import Moon from '@mui/icons-material/DarkMode'; | ||
import Sun from '@mui/icons-material/LightMode'; | ||
import MobileStepper from '@mui/material/MobileStepper'; | ||
import Paper from '@mui/material/Paper'; | ||
import Typography from '@mui/material/Typography'; | ||
import Button from '@mui/material/Button'; | ||
import KeyboardArrowLeft from '@mui/icons-material/KeyboardArrowLeft'; | ||
import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight'; | ||
|
||
const steps = [ | ||
{ | ||
label: 'Select campaign settings', | ||
description: `For each ad campaign that you create, you can control how much | ||
you're willing to spend on clicks and conversions, which networks | ||
and geographical locations you want your ads to show on, and more.`, | ||
}, | ||
{ | ||
label: 'Create an ad group', | ||
description: 'An ad group contains one or more ads which target a shared set of keywords.', | ||
}, | ||
{ | ||
label: 'Create an ad', | ||
description: `Try out different ad text to see what brings in the most customers, | ||
and learn how to enhance your ads using features like ad extensions. | ||
If you run into any problems with your ads, find out how to tell if | ||
they're running and how to resolve approval issues.`, | ||
}, | ||
]; | ||
|
||
function TextMobileStepper() { | ||
const theme = useTheme(); | ||
const [activeStep, setActiveStep] = React.useState(0); | ||
const maxSteps = steps.length; | ||
|
||
const handleNext = () => { | ||
setActiveStep((prevActiveStep) => prevActiveStep + 1); | ||
}; | ||
|
||
const handleBack = () => { | ||
setActiveStep((prevActiveStep) => prevActiveStep - 1); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ maxWidth: 400, flexGrow: 1 }}> | ||
<Paper | ||
square | ||
elevation={0} | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
height: 50, | ||
pl: 2, | ||
bgcolor: 'background.default', | ||
}} | ||
> | ||
<Typography>{steps[activeStep].label}</Typography> | ||
</Paper> | ||
<Box sx={{ height: 255, maxWidth: 400, width: '100%', p: 2 }}> | ||
{steps[activeStep].description} | ||
</Box> | ||
<MobileStepper | ||
variant="text" | ||
steps={maxSteps} | ||
position="static" | ||
activeStep={activeStep} | ||
nextButton={ | ||
<Button size="small" onClick={handleNext} disabled={activeStep === maxSteps - 1}> | ||
Next | ||
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />} | ||
</Button> | ||
} | ||
backButton={ | ||
<Button size="small" onClick={handleBack} disabled={activeStep === 0}> | ||
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />} | ||
Back | ||
</Button> | ||
} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
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>Mobile Stepper</Box> | ||
|
||
<Box> | ||
<TextMobileStepper /> | ||
</Box> | ||
</Box> | ||
</Container> | ||
</CssVarsProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters