-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add page for CSS variables support in @mui/material (#32050)
- Loading branch information
Showing
19 changed files
with
552 additions
and
5 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
docs/data/material/experimental-api/css-variables/CssVariablesCustomization.js
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,32 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/material/Button'; | ||
import { colorChannel } from '@mui/system'; | ||
import { | ||
Experimental_CssVarsProvider as CssVarsProvider, | ||
styled, | ||
} from '@mui/material/styles'; | ||
|
||
// Custom button using custom styles with CSS variables | ||
const CustomButton = styled(Button)(({ theme }) => ({ | ||
backgroundColor: theme.vars.palette.success.dark, | ||
color: theme.vars.palette.common.white, | ||
'&:hover': { | ||
backgroundColor: `rgba(${theme.vars.palette.success.mainChannel} / 0.95)`, | ||
}, | ||
})); | ||
|
||
// Custom button using CSS variables | ||
const CssVarsCustomButton = styled(Button)({ | ||
'--md-palette-primary-main': '#FF0000', | ||
'--md-palette-primary-dark': '#8B0000', | ||
'--md-palette-primary-mainChannel': colorChannel('#FF0000'), // necessary for calculating the alpha values | ||
}); | ||
|
||
export default function App() { | ||
return ( | ||
<CssVarsProvider> | ||
<CustomButton sx={{ mr: 1 }}>Custom styles</CustomButton> | ||
<CssVarsCustomButton variant="contained">CSS variables</CssVarsCustomButton> | ||
</CssVarsProvider> | ||
); | ||
} |
118 changes: 118 additions & 0 deletions
118
docs/data/material/experimental-api/css-variables/CssVarsCustomTheme.js
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,118 @@ | ||
import * as React from 'react'; | ||
import { | ||
Experimental_CssVarsProvider as CssVarsProvider, | ||
useColorScheme, | ||
experimental_extendTheme, | ||
} from '@mui/material/styles'; | ||
import Moon from '@mui/icons-material/DarkMode'; | ||
import Sun from '@mui/icons-material/LightMode'; | ||
import Button from '@mui/material/Button'; | ||
import Box from '@mui/material/Box'; | ||
import { teal, deepOrange, orange, cyan } from '@mui/material/colors'; | ||
|
||
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 theme = experimental_extendTheme({ | ||
colorSchemes: { | ||
light: { | ||
palette: { | ||
primary: teal, | ||
secondary: deepOrange, | ||
}, | ||
}, | ||
dark: { | ||
palette: { | ||
primary: cyan, | ||
secondary: orange, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
export default function Page() { | ||
return ( | ||
<CssVarsProvider theme={theme}> | ||
<Box bgcolor="background.paper" sx={{ p: 1 }}> | ||
<Box sx={{ py: 2, mx: 'auto' }}> | ||
<Box sx={{ pb: 4 }}> | ||
<ColorSchemePicker /> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button variant="contained">Text</Button> | ||
<Button variant="outlined">Text</Button> | ||
<Button>Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="secondary" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="secondary" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="secondary">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="error" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="error" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="error">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="info" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="info" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="info">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="warning" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="warning" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="warning">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="success" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="success" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="success">Text</Button> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</CssVarsProvider> | ||
); | ||
} |
118 changes: 118 additions & 0 deletions
118
docs/data/material/experimental-api/css-variables/CssVarsCustomTheme.tsx
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,118 @@ | ||
import * as React from 'react'; | ||
import { | ||
Experimental_CssVarsProvider as CssVarsProvider, | ||
useColorScheme, | ||
experimental_extendTheme, | ||
} from '@mui/material/styles'; | ||
import Moon from '@mui/icons-material/DarkMode'; | ||
import Sun from '@mui/icons-material/LightMode'; | ||
import Button from '@mui/material/Button'; | ||
import Box from '@mui/material/Box'; | ||
import { teal, deepOrange, orange, cyan } from '@mui/material/colors'; | ||
|
||
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 theme = experimental_extendTheme({ | ||
colorSchemes: { | ||
light: { | ||
palette: { | ||
primary: teal, | ||
secondary: deepOrange, | ||
}, | ||
}, | ||
dark: { | ||
palette: { | ||
primary: cyan, | ||
secondary: orange, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
export default function Page() { | ||
return ( | ||
<CssVarsProvider theme={theme}> | ||
<Box bgcolor="background.paper" sx={{ p: 1 }}> | ||
<Box sx={{ py: 2, mx: 'auto' }}> | ||
<Box sx={{ pb: 4 }}> | ||
<ColorSchemePicker /> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button variant="contained">Text</Button> | ||
<Button variant="outlined">Text</Button> | ||
<Button>Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="secondary" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="secondary" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="secondary">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="error" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="error" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="error">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="info" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="info" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="info">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="warning" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="warning" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="warning">Text</Button> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 4, mb: 1 }}> | ||
<Button color="success" variant="contained"> | ||
Text | ||
</Button> | ||
<Button color="success" variant="outlined"> | ||
Text | ||
</Button> | ||
<Button color="success">Text</Button> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</CssVarsProvider> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
docs/data/material/experimental-api/css-variables/CssVarsProviderBasic.tsx.preview
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,3 @@ | ||
<CssVarsProvider> | ||
<ThemeConsumer /> | ||
</CssVarsProvider> |
Oops, something went wrong.