index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Inline.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Inline() { return ( <div style={{ width: '100%' }}> <Box component="div" sx={{ display: 'inline', p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > inline </Box> <Box component="div" sx={{ display: 'inline', p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > inline </Box> </div> ); }
3,800
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Overflow.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Overflow() { return ( <div style={{ width: 200, whiteSpace: 'nowrap' }}> <Box component="div" sx={{ overflow: 'hidden', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Not scrollable, overflow is hidden </Box> <Box component="div" sx={{ overflow: 'auto', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Try scrolling this overflow auto box </Box> </div> ); }
3,801
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Overflow.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Overflow() { return ( <div style={{ width: 200, whiteSpace: 'nowrap' }}> <Box component="div" sx={{ overflow: 'hidden', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Not scrollable, overflow is hidden </Box> <Box component="div" sx={{ overflow: 'auto', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Try scrolling this overflow auto box </Box> </div> ); }
3,802
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Print.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Print() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'block', displayPrint: 'none', m: 1, fontSize: '0.875rem', fontWeight: '700', }} > Screen Only (Hide on print only) </Box> <Box sx={{ display: 'none', displayPrint: 'block', m: 1, fontSize: '0.875rem', fontWeight: '700', }} > Print Only (Hide on screen only) </Box> </div> ); }
3,803
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Print.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Print() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'block', displayPrint: 'none', m: 1, fontSize: '0.875rem', fontWeight: '700', }} > Screen Only (Hide on print only) </Box> <Box sx={{ display: 'none', displayPrint: 'block', m: 1, fontSize: '0.875rem', fontWeight: '700', }} > Print Only (Hide on screen only) </Box> </div> ); }
3,804
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/TextOverflow.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function TextOverflow() { return ( <div style={{ width: 200, whiteSpace: 'nowrap' }}> <Box component="div" sx={{ textOverflow: 'clip', overflow: 'hidden', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum is simply dummy text </Box> <Box component="div" sx={{ textOverflow: 'ellipsis', overflow: 'hidden', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum is simply dummy text </Box> </div> ); }
3,805
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/TextOverflow.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function TextOverflow() { return ( <div style={{ width: 200, whiteSpace: 'nowrap' }}> <Box component="div" sx={{ textOverflow: 'clip', overflow: 'hidden', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum is simply dummy text </Box> <Box component="div" sx={{ textOverflow: 'ellipsis', overflow: 'hidden', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum is simply dummy text </Box> </div> ); }
3,806
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Visibility.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Visibility() { return ( <div style={{ width: '100%' }}> <Box component="span" sx={{ visibility: 'visible', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Visible container </Box> <Box component="span" sx={{ visibility: 'hidden', p: 1, m: 1, bgcolor: 'background.paper', }} > Invisible container </Box> </div> ); }
3,807
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/Visibility.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Visibility() { return ( <div style={{ width: '100%' }}> <Box component="span" sx={{ visibility: 'visible', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Visible container </Box> <Box component="span" sx={{ visibility: 'hidden', p: 1, m: 1, bgcolor: 'background.paper', }} > Invisible container </Box> </div> ); }
3,808
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/WhiteSpace.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function WhiteSpace() { return ( <div style={{ width: 200 }}> <Box component="div" sx={{ whiteSpace: 'nowrap', overflowX: 'auto', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s. </Box> <Box component="div" sx={{ whiteSpace: 'normal', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s. </Box> </div> ); }
3,809
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/WhiteSpace.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function WhiteSpace() { return ( <div style={{ width: 200 }}> <Box component="div" sx={{ whiteSpace: 'nowrap', overflowX: 'auto', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s. </Box> <Box component="div" sx={{ whiteSpace: 'normal', my: 2, p: 1, bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s. </Box> </div> ); }
3,810
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/display/display.md
# Display <p class="description">Quickly and responsively toggle the display, overflow, visibility, and more with the display utilities.</p> ## Examples ### Inline {{"demo": "Inline.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box component="div" sx={{ display: 'inline' }}>inline</Box> <Box component="div" sx={{ display: 'inline' }}>inline</Box> ``` ### Block {{"demo": "Block.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box component="span" sx={{ display: 'block' }}>block</Box> <Box component="span" sx={{ display: 'block' }}>block</Box> ``` ## Hiding elements For faster mobile-friendly development, use responsive display classes for showing and hiding elements by device. Avoid creating entirely different versions of the same site, instead hide element responsively for each screen size. | Screen Size | Class | | :----------------- | :----------------------------------------------------------- | | Hidden on all | `sx={{ display: 'none' }}` | | Hidden only on xs | `sx={{ display: { xs: 'none', sm: 'block' } }}` | | Hidden only on sm | `sx={{ display: { xs: 'block', sm: 'none', md: 'block' } }}` | | Hidden only on md | `sx={{ display: { xs: 'block', md: 'none', lg: 'block' } }}` | | Hidden only on lg | `sx={{ display: { xs: 'block', lg: 'none', xl: 'block' } }}` | | Hidden only on xl | `sx={{ display: { xs: 'block', xl: 'none' } }}` | | Visible only on xs | `sx={{ display: { xs: 'block', sm: 'none' } }}` | | Visible only on sm | `sx={{ display: { xs: 'none', sm: 'block', md: 'none' } }}` | | Visible only on md | `sx={{ display: { xs: 'none', md: 'block', lg: 'none' } }}` | | Visible only on lg | `sx={{ display: { xs: 'none', lg: 'block', xl: 'none' } }}` | | Visible only on xl | `sx={{ display: { xs: 'none', xl: 'block' } }}` | {{"demo": "Hiding.js", "defaultCodeOpen": false}} ```jsx <Box sx={{ display: { xs: 'block', md: 'none' }}}> hide on screens wider than md </Box> <Box sx={{ display: { xs: 'none', md: 'block' }}}> hide on screens smaller than md </Box> ``` ## Display in print {{"demo": "Print.js", "defaultCodeOpen": false}} ```jsx <Box sx={{ display: 'block', displayPrint: 'none' }}> Screen Only (Hide on print only) </Box> <Box sx={{ display: 'none', displayPrint: 'block' }}> Print Only (Hide on screen only) </Box> ``` ## Overflow {{"demo": "Overflow.js", "defaultCodeOpen": false}} ```jsx <Box component="div" sx={{ overflow: 'hidden' }}> Not scrollable, overflow is hidden </Box> <Box component="div" sx={{ overflow: 'auto' }}> Try scrolling this overflow auto box </Box> ``` ## Text overflow {{"demo": "TextOverflow.js", "defaultCodeOpen": false}} ```jsx <Box component="div" sx={{ textOverflow: 'clip' }}> Lorem Ipsum is simply dummy text </Box> <Box component="div" sx={{ textOverflow: 'ellipsis' }}> Lorem Ipsum is simply dummy text </Box> ``` ## Visibility {{"demo": "Visibility.js", "defaultCodeOpen": false}} ```jsx <Box component="div" sx={{ visibility: 'visible' }}> Visible container </Box> <Box component="div" sx={{ visibility: 'hidden' }}> Invisible container </Box> ``` ## White space {{"demo": "WhiteSpace.js", "defaultCodeOpen": false}} ```jsx <Box component="div" sx={{ whiteSpace: 'nowrap' }}> Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. </Box> <Box component="div" sx={{ whiteSpace: 'normal' }}> Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. </Box> ``` ## API ```js import { display } from '@mui/system'; ``` | Import name | Prop | CSS property | Theme key | | :------------- | :------------- | :-------------- | :-------- | | `displayPrint` | `displayPrint` | `display` | none | | `displayRaw` | `display` | `display` | none | | `overflow` | `overflow` | `overflow` | none | | `textOverflow` | `textOverflow` | `text-overflow` | none | | `visibility` | `visibility` | `visibility` | none | | `whiteSpace` | `whiteSpace` | `white-space` | none |
3,811
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/ChangeTheBehaviorSxProp.js
import * as React from 'react'; import { Box, Stack } from '@mui/system'; import { createTheme, ThemeProvider } from '@mui/material/styles'; // Retain type safety. const theme = createTheme({ unstable_sxConfig: { // You can now use the borderRadius key in sx // by providing direct values from the palette borderRadius: { themeKey: 'shape', }, }, shape: { sm: 4, md: 8, lg: 12, }, }); export default function ChangeTheBehaviorSxProp() { return ( <Stack direction="row" gap={1}> <ThemeProvider theme={theme}> <Box sx={{ borderRadius: 'sm', border: 1, p: 4 }} /> <Box sx={{ borderRadius: 'md', border: 1, p: 4 }} /> <Box sx={{ borderRadius: 'lg', border: 1, p: 4 }} /> </ThemeProvider> </Stack> ); }
3,812
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/ChangeTheBehaviorSxProp.tsx
import * as React from 'react'; import { Box, Stack } from '@mui/system'; import { createTheme, ThemeProvider } from '@mui/material/styles'; // Retain type safety. declare module '@mui/system' { interface Shape { sm: number; md: number; lg: number; } } const theme = createTheme({ unstable_sxConfig: { // You can now use the borderRadius key in sx // by providing direct values from the palette borderRadius: { themeKey: 'shape', }, }, shape: { sm: 4, md: 8, lg: 12, }, }); export default function ChangeTheBehaviorSxProp() { return ( <Stack direction="row" gap={1}> <ThemeProvider theme={theme}> <Box sx={{ borderRadius: 'sm', border: 1, p: 4 }} /> <Box sx={{ borderRadius: 'md', border: 1, p: 4 }} /> <Box sx={{ borderRadius: 'lg', border: 1, p: 4 }} /> </ThemeProvider> </Stack> ); }
3,813
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/ChangeTheBehaviorSxProp.tsx.preview
<ThemeProvider theme={theme}> <Box sx={{ borderRadius: 'sm', border: 1, p: 4 }} /> <Box sx={{ borderRadius: 'md', border: 1, p: 4 }} /> <Box sx={{ borderRadius: 'lg', border: 1, p: 4 }} /> </ThemeProvider>
3,814
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/ExtendTheSxProp.js
import * as React from 'react'; import { Box, handleBreakpoints } from '@mui/system'; import { createTheme, ThemeProvider } from '@mui/material/styles'; const customTheme = createTheme({ unstable_sxConfig: { size: { style: (props) => { const { size, theme } = props; const styleFromPropValue = (propValueFinal) => { const value = theme.spacing(propValueFinal); return { width: value, height: value, }; }; // Adding support for the breakpoints syntax return handleBreakpoints(props, size, styleFromPropValue); }, }, }, }); export default function ExtendTheSxProp() { return ( <ThemeProvider theme={customTheme}> <Box sx={{ size: 10, border: 1, }} /> </ThemeProvider> ); }
3,815
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/ExtendTheSxProp.tsx
import * as React from 'react'; import { Box, handleBreakpoints } from '@mui/system'; import { createTheme, ThemeProvider } from '@mui/material/styles'; const customTheme = createTheme({ unstable_sxConfig: { size: { style: (props) => { const { size, theme } = props; const styleFromPropValue = (propValueFinal: number) => { const value = theme.spacing(propValueFinal); return { width: value, height: value, }; }; // Adding support for the breakpoints syntax return handleBreakpoints(props, size, styleFromPropValue); }, }, }, }); export default function ExtendTheSxProp() { return ( <ThemeProvider theme={customTheme}> <Box sx={{ size: 10, border: 1, }} /> </ThemeProvider> ); }
3,816
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/ExtendTheSxProp.tsx.preview
<ThemeProvider theme={customTheme}> <Box sx={{ size: 10, border: 1, }} /> </ThemeProvider>
3,817
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/configure-the-sx-prop/configure-the-sx-prop.md
# Configure the sx prop <p class="description">Learn about the experimental API for extending or changing the behavior of the sx prop.</p> ## Extend the sx prop You can add new keys to be processed by the `sx` prop by extending the `unstable_sxConfig` option inside the theme, as shown below: {{"demo": "ExtendTheSxProp.js"}} ## Override existing behavior It is also possible to change some of the existing behavior of the `sx` prop. For example, in some design systems, the border radiuses need to be restricted to specific values, instead of allowing any number to be used—as is the default with MUI System. You can change this behavior by providing a custom config for the `borderRadius` property: {{"demo": "ChangeTheBehaviorSxProp.js"}} ## API Each value of the config inside `unstable_sxConfig` accepts the following properties: - `cssProperty` (_string_ [optional]): Indicates the CSS property, if it is different than the key - `themeKey` (_string_ [optional]): The path of the theme mapping - `transform` (_(cssValue: unknown, userValue: unknown) => number | string | React.CSSProperties | CSSObject_ [optional]): Lets users define a function that can transform the value before it's returned - `style` (_(props: any) => CSSObject_ [optional]): Offers maximum customizability. Note that you need to make sure that the breakpoint values can be processed
3,818
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/css-theme-variables/CreateCssVarsProvider.js
import * as React from 'react'; import { unstable_createCssVarsProvider as createCssVarsProvider, unstable_prepareCssVars as prepareCssVars, styled, } from '@mui/system'; const lightColorScheme = { palette: { mode: 'light', primary: { default: '#3990FF', dark: '#02367D', }, text: { default: '#111111', }, // ... other colors }, }; const darkColorScheme = { palette: { mode: 'dark', primary: { default: '#265D97', dark: '#132F4C', main: '#5090D3', }, text: { default: '#ffffff', }, // ... other colors }, }; function extendTheme({ cssVarPrefix = 'system-demo' } = {}) { const { vars: themeVars, generateCssVars } = prepareCssVars( { colorSchemes: { light: lightColorScheme, dark: darkColorScheme, }, }, { prefix: cssVarPrefix, }, ); const theme = { colorSchemes: { light: lightColorScheme, dark: darkColorScheme, }, // ... any other objects independent of color-scheme, // like fontSizes, spacing etc vars: themeVars, generateCssVars, palette: { ...lightColorScheme.palette, colorScheme: 'light', }, }; return theme; } const myCustomDefaultTheme = extendTheme(); const { CssVarsProvider, useColorScheme } = createCssVarsProvider({ theme: myCustomDefaultTheme, modeStorageKey: 'system-demo-mode', attribute: 'data-system-demo-color-scheme', defaultColorScheme: { light: 'light', dark: 'dark', }, }); const Button = styled('button')(({ theme }) => ({ backgroundColor: theme.vars.palette.primary.default, border: `1px solid ${theme.vars.palette.primary.dark}`, color: theme.vars.palette.text.default, padding: 10, borderRadius: 5, fontWeight: 'bold', })); const WrapperDiv = styled('div')(({ theme }) => ({ width: '100%', minHeight: 100, padding: 20, color: theme.vars.palette.text.default, backgroundColor: theme.palette.mode === 'dark' ? '#111' : '#fff', })); function App() { // changes specific to this demo. const [shouldRender, setShouldRender] = React.useState(false); const { setMode, mode } = useColorScheme(); const toggleMode = () => { setMode(mode === 'dark' ? 'light' : 'dark'); }; // to avoid hydration error in demo. unrelated to the actual implementation React.useEffect(() => { setShouldRender(true); }, []); if (!shouldRender) { return null; } return ( <WrapperDiv className="App"> <div className="card"> <h2>Current mode: {mode}</h2> <Button type="button" onClick={toggleMode}> Toggle Mode </Button> </div> </WrapperDiv> ); } export default function CreateCssVarsProvider() { return ( <CssVarsProvider> <App /> </CssVarsProvider> ); }
3,819
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/css-theme-variables/CreateCssVarsProvider.tsx
import * as React from 'react'; import { unstable_createCssVarsProvider as createCssVarsProvider, unstable_prepareCssVars as prepareCssVars, styled, } from '@mui/system'; type Theme = { colorSchemes: { light: typeof lightColorScheme; dark: typeof lightColorScheme; }; palette: { colorScheme: 'light' | 'dark'; } & (typeof lightColorScheme)['palette']; vars: ReturnType<typeof prepareCssVars>['vars']; generateCssVars: ReturnType<typeof prepareCssVars>['generateCssVars']; }; const lightColorScheme = { palette: { mode: 'light', primary: { default: '#3990FF', dark: '#02367D', }, text: { default: '#111111', }, // ... other colors }, }; const darkColorScheme = { palette: { mode: 'dark', primary: { default: '#265D97', dark: '#132F4C', main: '#5090D3', }, text: { default: '#ffffff', }, // ... other colors }, }; function extendTheme({ cssVarPrefix = 'system-demo' } = {}) { const { vars: themeVars, generateCssVars } = prepareCssVars( { colorSchemes: { light: lightColorScheme, dark: darkColorScheme, }, }, { prefix: cssVarPrefix, }, ); const theme: Theme = { colorSchemes: { light: lightColorScheme, dark: darkColorScheme, }, // ... any other objects independent of color-scheme, // like fontSizes, spacing etc vars: themeVars, generateCssVars, palette: { ...lightColorScheme.palette, colorScheme: 'light', }, }; return theme; } const myCustomDefaultTheme = extendTheme(); const { CssVarsProvider, useColorScheme } = createCssVarsProvider({ theme: myCustomDefaultTheme, modeStorageKey: 'system-demo-mode', attribute: 'data-system-demo-color-scheme', defaultColorScheme: { light: 'light', dark: 'dark', }, }); const Button = styled('button')<{ theme?: Theme }>(({ theme }) => ({ backgroundColor: theme.vars.palette.primary.default, border: `1px solid ${theme.vars.palette.primary.dark}`, color: theme.vars.palette.text.default, padding: 10, borderRadius: 5, fontWeight: 'bold', })); const WrapperDiv = styled('div')<{ theme?: Theme }>(({ theme }) => ({ width: '100%', minHeight: 100, padding: 20, color: theme.vars.palette.text.default, backgroundColor: theme.palette.mode === 'dark' ? '#111' : '#fff', })); function App() { // changes specific to this demo. const [shouldRender, setShouldRender] = React.useState(false); const { setMode, mode } = useColorScheme(); const toggleMode = () => { setMode(mode === 'dark' ? 'light' : 'dark'); }; // to avoid hydration error in demo. unrelated to the actual implementation React.useEffect(() => { setShouldRender(true); }, []); if (!shouldRender) { return null; } return ( <WrapperDiv className="App"> <div className="card"> <h2>Current mode: {mode}</h2> <Button type="button" onClick={toggleMode}> Toggle Mode </Button> </div> </WrapperDiv> ); } export default function CreateCssVarsProvider() { return ( <CssVarsProvider> <App /> </CssVarsProvider> ); }
3,820
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/css-theme-variables/CreateCssVarsProvider.tsx.preview
<CssVarsProvider> <App /> </CssVarsProvider>
3,821
0
petrpan-code/mui/material-ui/docs/data/system/experimental-api
petrpan-code/mui/material-ui/docs/data/system/experimental-api/css-theme-variables/css-theme-variables.md
# CSS theme variables <p class="description">An overview of adopting CSS theme variables in Material UI or Joy UI.</p> [CSS variables](https://www.w3.org/TR/css-variables-1/) are a modern cross-browser feature that let you declare variables in CSS and reuse them in other properties. :::info If this is your first time encountering CSS variables, you should check out [the MDN Web Docs on CSS custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) before continuing here. ::: ## Introduction CSS theme variable support is a new feature in MUI System added in [`v5.0.5`](https://github.com/mui/material-ui/releases/tag/v5.0.5) as an experimental export. It tells the underlying Material UI, Joy UI or even custom UI library components to use the generated CSS theme variables instead of raw values. This provides significant improvements in developer experience related to theming and customization. With these variables, you can inject a theme into your app's stylesheet _at build time_ to apply the user's selected settings before the whole app is rendered. You can checkout the [advantages](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/#advantages) and [trade-offs](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/#trade-offs) of using CSS theme variables before using them. ### Advantages - It lets you prevent [dark-mode SSR flickering](https://github.com/mui/material-ui/issues/27651). - You can create unlimited color schemes beyond `light` and `dark`. - It offers a better debugging experience not only for developers but also designers on your team. - The color scheme of your website is automatically synced between browser tabs. - It simplifies integration with third-party tools because CSS theme variables are available globally. - It reduces the need for a nested theme when you want to apply dark styles to a specific part of your application. ## Trade-offs For server-side applications, there are some trade-offs to consider: | | Compare to the default method | Reason | | :----------------------------------------------------------- | :---------------------------- | :------------------------------------------------------------------------------------------------------------- | | HTML size | Bigger | CSS variables are generated for both light and dark mode at build time. | | [First Contentful Paint (FCP)](https://web.dev/articles/fcp) | Longer | Since the HTML size is bigger, the time to download the HTML before showing the content is bit longer. | | [Time to Interactive (TTI)](https://web.dev/articles/tti) | Shorter (for dark mode) | Stylesheets are not regenerated between light and dark mode, a lot less time is spent running JavaScript code. | :::warning The comparison described in the table above may not be applicable to large and complex applications since there are so many factors that can impact performance metrics. ::: ## Usage The CSS variables API usage is exposed as a higher order function called `unstable_createCssVarsProvider` which can be called to create a theme provider and other utilities to share the theme config throughout your app. This is a very low-level function and has a lot of moving parts. If you are already using [Material UI](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/) or [Joy UI](https://mui.com/joy-ui/customization/using-css-variables/), they already expose their own `CssVarsProvider` component that you can use directly without needing to configure your theme. Now that's out of the way, we can continue with how this util can be used. We'll first define a minimal theme palette for light and dark modes. ```js // extendTheme.js import { unstable_createGetCssVar as systemCreateGetCssVar, unstable_prepareCssVars as prepareCssVars, } from '@mui/system'; const lightColorScheme = { palette: { mode: 'light', primary: { default: '#3990FF', dark: '#02367D', }, text: { default: '#111111', }, // ... other colors }, }; const darkColorScheme = { palette: { mode: 'dark', primary: { default: '#265D97', dark: '#132F4C', main: '#5090D3', }, text: { default: '#ffffff', }, // ... other colors }, }; const createGetCssVar = (cssVarPrefix = 'my-app') => systemCreateGetCssVar(cssVarPrefix); function extendTheme({ cssVarPrefix = 'my-app' } = {}) { const getCssVar = createGetCssVar(cssVarPrefix); const theme = { colorSchemes: { light: lightColorScheme, dark: darkColorScheme, }, // ... any other objects independent of color-scheme, // like fontSizes, spacing tokens, etc }; const { vars: themeVars, generateCssVars } = prepareCssVars( { colorSchemes: theme.colorSchemes }, { prefix: cssVarPrefix, }, ); theme.vars = themeVars; theme.generateCssVars = generateCssVars; theme.palette = { ...theme.colorSchemes.light.palette, colorScheme: 'light', }; return theme; } const myCustomDefaultTheme = extendTheme(); export default myCustomDefaultTheme; ``` Here, the returned `theme` object needs to follow a certain structure to be used correctly by the final `CssVarsProvider`. It should have a `colorSchemes` key with the light and dark (and any other) palette. `prepareCssVars` import from `@mui/system` is used to create CSS variable names which can then be easily accessed using the returned `vars`. This is also added to the `theme` object. Finally, `myCustomDefaultTheme` theme object is created that can now be passed to the `createCssVarsProvider` to get a `CssVarsProvider`. ```js // CssVarsProvider.js import { unstable_createCssVarsProvider as createCssVarsProvider } from '@mui/system'; const { CssVarsProvider, useColorScheme } = createCssVarsProvider({ defaultColorScheme: { light: 'light', dark: 'dark', }, theme: myCustomDefaultTheme, }); export { CssVarsProvider, useColorScheme }; ``` Now wrap your top level app component with this `CssVarsProvider` component and then you can access the passed theme value to any of the components rendered inside the provider. Example of a component using the CSS variable - ```js // Button.js import { styled } from '@mui/system'; const Button = styled('button')(({ theme }) => ({ backgroundColor: theme.vars.palette.primary.default, border: `1px solid ${theme.vars.palette.primary.dark}`, color: theme.vars.palette.text.default, })); export default Button; ``` The hook, `useColorScheme` can be used to get the current `mode` (light or dark) and can also update the mode like: ```js // App.js function App() { const { setMode, mode } = useColorScheme(); const toggleMode = () => { setMode(mode === 'dark' ? 'light' : 'dark'); }; return ( <div> <h1>Current Mode: {mode}</h1> <Button onClick={toggleMode}>Toggle Mode</Button> </div> ); } // main.js import * as React from 'react'; import * as ReactDOM from 'react-dom/client'; import App from './App'; import { CssVarsProvider } from './CssVarsProvider'; ReactDOM.createRoot(document.getElementById('root')).render( <CssVarsProvider> <App /> </CssVarsProvider>, ); ``` Now, the Button's `backgroundColor`, `borderColor` and text `color` values will correctly use the colors based on the selected `mode`. ### Demo {{"demo": "CreateCssVarsProvider.js"}} For framework or language specific setup, see [this](https://mui.com/material-ui/experimental-api/css-theme-variables/usage/#server-side-rendering) See the complete usage of `createVssVarsProvider` in [Material UI](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/CssVarsProvider.tsx) and [Joy UI](https://github.com/mui/material-ui/blob/master/packages/mui-joy/src/styles/CssVarsProvider.tsx). ## API ### `createCssVarsProvider` options - `attribute?`: DOM attribute for applying color scheme (`data-color-scheme` by default) - `modeStorageKey?`: localStorage key used to store application `mode` (`mode` by default) - `colorSchemeStorageKey?`: localStorage key used to store `colorScheme` - `defaultColorScheme`: Design system default color scheme (string or object depending on if the design system has 1 or more themes, can be `light` or `dark`) - `defaultMode?`: Design system default mode (`light` by default) - `disableTransitionOnChange?`: Disable CSS transitions when switching between modes or color schemes (`false` by default) - `themeId?`: The design system's unique id for getting the corresponded theme when there are multiple design systems. - `theme`: Design system default theme. It's structure, besides the minimum requirements by `createCssVarsProvider`, is upto the design system to implement. - `resolveTheme(theme: Theme) => Theme`: A function to be called after the CSS variables are attached. The result of this function will be the final theme pass to `ThemeProvider`. `createCssVarsProvider` returns 3 items. ### `<CssVarsProvider>` props - `defaultMode?: 'light' | 'dark' | 'system'` - Application's default mode (`light` by default) - `disableTransitionOnChange : boolean` - Disable CSS transitions when switching between modes - `theme: ThemeInput` - the theme provided to React's context - `modeStorageKey?: string` - localStorage key used to store application `mode` - `attribute?: string` - DOM attribute for applying color scheme ### `useColorScheme: () => ColorSchemeContextValue` - `mode: string` - The user's selected mode - `setMode: mode => {…}` - Function for setting the `mode`. The `mode` is saved to internal state and local storage; if `mode` is null, it will be reset to the default mode ### `getInitColorSchemeScript: (options) => React.ReactElement` **options** - `defaultMode?: 'light' | 'dark' | 'system'`: - Application's default mode before React renders the tree (`light` by default) - `modeStorageKey?: string`: - localStorage key used to store application `mode` - `attribute?: string` - DOM attribute for applying color scheme
3,822
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignContent.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function AlignContent() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'flex-end', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'center', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'space-between', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'space-around', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'stretch', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> </div> ); }
3,823
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignContent.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function AlignContent() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'flex-end', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'center', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'space-between', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'space-around', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', alignContent: 'stretch', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 380, height: 200, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> <Item>Item 7</Item> </Box> </div> ); }
3,824
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignItems.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function AlignItems() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'flex-end', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'center', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'stretch', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'baseline', p: 1, m: 1, bgcolor: 'background.paper', height: 116, borderRadius: 1, }} > <Item sx={{ height: 64, }} > Item 1 </Item> <Item sx={{ height: 84, }} > Item 2 </Item> <Item>Item 3</Item> </Box> </div> ); }
3,825
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignItems.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function AlignItems() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'flex-end', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'center', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'stretch', p: 1, m: 1, bgcolor: 'background.paper', height: 100, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'baseline', p: 1, m: 1, bgcolor: 'background.paper', height: 116, borderRadius: 1, }} > <Item sx={{ height: 64, }} > Item 1 </Item> <Item sx={{ height: 84, }} > Item 2 </Item> <Item>Item 3</Item> </Box> </div> ); }
3,826
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignSelf.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function AlignSelf() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', height: 124, borderRadius: 1, }} > <Item>Item 1</Item> <Item sx={{ alignSelf: 'flex-end' }}>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,827
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignSelf.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function AlignSelf() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', height: 124, borderRadius: 1, }} > <Item>Item 1</Item> <Item sx={{ alignSelf: 'flex-end' }}>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,828
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/AlignSelf.tsx.preview
<Box sx={{ display: 'flex', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', height: 124, borderRadius: 1, }} > <Item>Item 1</Item> <Item sx={{ alignSelf: 'flex-end' }}>Item 2</Item> <Item>Item 3</Item> </Box>
3,829
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/Display.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Display() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', m: 1, p: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > {"I'm a flexbox container that uses flex!"} </Box> <Box sx={{ display: 'inline-flex', m: 1, p: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > {"I'm a flexbox container that uses inline-flex!"} </Box> </div> ); }
3,830
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/Display.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Display() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', m: 1, p: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > {"I'm a flexbox container that uses flex!"} </Box> <Box sx={{ display: 'inline-flex', m: 1, p: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > {"I'm a flexbox container that uses inline-flex!"} </Box> </div> ); }
3,831
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexDirection.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function FlexDirection() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', flexDirection: 'row', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', flexDirection: 'row-reverse', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'flex-start', flexDirection: 'column', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', flexDirection: 'column-reverse', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,832
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexDirection.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function FlexDirection() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', flexDirection: 'row', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', flexDirection: 'row-reverse', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', alignItems: 'flex-start', flexDirection: 'column', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', flexDirection: 'column-reverse', alignItems: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,833
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexGrow.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function FlexGrow() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ flexGrow: 1 }}>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,834
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexGrow.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function FlexGrow() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ flexGrow: 1 }}>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,835
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexGrow.tsx.preview
<Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ flexGrow: 1 }}>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box>
3,836
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexShrink.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function FlexShrink() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ width: '100%' }}>Item 1</Item> <Item sx={{ flexShrink: 1 }}>Item 2</Item> <Item sx={{ flexShrink: 0 }}>Item 3</Item> </Box> </div> ); }
3,837
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexShrink.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function FlexShrink() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ width: '100%' }}>Item 1</Item> <Item sx={{ flexShrink: 1 }}>Item 2</Item> <Item sx={{ flexShrink: 0 }}>Item 3</Item> </Box> </div> ); }
3,838
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexShrink.tsx.preview
<Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ width: '100%' }}>Item 1</Item> <Item sx={{ flexShrink: 1 }}>Item 2</Item> <Item sx={{ flexShrink: 0 }}>Item 3</Item> </Box>
3,839
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexWrap.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function FlexWrap() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', flexWrap: 'nowrap', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 300, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 300, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap-reverse', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 300, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> </Box> </div> ); }
3,840
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/FlexWrap.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function FlexWrap() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', flexWrap: 'nowrap', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 300, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 300, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> </Box> <Box sx={{ display: 'flex', flexWrap: 'wrap-reverse', p: 1, m: 1, bgcolor: 'background.paper', maxWidth: 300, borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> <Item>Item 4</Item> <Item>Item 5</Item> <Item>Item 6</Item> </Box> </div> ); }
3,841
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/JustifyContent.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function JustifyContent() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', justifyContent: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'flex-end', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'center', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'space-between', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'space-around', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'space-evenly', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,842
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/JustifyContent.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function JustifyContent() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', justifyContent: 'flex-start', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'flex-end', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'center', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'space-between', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'space-around', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> <Box sx={{ display: 'flex', justifyContent: 'space-evenly', p: 1, m: 1, bgcolor: 'background.paper', borderRadius: 1, }} > <Item>Item 1</Item> <Item>Item 2</Item> <Item>Item 3</Item> </Box> </div> ); }
3,843
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/Order.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function Order() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ order: 2 }}>Item 1</Item> <Item sx={{ order: 3 }}>Item 2</Item> <Item sx={{ order: 1 }}>Item 3</Item> </Box> </div> ); }
3,844
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/Order.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ p: 1, m: 1, bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function Order() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ order: 2 }}>Item 1</Item> <Item sx={{ order: 3 }}>Item 2</Item> <Item sx={{ order: 1 }}>Item 3</Item> </Box> </div> ); }
3,845
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/Order.tsx.preview
<Box sx={{ display: 'flex', p: 1, bgcolor: 'background.paper', borderRadius: 1 }} > <Item sx={{ order: 2 }}>Item 1</Item> <Item sx={{ order: 3 }}>Item 2</Item> <Item sx={{ order: 1 }}>Item 3</Item> </Box>
3,846
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/flexbox/flexbox.md
# Flexbox <p class="description">Quickly manage the layout, alignment, and sizing of grid columns, navigation, components, and more with a full suite of responsive flexbox utilities.</p> If you are **new to or unfamiliar with flexbox**, we encourage you to read this [CSS-Tricks flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) guide. ## Properties for the Parent ### display {{"demo": "Display.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ display: 'flex' }}>… <Box sx={{ display: 'inline-flex' }}>… ``` ### flex-direction For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction" target="_blank" rel="noopener noreferrer">flex-direction</a> on MDN. {{"demo": "FlexDirection.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ flexDirection: 'row' }}>… <Box sx={{ flexDirection: 'row-reverse' }}>… <Box sx={{ flexDirection: 'column' }}>… <Box sx={{ flexDirection: 'column-reverse' }}>… ``` ### flex-wrap For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap" target="_blank" rel="noopener noreferrer">flex-wrap</a> on MDN. {{"demo": "FlexWrap.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ flexWrap: 'nowrap' }}>… <Box sx={{ flexWrap: 'wrap' }}>… <Box sx={{ flexWrap: 'wrap-reverse' }}>… ``` ### justify-content For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content" target="_blank" rel="noopener noreferrer">justify-content</a> on MDN. {{"demo": "JustifyContent.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ justifyContent: 'flex-start' }}>… <Box sx={{ justifyContent: 'flex-end' }}>… <Box sx={{ justifyContent: 'center' }}>… <Box sx={{ justifyContent: 'space-between' }}>… <Box sx={{ justifyContent: 'space-around' }}>… <Box sx={{ justifyContent: 'space-evenly' }}>… ``` ### align-items For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items" target="_blank" rel="noopener noreferrer">align-items</a> on MDN. {{"demo": "AlignItems.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ alignItems: 'flex-start' }}>… <Box sx={{ alignItems: 'flex-end' }}>… <Box sx={{ alignItems: 'center' }}>… <Box sx={{ alignItems: 'stretch' }}>… <Box sx={{ alignItems: 'baseline' }}>… ``` ### align-content For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-content" target="_blank" rel="noopener noreferrer">align-content</a> on MDN. {{"demo": "AlignContent.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ alignContent: 'flex-start' }}>… <Box sx={{ alignContent: 'flex-end' }}>… <Box sx={{ alignContent: 'center' }}>… <Box sx={{ alignContent: 'space-between' }}>… <Box sx={{ alignContent: 'space-around' }}>… <Box sx={{ alignContent: 'stretch' }}>… ``` ## Properties for the Children ### order For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/order" target="_blank" rel="noopener noreferrer">order</a> on MDN. {{"demo": "Order.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ order: 2 }}>Item 1</Box> <Box sx={{ order: 3 }}>Item 2</Box> <Box sx={{ order: 1 }}>Item 3</Box> ``` ### flex-grow For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow" target="_blank" rel="noopener noreferrer">flex-grow</a> on MDN. {{"demo": "FlexGrow.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ flexGrow: 1 }}>Item 1</Box> <Box>Item 2</Box> <Box>Item 3</Box> ``` ### flex-shrink For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink" target="_blank" rel="noopener noreferrer">flex-shrink</a> on MDN. {{"demo": "FlexShrink.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box sx={{ width: '100%' }}>Item 1</Box> <Box sx={{ flexShrink: 1 }}>Item 2</Box> <Box sx={{ flexShrink: 0 }}>Item 3</Box> ``` ### align-self For more information please see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-self" target="_blank" rel="noopener noreferrer">align-self</a> on MDN. {{"demo": "AlignSelf.js", "defaultCodeOpen": false, "bg": true}} ```jsx <Box>Item 1</Box> <Box sx={{ alignSelf: 'flex-end' }}>Item 2</Box> <Box>Item 3</Box> ``` ## API ```js import { flexbox } from '@mui/system'; ``` | Import name | Prop | CSS property | Theme key | | :--------------- | :--------------- | :---------------- | :-------- | | `flexDirection` | `flexDirection` | `flex-direction` | none | | `flexWrap` | `flexWrap` | `flex-wrap` | none | | `justifyContent` | `justifyContent` | `justify-content` | none | | `alignItems` | `alignItems` | `align-items` | none | | `alignContent` | `alignContent` | `align-content` | none | | `order` | `order` | `order` | none | | `flex` | `flex` | `flex` | none | | `flexGrow` | `flexGrow` | `flex-grow` | none | | `flexShrink` | `flexShrink` | `flex-shrink` | none | | `alignSelf` | `alignSelf` | `align-self` | none |
3,847
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/CombiningStyleFunctionsDemo.js
import * as React from 'react'; import styled from 'styled-components'; import { palette, spacing } from '@mui/system'; const Div = styled.div` ${palette} ${spacing} `; export default function CombiningStyleFunctionsDemo() { return ( <Div color="white" bgcolor="palevioletred" p={1}> Styled components </Div> ); }
3,848
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/CombiningStyleFunctionsDemo.tsx
import * as React from 'react'; import styled from 'styled-components'; import { palette, PaletteProps, spacing, SpacingProps } from '@mui/system'; const Div = styled.div<PaletteProps & SpacingProps>` ${palette} ${spacing} `; export default function CombiningStyleFunctionsDemo() { return ( <Div color="white" bgcolor="palevioletred" p={1}> Styled components </Div> ); }
3,849
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/CombiningStyleFunctionsDemo.tsx.preview
<Div color="white" bgcolor="palevioletred" p={1}> Styled components </Div>
3,850
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/StyleFunctionSxDemo.js
import * as React from 'react'; import styled, { ThemeProvider } from 'styled-components'; import { unstable_styleFunctionSx } from '@mui/system'; import { createTheme } from '@mui/material/styles'; const theme = createTheme(); const Div = styled('div')(unstable_styleFunctionSx); export default function StyleFunctionSxDemo() { return ( <ThemeProvider theme={theme}> <Div sx={{ m: 1, p: 1, border: 1 }}>Custom component with the sx prop</Div> </ThemeProvider> ); }
3,851
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/StyleFunctionSxDemo.tsx
import * as React from 'react'; import styled, { ThemeProvider, StyleFunction } from 'styled-components'; import { unstable_styleFunctionSx, SxProps } from '@mui/system'; import { createTheme } from '@mui/material/styles'; interface DivProps { sx?: SxProps; } const theme = createTheme(); const Div = styled('div')<DivProps>( unstable_styleFunctionSx as StyleFunction<DivProps>, ); export default function StyleFunctionSxDemo() { return ( <ThemeProvider theme={theme}> <Div sx={{ m: 1, p: 1, border: 1 }}>Custom component with the sx prop</Div> </ThemeProvider> ); }
3,852
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/StyleFunctionSxDemo.tsx.preview
<ThemeProvider theme={theme}> <Div sx={{ m: 1, p: 1, border: 1 }}>Custom component with the sx prop</Div> </ThemeProvider>
3,853
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/custom-components/custom-components.md
# Custom components <p class="description">Learn how to use MUI System with custom components.</p> ## Using sx with custom components Normally you would use the [`Box`](/system/react-box/) component at the root of your component tree in order to work with [the `sx` prop](/system/getting-started/the-sx-prop/). If you want to use `sx` with fully custom (non-MUI) components, you can do so with the `unstable_styleFunctionSx` utility. This gives you all the same capabilities, and with a smaller bundle size. The following demo shows how to implement this utility: {{"demo": "StyleFunctionSxDemo.js"}} ## Using standalone system utilities If you only need specific style functions from the `sx` prop, you can import them individually rather than pulling in the entire package. This is useful if you need to optimize for the smallest bundle size possible. The demo below illustrates how this works: {{"demo": "CombiningStyleFunctionsDemo.js", "defaultCodeOpen": true}}
3,854
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/installation/installation.md
# Installation <p class="description">Install MUI System, a collection of CSS utilities for rapidly laying out custom designs.</p> ## Default installation Run one of the following commands to add MUI System to your project: <codeblock storageKey="package-manager"> ```bash npm npm install @mui/system @emotion/react @emotion/styled ``` ```bash yarn yarn add @mui/system @emotion/react @emotion/styled ``` ```bash pnpm pnpm add @mui/system @emotion/react @emotion/styled ``` </codeblock> ## With styled-components MUI System uses [Emotion](https://emotion.sh/) as its default styling engine. If you want to use [styled-components](https://styled-components.com/) instead, run one of the following commands: <codeblock storageKey="package-manager"> ```bash npm npm install @mui/system @mui/styled-engine-sc styled-components ``` ```bash yarn yarn add @mui/system @mui/styled-engine-sc styled-components ``` ```bash pnpm pnpm add @mui/system @mui/styled-engine-sc styled-components ``` </codeblock> :::error As of late 2021, [styled-components](https://github.com/styled-components/styled-components) is **not compatible** with server-rendered Material UI projects. This is because `babel-plugin-styled-components` isn't able to work with the `styled()` utility inside `@mui` packages. See [this GitHub issue](https://github.com/mui/material-ui/issues/29742) for more details. We **strongly recommend** using Emotion for SSR projects. ::: ## Peer dependencies <!-- #react-peer-version --> Please note that [react](https://www.npmjs.com/package/react) is a peer dependency too: ```json "peerDependencies": { "react": "^17.0.0 || ^18.0.0" }, ```
3,855
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/overview/overview.md
--- title: Overview --- # MUI System - Overview <p class="description">MUI System is a collection of CSS utilities for rapidly laying out custom designs with MUI component libraries.</p> ## Introduction MUI System is a set of CSS utilities to help you build custom designs more efficiently when working with MUI component libraries like [Material UI](/material-ui/), [Joy UI](/joy-ui/getting-started/), and [Base UI](/base-ui/). The System gives you a set of flexible, generic wrapper components like [`Box`](/system/react-box/) and [`Container`](/system/react-container/) that can be quickly customized using the `sx` prop. This prop lets you define styles directly within the components themselves, rather than creating bulky and redundant `const` definitions with styled-components. It also gives you direct access to your theme's custom design tokens to ensure consistency in one-off styles. Learn more on [the `sx` prop page](/system/getting-started/the-sx-prop/). ## Advantages of MUI System - **Write less code:** in situations where styled-components would be overkill, the `sx` prop can [replace dozens of lines of code](/system/getting-started/usage/#why-use-mui-system). - **Write the CSS you already know:** the `sx` prop features a superset of CSS, so it's intuitive to pick up and start working with right away if you're comfortable with CSS. - **Avoid context-switching:** with styled-components, you frequently have to jump between the usage and the definition to find what you need. With the System, it's all in one place. - **Forget unnecessary custom names:** if you've ever struggled to come up with a good name for a styled-component, then you'll appreciate skipping that step entirely when using MUI System. ## MUI System vs. Base UI [Base UI](/base-ui/) is a library of "unstyled" React components, while MUI System is a set of utilities for quickly applying styles to those components (as well as other MUI component libraries like Material UI and Joy UI). Base UI is a standalone component library, whereas MUI System is _supplemental_ in that it's designed to be paired with Base UI and other MUI components, as well as third-party components. See the [Custom components page](/system/getting-started/custom-components/) for details on how to use MUI System with non-MUI components.
3,856
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/the-sx-prop/Example.js
import * as React from 'react'; import { Box, ThemeProvider, createTheme } from '@mui/system'; const theme = createTheme({ palette: { background: { paper: '#fff', }, text: { primary: '#173A5E', secondary: '#46505A', }, action: { active: '#001E3C', }, success: { dark: '#009688', }, }, }); export default function Example() { return ( <ThemeProvider theme={theme}> <Box sx={{ bgcolor: 'background.paper', boxShadow: 1, borderRadius: 2, p: 2, minWidth: 300, }} > <Box sx={{ color: 'text.secondary' }}>Sessions</Box> <Box sx={{ color: 'text.primary', fontSize: 34, fontWeight: 'medium' }}> 98.3 K </Box> <Box sx={{ color: 'success.dark', display: 'inline', fontWeight: 'bold', mx: 0.5, fontSize: 14, }} > +18.77% </Box> <Box sx={{ color: 'text.secondary', display: 'inline', fontSize: 14 }}> vs. last week </Box> </Box> </ThemeProvider> ); }
3,857
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/the-sx-prop/Example.tsx
import * as React from 'react'; import { Box, ThemeProvider, createTheme } from '@mui/system'; const theme = createTheme({ palette: { background: { paper: '#fff', }, text: { primary: '#173A5E', secondary: '#46505A', }, action: { active: '#001E3C', }, success: { dark: '#009688', }, }, }); export default function Example() { return ( <ThemeProvider theme={theme}> <Box sx={{ bgcolor: 'background.paper', boxShadow: 1, borderRadius: 2, p: 2, minWidth: 300, }} > <Box sx={{ color: 'text.secondary' }}>Sessions</Box> <Box sx={{ color: 'text.primary', fontSize: 34, fontWeight: 'medium' }}> 98.3 K </Box> <Box sx={{ color: 'success.dark', display: 'inline', fontWeight: 'bold', mx: 0.5, fontSize: 14, }} > +18.77% </Box> <Box sx={{ color: 'text.secondary', display: 'inline', fontSize: 14 }}> vs. last week </Box> </Box> </ThemeProvider> ); }
3,858
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/the-sx-prop/PassingSxProp.js
import * as React from 'react'; import PropTypes from 'prop-types'; import ListItem from '@mui/material/ListItem'; import FormLabel from '@mui/material/FormLabel'; function ListHeader({ sx = [], children }) { return ( <ListItem sx={[ { width: 'auto', textDecoration: 'underline', }, // You cannot spread `sx` directly because `SxProps` (typeof sx) can be an array. ...(Array.isArray(sx) ? sx : [sx]), ]} > <FormLabel sx={{ color: 'inherit' }}>{children}</FormLabel> </ListItem> ); } ListHeader.propTypes = { children: PropTypes.node, sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function PassingSxProp() { return ( <ListHeader sx={(theme) => ({ color: 'info.main', ...theme.typography.overline, })} > Header </ListHeader> ); }
3,859
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/the-sx-prop/PassingSxProp.tsx
import * as React from 'react'; import ListItem from '@mui/material/ListItem'; import FormLabel from '@mui/material/FormLabel'; import { SxProps, Theme } from '@mui/material/styles'; interface ListHeaderProps { children: React.ReactNode; sx?: SxProps<Theme>; } function ListHeader({ sx = [], children }: ListHeaderProps) { return ( <ListItem sx={[ { width: 'auto', textDecoration: 'underline', }, // You cannot spread `sx` directly because `SxProps` (typeof sx) can be an array. ...(Array.isArray(sx) ? sx : [sx]), ]} > <FormLabel sx={{ color: 'inherit' }}>{children}</FormLabel> </ListItem> ); } export default function PassingSxProp() { return ( <ListHeader sx={(theme) => ({ color: 'info.main', ...theme.typography.overline, })} > Header </ListHeader> ); }
3,860
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/the-sx-prop/PassingSxProp.tsx.preview
<ListHeader sx={(theme) => ({ color: 'info.main', ...theme.typography.overline, })} > Header </ListHeader>
3,861
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/the-sx-prop/the-sx-prop.md
# The sx prop <p class="description">The sx prop is a shortcut for defining custom styles that has access to the theme.</p> The `sx` prop lets you work with a superset of CSS that packages all of the style functions exposed in `@mui/system`. You can specify any valid CSS using this prop, as well as many _theme-aware_ properties that are unique to MUI System. ## Basic example The following demo illustrates how to work with the `sx` prop. Note that not all of the values are valid CSS properties—that's because the `sx` keys are mapped to specific properties of the theme. The rest of this document explores this concept in more detail. {{"demo": "Example.js", "bg": true, "defaultCodeOpen": true}} ## Theme-aware properties ### Borders The `border` property can only receive a number as a value. It creates a solid black border using the number to define the width in pixels: ```jsx <Box sx={{ border: 1 }} /> // equivalent to border: '1px solid black' ``` The `borderColor` property can receive a string, which represents the path in `theme.palette`: ```jsx <Box sx={{ borderColor: 'primary.main' }} /> // equivalent to borderColor: theme => theme.palette.primary.main ``` The `borderRadius` property multiplies the value it receives by the `theme.shape.borderRadius` value (the default for this value is `4px`). ```jsx <Box sx={{ borderRadius: 2 }} /> // equivalent to borderRadius: theme => 2 * theme.shape.borderRadius ``` Read more on the [Borders page](/system/borders/). ### Display The `displayPrint` property allows you to specify a CSS `display` value that will only be applied when printing: ```jsx <Box sx={{ displayPrint: 'none' }} /> // equivalent to '@media print': { display: 'none' } ``` Read more on the [Display page](/system/display/). ### Grid The CSS Grid properties `gap`, `rowGap` and `columnGap` multiply the values they receive by the `theme.spacing` value (the default for the value is `8px`). ```jsx <Box sx={{ gap: 2 }} /> // equivalent to gap: theme => theme.spacing(2) ``` Read more on the [Grid page](/system/grid/). ### Palette The `color` and `backgroundColor` properties can receive a string, which represents the path in `theme.palette`: ```jsx <Box sx={{ color: 'primary.main' }} /> // equivalent to color: theme => theme.palette.primary.main ``` The `backgroundColor` property is also available through its alias `bgcolor`: ```jsx <Box sx={{ bgcolor: 'primary.main' }} /> // equivalent to backgroundColor: theme => theme.palette.primary.main ``` Read more on the [Palette page](/system/palette/). ### Positions The `zIndex` property maps its value to the `theme.zIndex` value: ```jsx <Box sx={{ zIndex: 'tooltip' }} /> // equivalent to zIndex: theme => theme.zIndex.tooltip ``` Read more on the [Positions page](/system/positions/). ### Shadows The `boxShadow` property maps its value to the `theme.shadows` value: ```jsx <Box sx={{ boxShadow: 1 }} /> // equivalent to boxShadow: theme => theme.shadows[1] ``` Read more on the [Shadows page](/system/shadows/). ### Sizing The sizing properties `width`, `height`, `minHeight`, `maxHeight`, `minWidth`, and `maxWidth` use the following custom transform function for the value: ```js function transform(value) { return value <= 1 && value !== 0 ? `${value * 100}%` : value; } ``` If the value is between (0, 1], it's converted to a percentage. Otherwise, it is directly set on the CSS property: ```jsx <Box sx={{ width: 1/2 }} /> // equivalent to width: '50%' <Box sx={{ width: 20 }} /> // equivalent to width: '20px' ``` Read more on the [Sizing page](/system/sizing/). ### Spacing The spacing properties `margin`, `padding`, and the corresponding longhand properties multiply the values they receive by the `theme.spacing` value (the default for the value is `8px`): ```jsx <Box sx={{ margin: 2 }} /> // equivalent to margin: theme => theme.spacing(2) ``` The following aliases are available for the spacing properties: | Prop | CSS property | | :--- | :------------------------------ | | `m` | `margin` | | `mt` | `margin-top` | | `mr` | `margin-right` | | `mb` | `margin-bottom` | | `ml` | `margin-left` | | `mx` | `margin-left`, `margin-right` | | `my` | `margin-top`, `margin-bottom` | | `p` | `padding` | | `pt` | `padding-top` | | `pr` | `padding-right` | | `pb` | `padding-bottom` | | `pl` | `padding-left` | | `px` | `padding-left`, `padding-right` | | `py` | `padding-top`, `padding-bottom` | Read more on the [Spacing page](/system/spacing/). ### Typography The `fontFamily`, `fontSize`, `fontStyle`, `fontWeight` properties map their value to the `theme.typography` value: ```jsx <Box sx={{ fontWeight: 'fontWeightLight' }} /> // equivalent to fontWeight: theme.typography.fontWeightLight ``` The same can be achieved by omitting the CSS property prefix `fontWeight`: ```jsx <Box sx={{ fontWeight: 'light' }} /> // equivalent to fontWeight: theme.typography.fontWeightLight ``` There is an additional `typography` prop available, which sets all values defined in the specific `theme.typography` variant: ```jsx <Box sx={{ typography: 'body1' }} /> // equivalent to { ...theme.typography.body1 } ``` Read more on the [Typography page](/system/typography/). ## Responsive values All properties associated with the `sx` prop also support responsive values for specific breakpoints. Read more on the [Usage page—Responsive values](/system/getting-started/usage/#responsive-values). ## Callback values Each property in the `sx` prop can receive a function callback as a value. This is useful when you want to use the `theme` for calculating a value: ```jsx <Box sx={{ height: (theme) => theme.spacing(10) }} /> ``` The `sx` prop can also receive a callback when you need to get theme values that are objects: ```jsx <Box sx={(theme) => ({ ...theme.typography.body, color: theme.palette.primary.main, })} /> ``` In TypeScript, to use custom theme properties with the `sx` prop callback, extend the `Theme` type from the `@mui/system` library using [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation): ```tsx import * as React from 'react'; import Box from '@mui/material/Box'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { orange } from '@mui/material/colors'; declare module '@mui/system' { interface Theme { status: { warning: string; }; } } const theme = createTheme({ status: { warning: orange[500], }, }); export default function App() { return ( <ThemeProvider theme={theme}> <Box sx={(theme) => ({ bgcolor: theme.status.warning, })} > Example </Box> </ThemeProvider> ); } ``` ## Array values Array types are useful when you want to partially override some styles in the former index: ```jsx <Box sx={[ { '&:hover': { color: 'red', backgroundColor: 'white', }, }, foo && { '&:hover': { backgroundColor: 'grey' }, }, bar && { '&:hover': { backgroundColor: 'yellow' }, }, ]} /> ``` When you hover on this element, `color: red; backgroundColor: white;` is applied. If `foo: true`, then `color: red; backgroundColor: grey;` is applied when hovering. If `bar: true`, then `color: red; backgroundColor: yellow;` is applied when hovering regardless of `foo` value, because the higher index of the array has higher specificity. :::info Each index can be an object or a callback. ::: ```jsx <Box sx={[ { mr: 2, color: 'red' }, (theme) => ({ '&:hover': { color: theme.palette.primary.main, }, }), ]} /> ``` ## Passing the sx prop If you want to receive the `sx` prop from a custom component and pass it down to an MUI component, we recommend this approach: {{"demo": "PassingSxProp.js", "bg": true, "defaultCodeOpen": true}} ## TypeScript usage A frequent source of confusion with the `sx` prop is TypeScript's [type widening](https://mariusschulz.com/blog/literal-type-widening-in-typescript), which causes this example not to work as expected: ```ts const style = { flexDirection: 'column', }; export default function App() { return <Button sx={style}>Example</Button>; } // Type '{ flexDirection: string; }' is not assignable to type 'SxProps<Theme> | undefined' // Type '{ flexDirection: string; }' is not assignable to type 'CSSSelectorObject<Theme>' // Property 'flexDirection' is incompatible with index signature // Type 'string' is not assignable to type 'SystemStyleObject<Theme>' ``` The problem is that the type of the `flexDirection` prop is inferred as `string`, which is too wide. To fix this, you can cast the object/function passed to the `sx` prop to `const`: ```ts const style = { flexDirection: 'column', } as const; export default function App() { return <Button sx={style}>Example</Button>; } ``` Alternatively, you can pass the style object directly to the `sx` prop: ```ts export default function App() { return <Button sx={{ flexDirection: 'column' }}>Example</Button>; } ``` ## Performance To learn more about the performance tradeoffs of the `sx` prop, check out [Usage–Performance tradeoffs](/system/getting-started/usage/#performance-tradeoffs).
3,862
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/BreakpointsAsArray.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function BreakpointsAsArray() { return ( <div> <Box sx={{ width: [100, 200, 300] }}>This box has a responsive width.</Box> </div> ); }
3,863
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/BreakpointsAsArray.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function BreakpointsAsArray() { return ( <div> <Box sx={{ width: [100, 200, 300] }}>This box has a responsive width.</Box> </div> ); }
3,864
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/BreakpointsAsArray.tsx.preview
<Box sx={{ width: [100, 200, 300] }}>This box has a responsive width.</Box>
3,865
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/BreakpointsAsObject.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function BreakpointsAsObject() { return ( <div> <Box sx={{ width: { xs: 100, // theme.breakpoints.up('xs') sm: 200, // theme.breakpoints.up('sm') md: 300, // theme.breakpoints.up('md') lg: 400, // theme.breakpoints.up('lg') xl: 500, // theme.breakpoints.up('xl') }, }} > This box has a responsive width. </Box> </div> ); }
3,866
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/BreakpointsAsObject.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function BreakpointsAsObject() { return ( <div> <Box sx={{ width: { xs: 100, // theme.breakpoints.up('xs') sm: 200, // theme.breakpoints.up('sm') md: 300, // theme.breakpoints.up('md') lg: 400, // theme.breakpoints.up('lg') xl: 500, // theme.breakpoints.up('xl') }, }} > This box has a responsive width. </Box> </div> ); }
3,867
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/BreakpointsAsObject.tsx.preview
<Box sx={{ width: { xs: 100, // theme.breakpoints.up('xs') sm: 200, // theme.breakpoints.up('sm') md: 300, // theme.breakpoints.up('md') lg: 400, // theme.breakpoints.up('lg') xl: 500, // theme.breakpoints.up('xl') }, }} > This box has a responsive width. </Box>
3,868
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/Demo.js
import * as React from 'react'; import Box from '@mui/material/Box'; import { alpha } from '@mui/material/styles'; import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; export default function Demo() { return ( <Box sx={{ display: 'flex', flexDirection: { xs: 'column', md: 'row' }, alignItems: 'center', bgcolor: 'background.paper', overflow: 'hidden', borderRadius: '12px', boxShadow: 1, fontWeight: 'bold', }} > <Box component="img" sx={{ height: 233, width: 350, maxHeight: { xs: 233, md: 167 }, maxWidth: { xs: 350, md: 250 }, }} alt="The house from the offer." src="https://images.unsplash.com/photo-1512917774080-9991f1c4c750?auto=format&w=350&dpr=2" /> <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: { xs: 'center', md: 'flex-start' }, m: 3, minWidth: { md: 350 }, }} > <Box component="span" sx={{ fontSize: 16, mt: 1 }}> 123 Main St, Phoenix AZ </Box> <Box component="span" sx={{ color: 'primary.main', fontSize: 22 }}> $280,000 — $310,000 </Box> <Box sx={{ mt: 1.5, p: 0.5, backgroundColor: (theme) => alpha(theme.palette.primary.main, 0.1), borderRadius: '5px', color: 'primary.main', fontWeight: 'medium', display: 'flex', fontSize: 12, alignItems: 'center', '& svg': { fontSize: 21, mr: 0.5, }, }} > <ErrorOutlineIcon /> CONFIDENCE SCORE 85% </Box> </Box> </Box> ); }
3,869
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/Demo.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import { alpha } from '@mui/material/styles'; import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; export default function Demo() { return ( <Box sx={{ display: 'flex', flexDirection: { xs: 'column', md: 'row' }, alignItems: 'center', bgcolor: 'background.paper', overflow: 'hidden', borderRadius: '12px', boxShadow: 1, fontWeight: 'bold', }} > <Box component="img" sx={{ height: 233, width: 350, maxHeight: { xs: 233, md: 167 }, maxWidth: { xs: 350, md: 250 }, }} alt="The house from the offer." src="https://images.unsplash.com/photo-1512917774080-9991f1c4c750?auto=format&w=350&dpr=2" /> <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: { xs: 'center', md: 'flex-start' }, m: 3, minWidth: { md: 350 }, }} > <Box component="span" sx={{ fontSize: 16, mt: 1 }}> 123 Main St, Phoenix AZ </Box> <Box component="span" sx={{ color: 'primary.main', fontSize: 22 }}> $280,000 — $310,000 </Box> <Box sx={{ mt: 1.5, p: 0.5, backgroundColor: (theme) => alpha(theme.palette.primary.main, 0.1), borderRadius: '5px', color: 'primary.main', fontWeight: 'medium', display: 'flex', fontSize: 12, alignItems: 'center', '& svg': { fontSize: 21, mr: 0.5, }, }} > <ErrorOutlineIcon /> CONFIDENCE SCORE 85% </Box> </Box> </Box> ); }
3,870
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/SxProp.tsx.preview
<NoSsr> <ThemeProvider theme={theme}> <Box color="white" sx={{ bgcolor: 'palevioletred', p: 1, textTransform: 'uppercase' }}> CssProp </Box> </ThemeProvider> </NoSsr>
3,871
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/ValueAsFunction.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function ValueAsFunction() { return ( <div> <Box sx={{ p: 1, border: 1, borderColor: (theme) => theme.palette.primary.main, }} > Border color with theme value. </Box> </div> ); }
3,872
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/ValueAsFunction.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import { Theme } from '@mui/material/styles'; export default function ValueAsFunction() { return ( <div> <Box sx={{ p: 1, border: 1, borderColor: (theme: Theme) => theme.palette.primary.main, }} > Border color with theme value. </Box> </div> ); }
3,873
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/ValueAsFunction.tsx.preview
<Box sx={{ p: 1, border: 1, borderColor: (theme: Theme) => theme.palette.primary.main, }} > Border color with theme value. </Box>
3,874
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/Why.js
import * as React from 'react'; import TrendingUpIcon from '@mui/icons-material/TrendingUp'; import Box from '@mui/material/Box'; export default function Why() { return ( <Box sx={{ bgcolor: 'background.paper', boxShadow: 1, borderRadius: 1, p: 2, minWidth: 300, }} > <Box sx={{ color: 'text.secondary' }}>Sessions</Box> <Box sx={{ color: 'text.primary', fontSize: 34, fontWeight: 'medium' }}> 98.3 K </Box> <Box component={TrendingUpIcon} sx={{ color: 'success.dark', fontSize: 16, verticalAlign: 'sub' }} /> <Box sx={{ color: 'success.dark', display: 'inline', fontWeight: 'medium', mx: 0.5, }} > 18.77% </Box> <Box sx={{ color: 'text.secondary', display: 'inline', fontSize: 12 }}> vs. last week </Box> </Box> ); }
3,875
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/Why.tsx
import * as React from 'react'; import TrendingUpIcon from '@mui/icons-material/TrendingUp'; import Box from '@mui/material/Box'; export default function Why() { return ( <Box sx={{ bgcolor: 'background.paper', boxShadow: 1, borderRadius: 1, p: 2, minWidth: 300, }} > <Box sx={{ color: 'text.secondary' }}>Sessions</Box> <Box sx={{ color: 'text.primary', fontSize: 34, fontWeight: 'medium' }}> 98.3 K </Box> <Box component={TrendingUpIcon} sx={{ color: 'success.dark', fontSize: 16, verticalAlign: 'sub' }} /> <Box sx={{ color: 'success.dark', display: 'inline', fontWeight: 'medium', mx: 0.5, }} > 18.77% </Box> <Box sx={{ color: 'text.secondary', display: 'inline', fontSize: 12 }}> vs. last week </Box> </Box> ); }
3,876
0
petrpan-code/mui/material-ui/docs/data/system/getting-started
petrpan-code/mui/material-ui/docs/data/system/getting-started/usage/usage.md
# Usage <p class="description">Learn the basics of working with MUI System and its utilities.</p> ## Why use MUI System? MUI System's `sx` prop lets you avoid writing unnecessary styled-component code, and instead define styles directly within the component itself. This is especially useful for one-off components with custom designs. The following code samples illustrate the difference between styled-components and `sx`: {{"demo": "Why.js", "bg": true, "defaultCodeOpen": false}} 1. Using the styled-components API: ```jsx const StatWrapper = styled('div')( ({ theme }) => ` background-color: ${theme.palette.background.paper}; box-shadow: ${theme.shadows[1]}; border-radius: ${theme.shape.borderRadius}px; padding: ${theme.spacing(2)}; min-width: 300px; `, ); const StatHeader = styled('div')( ({ theme }) => ` color: ${theme.palette.text.secondary}; `, ); const StyledTrend = styled(TrendingUpIcon)( ({ theme }) => ` color: ${theme.palette.success.dark}; font-size: 16px; vertical-alignment: sub; `, ); const StatValue = styled('div')( ({ theme }) => ` color: ${theme.palette.text.primary}; font-size: 34px; font-weight: ${theme.typography.fontWeightMedium}; `, ); const StatDiff = styled('div')( ({ theme }) => ` color: ${theme.palette.success.dark}; display: inline; font-weight: ${theme.typography.fontWeightMedium}; margin-left: ${theme.spacing(0.5)}; margin-right: ${theme.spacing(0.5)}; `, ); const StatPrevious = styled('div')( ({ theme }) => ` color: ${theme.palette.text.secondary}; display: inline; font-size: 12px; `, ); return ( <StatWrapper> <StatHeader>Sessions</StatHeader> <StatValue>98.3 K</StatValue> <StyledTrend /> <StatDiff>18.77%</StatDiff> <StatPrevious>vs last week</StatPrevious> </StatWrapper> ); ``` 2. Using MUI System: ```jsx <Box sx={{ bgcolor: 'background.paper', boxShadow: 1, borderRadius: 1, p: 2, minWidth: 300, }} > <Box sx={{ color: 'text.secondary' }}>Sessions</Box> <Box sx={{ color: 'text.primary', fontSize: 34, fontWeight: 'medium' }}> 98.3 K </Box> <Box component={TrendingUpIcon} sx={{ color: 'success.dark', fontSize: 16, verticalAlign: 'sub' }} /> <Box sx={{ color: 'success.dark', display: 'inline', fontWeight: 'medium', mx: 0.5, }} > 18.77% </Box> <Box sx={{ color: 'text.secondary', display: 'inline', fontSize: 12 }}> vs. last week </Box> </Box> ``` ### The sx prop MUI System's core utility is the `sx` prop, which gives you a quick and efficient way to apply the correct design tokens directly to a React element. This prop provides a superset of CSS (i.e. it contains all CSS properties and selectors in addition to custom ones) that maps values directly from the theme, depending on the CSS property used. It also simplifies the process of defining responsive values by referring to the breakpoints defined in the theme. Visit [the `sx` prop page](/system/getting-started/the-sx-prop/) for complete details. ### Responsive demo The following demo shows how to use the `sx` prop to apply custom styles and create a complex UI component using the `Box` wrapper alone. Resize the window to see the responsive breakpoints: {{"demo": "Demo.js", "bg": true, "defaultCodeOpen": true}} ## When to use MUI System The `sx` prop is best suited for applying one-off styles to custom components. This is in contrast to the styled-components API, which is ideal for building components that need to support a wide variety of contexts. These components are used in many different parts of the application and support different combinations of props. ### Performance tradeoffs MUI System relies on CSS-in-JS. It works with both Emotion and styled-components. #### Pros - 📚 The `sx` prop uses a superset of CSS, so the syntax will be immediately familiar to you if you know CSS already. It also offers (optional) shorthand definitions that can save you time if you put in a little work to learn them upfront. These are documented in the **Style utilities** section of the primary navigation to the left. - 📦 The System auto-purges, so that only the CSS that's used on the page is sent to the client. The initial bundle size cost is fixed—it doesn't get any larger as you add more CSS properties. You pay the cost of [@emotion/react](https://bundlephobia.com/package/@emotion/react) and [@mui/system](https://bundlephobia.com/package/@mui/system). The total size is ~15 kB gzipped. But if you are already using an MUI Core component library like Material UI, then it comes with no extra overhead. #### Cons - Runtime performance takes a hit. | Benchmark case | Code snippet | Time normalized | | :-------------------------------- | :-------------------- | --------------: | | a. Render 1,000 primitives | `<div className="…">` | 100ms | | b. Render 1,000 components | `<Div>` | 112ms | | c. Render 1,000 styled components | `<StyledDiv>` | 181ms | | d. Render 1,000 Box | `<Box sx={…}>` | 296ms | <!-- #default-branch-switch --> _Head to the [benchmark folder](https://github.com/mui/material-ui/tree/master/benchmark/browser) for a reproduction of these metrics._ We believe that for most use cases it's fast enough, but there are simple workarounds when performance becomes critical. For instance, when rendering a list with many items, you can use a CSS child selector to have a single "style injection" point (using d. for the wrapper and a. for each item). ### API tradeoff MUI System's unifying `sx` prop helps to maintain the separation of concerns between CSS utilities and component business logic. For instance, a `color` prop on a button impacts multiple states (hover, focus, etc.), and is distinct from the CSS `color` property. Only the `Box`, `Stack`, `Typography`, and `Grid` components accept the system properties as props for this reason. These components are designed to solve CSS problems—they are CSS component utilities. ## Where to use MUI System The `sx` prop can be used in four different locations: ### Core components All core MUI components support the `sx` prop. ### Box [`Box`](/material-ui/react-box/) is a lightweight component that gives access to the `sx` prop, and can be used as a utility component, and as a wrapper for other components. It renders a `<div>` element by default. ### Custom components In addition to MUI components, you can add the `sx` prop to your custom components too, by using the `styled` utility from `@mui/material/styles`. ```jsx import { styled } from '@mui/material/styles'; const Div = styled('div')``; ``` ### Any element with the babel plugin TODO [#23220](https://github.com/mui/material-ui/issues/23220). ## How to use MUI System ### Design tokens in the theme Visit the [System properties page](/system/properties/) to learn how the different CSS (and custom) properties are mapped to the theme keys. ### Shorthands There are many shorthands available for various CSS properties. These are documented on their respective Style utilities pages. Here is an example of a few: ```jsx <Box sx={{ boxShadow: 1, // theme.shadows[1] color: 'primary.main', // theme.palette.primary.main m: 1, // margin: theme.spacing(1) p: { xs: 1, // [theme.breakpoints.up('xs')]: { padding: theme.spacing(1) } }, zIndex: 'tooltip', // theme.zIndex.tooltip }} > ``` These shorthands are optional—they're great for saving time, but not necessary to use ### Superset of CSS The `sx` prop supports CSS syntax including child and pseudo-selectors, media queries, raw CSS values, and more. Here are a few examples of how you can implement these CSS features: - Using pseudo-selectors: ```jsx <Box sx={{ // some styles ":hover": { boxShadow: 6, }, }} > ``` - Using media queries: ```jsx <Box sx={{ // some styles '@media print': { width: 300, }, }} > ``` - Using nested selector: ```jsx <Box sx={{ // some styles '& .ChildSelector': { bgcolor: 'primary.main', }, }} > ``` ### Responsive values The `sx` prop simplifies the process of defining and implementing responsive breakpoints. You can define a set of breakpoints in two different ways: as an object, or as an array. #### Breakpoints as an object The first option for breakpoints is to define them as an object, using the breakpoint values as keys. Note that each property for a given breakpoint also applies to all larger breakpoints in the set. For example, `width: { lg: 100 }` is equivalent to `theme.breakpoints.up('lg')`. The following demo shows how to define a set of breakpoints using the object syntax: {{"demo": "BreakpointsAsObject.js"}} #### Breakpoints as an array The second option is to define your breakpoints as an array, from smallest to largest. Here's what that looks like: {{"demo": "BreakpointsAsArray.js"}} :::success This option should only be considered when the theme has a limited number of breakpoints, e.g. 3. We recommend using the object API instead if you need to define more than a few breakpoints. ::: You can skip breakpoints with the `null` value: ```jsx <Box sx={{ width: [null, null, 300] }}>This box has a responsive width.</Box> ``` #### Custom breakpoints You can also specify your own custom breakpoints, and use them as keys when defining the breakpoints object. Here is an example of how to do that: ```jsx import * as React from 'react'; import Box from '@mui/material/Box'; import { createTheme, ThemeProvider } from '@mui/material/styles'; const theme = createTheme({ breakpoints: { values: { mobile: 0, tablet: 640, laptop: 1024, desktop: 1280, }, }, }); export default function CustomBreakpoints() { return ( <ThemeProvider theme={theme}> <Box sx={{ width: { mobile: 100, laptop: 300, }, }} > This box has a responsive width </Box> </ThemeProvider> ); } ``` If you are using TypeScript, you will also need to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) for the theme to accept the above values. ```ts declare module '@mui/material/styles' { interface BreakpointOverrides { xs: false; // removes the `xs` breakpoint sm: false; md: false; lg: false; xl: false; tablet: true; // adds the `tablet` breakpoint laptop: true; desktop: true; } } ``` #### Theme getter If you wish to use the theme for a CSS property that is not supported natively by the system, then you can use a function as the value, in which you can access the theme object. The following demo shows how this works: {{"demo": "ValueAsFunction.js"}}
3,877
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/Display.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Display() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > {"I'm a grid container!"} </Box> </div> ); }
3,878
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/Display.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function Display() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', bgcolor: (theme) => theme.palette.mode === 'dark' ? '#101010' : 'grey.100', color: (theme) => theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }} > {"I'm a grid container!"} </Box> </div> ); }
3,879
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/Gap.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function Gap() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gap: 1, gridTemplateColumns: 'repeat(2, 1fr)', }} > <Item>1</Item> <Item>2</Item> <Item>3</Item> <Item>4</Item> </Box> </div> ); }
3,880
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/Gap.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function Gap() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gap: 1, gridTemplateColumns: 'repeat(2, 1fr)', }} > <Item>1</Item> <Item>2</Item> <Item>3</Item> <Item>4</Item> </Box> </div> ); }
3,881
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/Gap.tsx.preview
<Box sx={{ display: 'grid', gap: 1, gridTemplateColumns: 'repeat(2, 1fr)', }} > <Item>1</Item> <Item>2</Item> <Item>3</Item> <Item>4</Item> </Box>
3,882
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoColumns.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function GridAutoColumns() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridAutoColumns: '1fr', gap: 1, }} > <Item sx={{ gridRow: '1', gridColumn: 'span 2' }}>span 2</Item> {/* The second non-visible column has width of 1/4 */} <Item sx={{ gridRow: '1', gridColumn: '4 / 5' }}>4 / 5</Item> </Box> </div> ); }
3,883
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoColumns.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function GridAutoColumns() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridAutoColumns: '1fr', gap: 1, }} > <Item sx={{ gridRow: '1', gridColumn: 'span 2' }}>span 2</Item> {/* The second non-visible column has width of 1/4 */} <Item sx={{ gridRow: '1', gridColumn: '4 / 5' }}>4 / 5</Item> </Box> </div> ); }
3,884
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoColumns.tsx.preview
<Box sx={{ display: 'grid', gridAutoColumns: '1fr', gap: 1, }} > <Item sx={{ gridRow: '1', gridColumn: 'span 2' }}>span 2</Item> {/* The second non-visible column has width of 1/4 */} <Item sx={{ gridRow: '1', gridColumn: '4 / 5' }}>4 / 5</Item> </Box>
3,885
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoFlow.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, textAlign: 'center', fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function GridAutoFlow() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridAutoFlow: 'row', gridTemplateColumns: 'repeat(5, 1fr)', gridTemplateRows: 'repeat(2, 50px)', gap: 1, }} > <Item sx={{ gridColumn: '1', gridRow: '1 / 3' }}>1</Item> <Item>2</Item> <Item>3</Item> <Item>4</Item> <Item sx={{ gridColumn: '5', gridRow: '1 / 3' }}>5</Item> </Box> </div> ); }
3,886
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoFlow.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, textAlign: 'center', fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function GridAutoFlow() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridAutoFlow: 'row', gridTemplateColumns: 'repeat(5, 1fr)', gridTemplateRows: 'repeat(2, 50px)', gap: 1, }} > <Item sx={{ gridColumn: '1', gridRow: '1 / 3' }}>1</Item> <Item>2</Item> <Item>3</Item> <Item>4</Item> <Item sx={{ gridColumn: '5', gridRow: '1 / 3' }}>5</Item> </Box> </div> ); }
3,887
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoFlow.tsx.preview
<Box sx={{ display: 'grid', gridAutoFlow: 'row', gridTemplateColumns: 'repeat(5, 1fr)', gridTemplateRows: 'repeat(2, 50px)', gap: 1, }} > <Item sx={{ gridColumn: '1', gridRow: '1 / 3' }}>1</Item> <Item>2</Item> <Item>3</Item> <Item>4</Item> <Item sx={{ gridColumn: '5', gridRow: '1 / 3' }}>5</Item> </Box>
3,888
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoRows.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, textAlign: 'center', fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function GridAutoRows() { return ( <div style={{ width: '100%', height: 220 }}> <Box sx={{ display: 'grid', gridAutoRows: '40px', gap: 1, }} > <Item sx={{ gridColumn: '1', gridRow: 'span 2' }}>span 2</Item> {/* The second non-visible row has height of 40px */} <Item sx={{ gridColumn: '1', gridRow: '4 / 5' }}>4 / 5</Item> </Box> </div> ); }
3,889
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoRows.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, borderRadius: 2, textAlign: 'center', fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function GridAutoRows() { return ( <div style={{ width: '100%', height: 220 }}> <Box sx={{ display: 'grid', gridAutoRows: '40px', gap: 1, }} > <Item sx={{ gridColumn: '1', gridRow: 'span 2' }}>span 2</Item> {/* The second non-visible row has height of 40px */} <Item sx={{ gridColumn: '1', gridRow: '4 / 5' }}>4 / 5</Item> </Box> </div> ); }
3,890
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridAutoRows.tsx.preview
<Box sx={{ display: 'grid', gridAutoRows: '40px', gap: 1, }} > <Item sx={{ gridColumn: '1', gridRow: 'span 2' }}>span 2</Item> {/* The second non-visible row has height of 40px */} <Item sx={{ gridColumn: '1', gridRow: '4 / 5' }}>4 / 5</Item> </Box>
3,891
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateAreas.js
import * as React from 'react'; import Box from '@mui/material/Box'; export default function GridTemplateAreas() { return ( <Box sx={{ width: '100%', height: '140px', color: '#fff', '& > .MuiBox-root > .MuiBox-root': { p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }, }} > <Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 1, gridTemplateRows: 'auto', gridTemplateAreas: `"header header header header" "main main . sidebar" "footer footer footer footer"`, }} > <Box sx={{ gridArea: 'header', bgcolor: 'primary.main' }}>Header</Box> <Box sx={{ gridArea: 'main', bgcolor: 'secondary.main' }}>Main</Box> <Box sx={{ gridArea: 'sidebar', bgcolor: 'error.main' }}>Sidebar</Box> <Box sx={{ gridArea: 'footer', bgcolor: 'warning.dark' }}>Footer</Box> </Box> </Box> ); }
3,892
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateAreas.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; export default function GridTemplateAreas() { return ( <Box sx={{ width: '100%', height: '140px', color: '#fff', '& > .MuiBox-root > .MuiBox-root': { p: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', }, }} > <Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 1, gridTemplateRows: 'auto', gridTemplateAreas: `"header header header header" "main main . sidebar" "footer footer footer footer"`, }} > <Box sx={{ gridArea: 'header', bgcolor: 'primary.main' }}>Header</Box> <Box sx={{ gridArea: 'main', bgcolor: 'secondary.main' }}>Main</Box> <Box sx={{ gridArea: 'sidebar', bgcolor: 'error.main' }}>Sidebar</Box> <Box sx={{ gridArea: 'footer', bgcolor: 'warning.dark' }}>Footer</Box> </Box> </Box> ); }
3,893
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateAreas.tsx.preview
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 1, gridTemplateRows: 'auto', gridTemplateAreas: `"header header header header" "main main . sidebar" "footer footer footer footer"`, }} > <Box sx={{ gridArea: 'header', bgcolor: 'primary.main' }}>Header</Box> <Box sx={{ gridArea: 'main', bgcolor: 'secondary.main' }}>Main</Box> <Box sx={{ gridArea: 'sidebar', bgcolor: 'error.main' }}>Sidebar</Box> <Box sx={{ gridArea: 'footer', bgcolor: 'warning.dark' }}>Footer</Box> </Box>
3,894
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateColumns.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, m: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function GridTemplateColumns() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Box> </div> ); }
3,895
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateColumns.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, m: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function GridTemplateColumns() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Box> </div> ); }
3,896
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateColumns.tsx.preview
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Box>
3,897
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateRows.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; function Item(props) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, m: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } Item.propTypes = { /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([ PropTypes.arrayOf( PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]), ), PropTypes.func, PropTypes.object, ]), }; export default function GridTemplateRows() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridTemplateRows: 'repeat(3, 1fr)' }}> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Box> </div> ); }
3,898
0
petrpan-code/mui/material-ui/docs/data/system
petrpan-code/mui/material-ui/docs/data/system/grid/GridTemplateRows.tsx
import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; function Item(props: BoxProps) { const { sx, ...other } = props; return ( <Box sx={{ bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'), color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'), border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300', p: 1, m: 1, borderRadius: 2, fontSize: '0.875rem', fontWeight: '700', ...sx, }} {...other} /> ); } export default function GridTemplateRows() { return ( <div style={{ width: '100%' }}> <Box sx={{ display: 'grid', gridTemplateRows: 'repeat(3, 1fr)' }}> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Box> </div> ); }
3,899