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/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/Hook.js | import * as React from 'react';
import { makeStyles } from '@mui/styles';
import Button from '@mui/material/Button';
const useStyles = makeStyles({
root: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
},
});
export default function Hook() {
const classes = useStyles();
return <Button className={classes.root}>Styled with Hook API</Button>;
}
| 3,700 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/Hook.tsx | import * as React from 'react';
import { makeStyles } from '@mui/styles';
import Button from '@mui/material/Button';
const useStyles = makeStyles({
root: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
},
});
export default function Hook() {
const classes = useStyles();
return <Button className={classes.root}>Styled with Hook API</Button>;
}
| 3,701 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/Hook.tsx.preview | <Button className={classes.root}>Styled with Hook API</Button> | 3,702 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/NestedStylesHook.js | import * as React from 'react';
import { makeStyles } from '@mui/styles';
const useStyles = makeStyles({
root: {
color: 'red',
'& p': {
margin: 0,
color: 'green',
'& span': {
color: 'blue',
},
},
},
});
export default function NestedStylesHook() {
const classes = useStyles();
return (
<div className={classes.root}>
This is red since it is inside the root.
<p>
This is green since it is inside the paragraph{' '}
<span>and this is blue since it is inside the span</span>
</p>
</div>
);
}
| 3,703 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/NestedStylesHook.tsx | import * as React from 'react';
import { makeStyles } from '@mui/styles';
const useStyles = makeStyles({
root: {
color: 'red',
'& p': {
margin: 0,
color: 'green',
'& span': {
color: 'blue',
},
},
},
});
export default function NestedStylesHook() {
const classes = useStyles();
return (
<div className={classes.root}>
This is red since it is inside the root.
<p>
This is green since it is inside the paragraph{' '}
<span>and this is blue since it is inside the span</span>
</p>
</div>
);
}
| 3,704 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/NestedStylesHook.tsx.preview |
This is red since it is inside the root.
<p>
This is green since it is inside the paragraph{' '}
<span>and this is blue since it is inside the span</span>
</p> | 3,705 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/StressTest.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { ThemeProvider, useTheme, makeStyles } from '@mui/styles';
const useStyles = makeStyles((theme) => ({
root: (props) => ({
backgroundColor: props.backgroundColor,
color: theme.color,
}),
}));
const Component = React.memo((props) => {
const classes = useStyles(props);
const theme = useTheme();
const rendered = React.useRef(1);
React.useEffect(() => {
rendered.current += 1;
});
return (
<div className={classes.root}>
rendered {rendered.current} times
<br />
color: {theme.color}
<br />
backgroundColor: {props.backgroundColor}
</div>
);
});
Component.propTypes = {
backgroundColor: PropTypes.string.isRequired,
};
export default function StressTest() {
const [backgroundColor, setBackgroundColor] = React.useState('#2196f3');
const handleBackgroundColorChange = (event) => {
setBackgroundColor(event.target.value);
};
const [color, setColor] = React.useState('#ffffff');
const handleColorChange = (event) => {
setColor(event.target.value);
};
const theme = React.useMemo(() => ({ color }), [color]);
return (
<ThemeProvider theme={theme}>
<div>
<fieldset>
<div>
<label htmlFor="color">theme color: </label>
<input
id="color"
type="color"
onChange={handleColorChange}
value={color}
/>
</div>
<div>
<label htmlFor="background-color">background-color property: </label>
<input
id="background-color"
type="color"
onChange={handleBackgroundColorChange}
value={backgroundColor}
/>
</div>
</fieldset>
<Component backgroundColor={backgroundColor} />
</div>
</ThemeProvider>
);
}
| 3,706 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/StressTest.tsx | import * as React from 'react';
import { ThemeProvider, useTheme, makeStyles } from '@mui/styles';
interface MyTheme {
color: string;
}
interface ComponentProps {
backgroundColor: string;
}
const useStyles = makeStyles((theme: MyTheme) => ({
root: (props: ComponentProps) => ({
backgroundColor: props.backgroundColor,
color: theme.color,
}),
}));
const Component = React.memo((props: ComponentProps) => {
const classes = useStyles(props);
const theme = useTheme<MyTheme>();
const rendered = React.useRef(1);
React.useEffect(() => {
rendered.current += 1;
});
return (
<div className={classes.root}>
rendered {rendered.current} times
<br />
color: {theme.color}
<br />
backgroundColor: {props.backgroundColor}
</div>
);
});
export default function StressTest() {
const [backgroundColor, setBackgroundColor] = React.useState('#2196f3');
const handleBackgroundColorChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
setBackgroundColor(event.target.value);
};
const [color, setColor] = React.useState('#ffffff');
const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setColor(event.target.value);
};
const theme = React.useMemo(() => ({ color }), [color]);
return (
<ThemeProvider theme={theme}>
<div>
<fieldset>
<div>
<label htmlFor="color">theme color: </label>
<input
id="color"
type="color"
onChange={handleColorChange}
value={color}
/>
</div>
<div>
<label htmlFor="background-color">background-color property: </label>
<input
id="background-color"
type="color"
onChange={handleBackgroundColorChange}
value={backgroundColor}
/>
</div>
</fieldset>
<Component backgroundColor={backgroundColor} />
</div>
</ThemeProvider>
);
}
| 3,707 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/StyledComponents.js | import * as React from 'react';
import { styled } from '@mui/styles';
import Button from '@mui/material/Button';
const MyButton = styled(Button)({
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
});
export default function StyledComponents() {
return <MyButton>Styled with styled-components API</MyButton>;
}
| 3,708 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/StyledComponents.tsx | import * as React from 'react';
import { styled } from '@mui/styles';
import Button from '@mui/material/Button';
const MyButton = styled(Button)({
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
});
export default function StyledComponents() {
return <MyButton>Styled with styled-components API</MyButton>;
}
| 3,709 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/StyledComponents.tsx.preview | <MyButton>Styled with styled-components API</MyButton> | 3,710 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/basics/basics.md | # @mui/styles (LEGACY)
<p class="description">The legacy styling solution for Material UI, now deprecated and not recommended for use.</p>
:::error
`@mui/styles` was deprecated with the release of MUI Core v5 in late 2021.
It depended on [JSS](https://cssinjs.org/) as a styling solution, which is no longer used in `@mui/material`.
`@mui/styles` is not compatible with [React.StrictMode](https://react.dev/reference/react/StrictMode) or React 18, and it will not be updated.
This documentation remains here for those working on legacy projects, but we **strongly discourage** you from using `@mui/styles` when creating a new app with Material UI—you _will_ face unresolvable dependency issues.
Please use [`@mui/system`](/system/getting-started/) instead.
:::
## Installation
To install and save in your `package.json` dependencies, run:
<!-- #default-branch-switch -->
```bash
npm install @mui/styles
```
## Getting started
There are 3 possible APIs you can use to generate and apply styles, however they all share the same underlying logic.
### Hook API
```jsx
import * as React from 'react';
import { makeStyles } from '@mui/styles';
import Button from '@mui/material/Button';
const useStyles = makeStyles({
root: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
},
});
export default function Hook() {
const classes = useStyles();
return <Button className={classes.root}>Hook</Button>;
}
```
{{"demo": "Hook.js"}}
### Styled components API
Note: this only applies to the calling syntax – style definitions still use a JSS object.
You can also [change this behavior](/system/styles/advanced/#string-templates), with some limitations.
```jsx
import * as React from 'react';
import { styled } from '@mui/styles';
import Button from '@mui/material/Button';
const MyButton = styled(Button)({
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
});
export default function StyledComponents() {
return <MyButton>Styled Components</MyButton>;
}
```
{{"demo": "StyledComponents.js"}}
### Higher-order component API
```jsx
import * as React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@mui/styles';
import Button from '@mui/material/Button';
const styles = {
root: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
},
};
function HigherOrderComponent(props) {
const { classes } = props;
return <Button className={classes.root}>Higher-order component</Button>;
}
HigherOrderComponent.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(HigherOrderComponent);
```
{{"demo": "HigherOrderComponent.js"}}
## Nesting selectors
You can nest selectors to target elements inside the current class or component.
The following example uses the Hook API, but it works the same way with the other APIs.
```js
const useStyles = makeStyles({
root: {
color: 'red',
'& p': {
color: 'green',
'& span': {
color: 'blue',
},
},
},
});
```
{{"demo": "NestedStylesHook.js", "defaultCodeOpen": false}}
## Adapting based on props
You can pass a function to `makeStyles` ("interpolation")
in order to adapt the generated value based on the component's props.
The function can be provided at the style rule level, or at the CSS property level:
```jsx
const useStyles = makeStyles({
// style rule
foo: (props) => ({
backgroundColor: props.backgroundColor,
}),
bar: {
// CSS property
color: (props) => props.color,
},
});
function MyComponent() {
// Simulated props for the purpose of the example
const props = {
backgroundColor: 'black',
color: 'white',
};
// Pass the props as the first argument of useStyles()
const classes = useStyles(props);
return <div className={`${classes.foo} ${classes.bar}`} />;
}
```
This button component has a `color` prop that changes its color:
### Adapting the hook API
{{"demo": "AdaptingHook.js"}}
### Adapting the styled components API
{{"demo": "AdaptingStyledComponents.js"}}
### Adapting the higher-order component API
{{"demo": "AdaptingHOC.js"}}
### Stress test
In the following stress test, you can update the _theme color_ and the _background-color property_ live:
```js
const useStyles = makeStyles((theme) => ({
root: (props) => ({
backgroundColor: props.backgroundColor,
color: theme.color,
}),
}));
```
{{"demo": "StressTest.js"}}
## Using the theme context
Starting from v5, Material UI no longer uses JSS as its default styling solution. If you still want to use the utilities exported by `@mui/styles` and they depend on the `theme`, you will need to provide the `theme` as part of the context. For this, you can use the `ThemeProvider` component available in `@mui/styles`, or, if you are already using `@mui/material`, you should use the one exported from `@mui/material/styles` so that the same `theme` is available for components from '@mui/material'.
```jsx
import { makeStyles } from '@mui/styles';
import { createTheme, ThemeProvider } from '@mui/material/styles';
const theme = createTheme();
const useStyles = makeStyles((theme) => ({
root: {
color: theme.palette.primary.main,
}
}));
const App = (props) => {
const classes = useStyles();
return <ThemeProvider theme={theme}><div {...props} className={classes.root}></ThemeProvider>;
}
```
| 3,711 |
0 | petrpan-code/mui/material-ui/docs/data/styles | petrpan-code/mui/material-ui/docs/data/styles/typescript/typescript.md | # TypeScript
## Customization of `Theme`
You can augment the default theme type to avoid having to set the theme type every time you use `makeStyles`, `useTheme`, or `styled`.
```ts
declare module '@mui/material/styles' {
interface DefaultTheme {
myProperty: string;
}
}
```
| 3,712 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/system/pages.ts | import type { MuiPage } from 'docs/src/MuiPage';
import pagesApi from 'docs/data/system/pagesApi';
const pages: readonly MuiPage[] = [
{
pathname: '/system/getting-started-group',
title: 'Getting started',
children: [
{ pathname: '/system/getting-started', title: 'Overview' },
{ pathname: '/system/getting-started/installation' },
{ pathname: '/system/getting-started/usage' },
{ pathname: '/system/getting-started/the-sx-prop' },
{ pathname: '/system/getting-started/custom-components' },
],
},
{
pathname: '/style-utilities',
children: [
{ pathname: '/system/properties' },
{ pathname: '/system/borders' },
{ pathname: '/system/display' },
{ pathname: '/system/flexbox' },
{ pathname: '/system/grid' },
{ pathname: '/system/palette' },
{ pathname: '/system/positions' },
{ pathname: '/system/shadows' },
{ pathname: '/system/sizing' },
{ pathname: '/system/spacing' },
{ pathname: '/system/screen-readers' },
{ pathname: '/system/typography' },
{ pathname: '/system/styled', title: 'styled' },
],
},
{
pathname: '/system/react-',
title: 'Components',
children: [
{ pathname: '/system/react-box', title: 'Box' },
{ pathname: '/system/react-container', title: 'Container' },
{ pathname: '/system/react-grid', title: 'Grid' },
{ pathname: '/system/react-stack', title: 'Stack' },
],
},
{
title: 'APIs',
pathname: '/system/api',
children: pagesApi,
},
{
pathname: '/system/experimental-api',
title: 'Experimental APIs',
children: [
{
pathname: '/system/experimental-api/configure-the-sx-prop',
title: 'Configure the sx prop',
},
{
pathname: '/system/experimental-api/css-theme-variables',
title: 'CSS Theme Variables',
},
],
},
{
pathname: '/system/styles',
title: 'Styles',
legacy: true,
children: [
{ pathname: '/system/styles/basics' },
{ pathname: '/system/styles/advanced' },
{ pathname: '/system/styles/api', title: 'APIs' },
],
},
];
export default pages;
| 3,713 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/system/pagesApi.js | module.exports = [
{ pathname: '/system/api/box' },
{ pathname: '/system/api/container' },
{ pathname: '/system/api/grid' },
{ pathname: '/system/api/stack' },
];
| 3,714 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderAdditive.js | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
m: 1,
borderColor: 'text.primary',
width: '5rem',
height: '5rem',
};
export default function BorderAdditive() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, border: 1 }} />
<Box sx={{ ...commonStyles, borderTop: 1 }} />
<Box sx={{ ...commonStyles, borderRight: 1 }} />
<Box sx={{ ...commonStyles, borderBottom: 1 }} />
<Box sx={{ ...commonStyles, borderLeft: 1 }} />
</Box>
);
}
| 3,715 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderAdditive.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
m: 1,
borderColor: 'text.primary',
width: '5rem',
height: '5rem',
};
export default function BorderAdditive() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, border: 1 }} />
<Box sx={{ ...commonStyles, borderTop: 1 }} />
<Box sx={{ ...commonStyles, borderRight: 1 }} />
<Box sx={{ ...commonStyles, borderBottom: 1 }} />
<Box sx={{ ...commonStyles, borderLeft: 1 }} />
</Box>
);
}
| 3,716 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderAdditive.tsx.preview | <Box sx={{ ...commonStyles, border: 1 }} />
<Box sx={{ ...commonStyles, borderTop: 1 }} />
<Box sx={{ ...commonStyles, borderRight: 1 }} />
<Box sx={{ ...commonStyles, borderBottom: 1 }} />
<Box sx={{ ...commonStyles, borderLeft: 1 }} /> | 3,717 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderColor.js | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
m: 1,
border: 1,
width: '5rem',
height: '5rem',
};
export default function BorderColor() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, borderColor: 'primary.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'secondary.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'error.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'grey.500' }} />
<Box sx={{ ...commonStyles, borderColor: 'text.primary' }} />
</Box>
);
}
| 3,718 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderColor.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
m: 1,
border: 1,
width: '5rem',
height: '5rem',
};
export default function BorderColor() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, borderColor: 'primary.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'secondary.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'error.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'grey.500' }} />
<Box sx={{ ...commonStyles, borderColor: 'text.primary' }} />
</Box>
);
}
| 3,719 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderColor.tsx.preview | <Box sx={{ ...commonStyles, borderColor: 'primary.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'secondary.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'error.main' }} />
<Box sx={{ ...commonStyles, borderColor: 'grey.500' }} />
<Box sx={{ ...commonStyles, borderColor: 'text.primary' }} /> | 3,720 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderRadius.js | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
borderColor: 'text.primary',
m: 1,
border: 1,
width: '5rem',
height: '5rem',
};
export default function BorderRadius() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, borderRadius: '50%' }} />
<Box sx={{ ...commonStyles, borderRadius: 1 }} />
<Box sx={{ ...commonStyles, borderRadius: '16px' }} />
</Box>
);
}
| 3,721 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderRadius.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
borderColor: 'text.primary',
m: 1,
border: 1,
width: '5rem',
height: '5rem',
};
export default function BorderRadius() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, borderRadius: '50%' }} />
<Box sx={{ ...commonStyles, borderRadius: 1 }} />
<Box sx={{ ...commonStyles, borderRadius: '16px' }} />
</Box>
);
}
| 3,722 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderRadius.tsx.preview | <Box sx={{ ...commonStyles, borderRadius: '50%' }} />
<Box sx={{ ...commonStyles, borderRadius: 1 }} />
<Box sx={{ ...commonStyles, borderRadius: '16px' }} /> | 3,723 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderSubtractive.js | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
border: 1,
m: 1,
borderColor: 'text.primary',
width: '5rem',
height: '5rem',
};
export default function BorderSubtractive() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, border: 0 }} />
<Box sx={{ ...commonStyles, borderTop: 0 }} />
<Box sx={{ ...commonStyles, borderRight: 0 }} />
<Box sx={{ ...commonStyles, borderBottom: 0 }} />
<Box sx={{ ...commonStyles, borderLeft: 0 }} />
</Box>
);
}
| 3,724 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderSubtractive.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
const commonStyles = {
bgcolor: 'background.paper',
border: 1,
m: 1,
borderColor: 'text.primary',
width: '5rem',
height: '5rem',
};
export default function BorderSubtractive() {
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ ...commonStyles, border: 0 }} />
<Box sx={{ ...commonStyles, borderTop: 0 }} />
<Box sx={{ ...commonStyles, borderRight: 0 }} />
<Box sx={{ ...commonStyles, borderBottom: 0 }} />
<Box sx={{ ...commonStyles, borderLeft: 0 }} />
</Box>
);
}
| 3,725 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/BorderSubtractive.tsx.preview | <Box sx={{ ...commonStyles, border: 0 }} />
<Box sx={{ ...commonStyles, borderTop: 0 }} />
<Box sx={{ ...commonStyles, borderRight: 0 }} />
<Box sx={{ ...commonStyles, borderBottom: 0 }} />
<Box sx={{ ...commonStyles, borderLeft: 0 }} /> | 3,726 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/borders/borders.md | # Borders
<p class="description">Use border utilities to quickly style the border and border-radius of an element. Great for images, buttons, or any other element.</p>
## Border
Use border utilities to add or remove an element's borders. Choose from all borders or one at a time.
### Additive
{{"demo": "BorderAdditive.js", "defaultCodeOpen": false, "bg": true}}
```jsx
<Box sx={{ border: 1 }}>…
<Box sx={{ borderTop: 1 }}>…
<Box sx={{ borderRight: 1 }}>…
<Box sx={{ borderBottom: 1 }}>…
<Box sx={{ borderLeft: 1 }}>…
```
### Subtractive
{{"demo": "BorderSubtractive.js", "defaultCodeOpen": false, "bg": true}}
```jsx
<Box sx={{ border: 0 }}>…
<Box sx={{ borderTop: 0 }}>…
<Box sx={{ borderRight: 0 }}>…
<Box sx={{ borderBottom: 0 }}>…
<Box sx={{ borderLeft: 0 }}>…
```
## Border color
{{"demo": "BorderColor.js", "defaultCodeOpen": false}}
```jsx
<Box sx={{ borderColor: 'primary.main' }}>…
<Box sx={{ borderColor: 'secondary.main' }}>…
<Box sx={{ borderColor: 'error.main' }}>…
<Box sx={{ borderColor: 'grey.500' }}>…
<Box sx={{ borderColor: 'text.primary' }}>…
```
## Border-radius
{{"demo": "BorderRadius.js", "defaultCodeOpen": false}}
```jsx
<Box sx={{ borderRadius: '50%' }}>…
<Box sx={{ borderRadius: 1 }}>… // theme.shape.borderRadius * 1
<Box sx={{ borderRadius: '16px' }}>…
```
## API
```js
import { borders } from '@mui/system';
```
| Import name | Prop | CSS property | Theme key |
| :------------------ | :------------------ | :-------------------- | :--------------------------------------------------------------------------- |
| `border` | `border` | `border` | `borders` |
| `borderTop` | `borderTop` | `border-top` | `borders` |
| `borderLeft` | `borderLeft` | `border-left` | `borders` |
| `borderRight` | `borderRight` | `border-right` | `borders` |
| `borderBottom` | `borderBottom` | `border-bottom` | `borders` |
| `borderColor` | `borderColor` | `border-color` | [`palette`](/material-ui/customization/default-theme/?expand-path=$.palette) |
| `borderTopColor` | `borderTopColor` | `border-top-color` | [`palette`](/material-ui/customization/default-theme/?expand-path=$.palette) |
| `borderRightColor` | `borderRightColor` | `border-right-color` | [`palette`](/material-ui/customization/default-theme/?expand-path=$.palette) |
| `borderBottomColor` | `borderBottomColor` | `border-bottom-color` | [`palette`](/material-ui/customization/default-theme/?expand-path=$.palette) |
| `borderLeftColor` | `borderLeftColor` | `border-left-color` | [`palette`](/material-ui/customization/default-theme/?expand-path=$.palette) |
| `borderRadius` | `borderRadius` | `border-radius` | [`shape`](/material-ui/customization/default-theme/?expand-path=$.shape) |
| 3,727 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxBasic.js | import * as React from 'react';
import Box from '@mui/system/Box';
export default function BoxBasic() {
return (
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
This is a section container
</Box>
);
}
| 3,728 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxBasic.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
export default function BoxBasic() {
return (
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
This is a section container
</Box>
);
}
| 3,729 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxBasic.tsx.preview |
This is a section container
| 3,730 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxComponent.js | import * as React from 'react';
import { Box } from '@mui/system';
import Button from '@mui/material/Button';
export default function BoxComponent() {
return (
<Box component="span" sx={{ p: 2, border: '1px dashed grey' }}>
<Button>Save</Button>
</Box>
);
}
| 3,731 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxComponent.tsx | import * as React from 'react';
import { Box } from '@mui/system';
import Button from '@mui/material/Button';
export default function BoxComponent() {
return (
<Box component="span" sx={{ p: 2, border: '1px dashed grey' }}>
<Button>Save</Button>
</Box>
);
}
| 3,732 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxComponent.tsx.preview | <Button>Save</Button> | 3,733 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxSx.js | import * as React from 'react';
import { Box, ThemeProvider } from '@mui/system';
export default function BoxSx() {
return (
<ThemeProvider
theme={{
palette: {
primary: {
main: '#007FFF',
dark: '#0066CC',
},
},
}}
>
<Box
sx={{
width: 100,
height: 100,
borderRadius: 1,
bgcolor: 'primary.main',
'&:hover': {
bgcolor: 'primary.dark',
},
}}
/>
</ThemeProvider>
);
}
| 3,734 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/BoxSx.tsx | import * as React from 'react';
import { Box, ThemeProvider } from '@mui/system';
export default function BoxSx() {
return (
<ThemeProvider
theme={{
palette: {
primary: {
main: '#007FFF',
dark: '#0066CC',
},
},
}}
>
<Box
sx={{
width: 100,
height: 100,
borderRadius: 1,
bgcolor: 'primary.main',
'&:hover': {
bgcolor: 'primary.dark',
},
}}
/>
</ThemeProvider>
);
}
| 3,735 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/box/box.md | ---
productId: system
title: React Box component
components: Box
githubLabel: 'component: Box'
---
# Box
<p class="description">The Box component is a generic, theme-aware container with access to CSS utilities from MUI System.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
## Introduction
The Box component is a generic container for grouping other components.
It's a fundamental building block when building with MUI component libraries—you can think of it as a `<div>` with special features (like access to your app's theme and the [`sx` prop](/system/getting-started/the-sx-prop/)).
## Basics
```jsx
import Box from '@mui/system/Box';
```
The Box component renders as a `<div>` by default, but you can swap in any other valid HTML tag or React component using the `component` prop.
The demo below replaces the `<div>` with a `<section>` element:
{{"demo": "BoxBasic.js", "defaultCodeOpen": true }}
:::info
The Box component differs from other containers available in Material UI and Joy UI because it's intended to be multipurpose—components like [Stack](/material-ui/react-stack/) and [Paper](/material-ui/react-paper/), by contrast, feature usage-specific props that make them ideal for certain use cases.
:::
## Component
### Using the sx prop
Use the [`sx` prop](/system/getting-started/the-sx-prop/) to quickly customize any Box instance using a superset of CSS with access to all the style functions and theme-aware properties exposed in the MUI System package.
{{"demo": "BoxSx.js", "defaultCodeOpen": true }}
### System props
As a CSS utility component, the Box supports all [MUI System properties](/system/properties/).
You can use them as prop directly on the component.
```jsx
<Box height={20} width={20} my={4} display="flex" alignItems="center" gap={4}>
```
## Create your own Box component
Use the `createBox()` utility to create your version of the Box component.
This is useful if you need to expose your container to a theme that's different from the default theme of the library you're working with:
```js
import { createBox, createTheme } from '@mui/system';
const defaultTheme = createTheme({
// your custom theme values
});
const Box = createBox({ defaultTheme });
export default Box;
```
| 3,736 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/FixedContainer.js | import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import { Box, Container } from '@mui/system';
export default function FixedContainer() {
return (
<React.Fragment>
<CssBaseline />
<Container fixed>
<Box sx={{ bgcolor: '#cfe8fc', height: '100vh' }} />
</Container>
</React.Fragment>
);
}
| 3,737 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/FixedContainer.tsx | import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import { Box, Container } from '@mui/system';
export default function FixedContainer() {
return (
<React.Fragment>
<CssBaseline />
<Container fixed>
<Box sx={{ bgcolor: '#cfe8fc', height: '100vh' }} />
</Container>
</React.Fragment>
);
}
| 3,738 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/FixedContainer.tsx.preview | <React.Fragment>
<CssBaseline />
<Container fixed>
<Box sx={{ bgcolor: '#cfe8fc', height: '100vh' }} />
</Container>
</React.Fragment> | 3,739 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/SimpleContainer.js | import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import { Box, Container } from '@mui/system';
export default function SimpleContainer() {
return (
<React.Fragment>
<CssBaseline />
<Container maxWidth="sm">
<Box sx={{ bgcolor: '#cfe8fc', height: '100vh' }} />
</Container>
</React.Fragment>
);
}
| 3,740 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/SimpleContainer.tsx | import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import { Box, Container } from '@mui/system';
export default function SimpleContainer() {
return (
<React.Fragment>
<CssBaseline />
<Container maxWidth="sm">
<Box sx={{ bgcolor: '#cfe8fc', height: '100vh' }} />
</Container>
</React.Fragment>
);
}
| 3,741 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/SimpleContainer.tsx.preview | <React.Fragment>
<CssBaseline />
<Container maxWidth="sm">
<Box sx={{ bgcolor: '#cfe8fc', height: '100vh' }} />
</Container>
</React.Fragment> | 3,742 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/container/container.md | ---
productId: system
title: React Container component
components: Container
githubLabel: 'component: Container'
---
# Container
<p class="description">The container centers your content horizontally. It's the most basic layout element.</p>
While containers can be nested, most layouts do not require a nested container.
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
## Fluid
A fluid container width is bounded by the `maxWidth` prop value.
{{"demo": "SimpleContainer.js", "iframe": true, "defaultCodeOpen": false}}
```jsx
<Container maxWidth="sm">
```
## Fixed
If you prefer to design for a fixed set of sizes instead of trying to accommodate a fully fluid viewport, you can set the `fixed` prop.
The max-width matches the min-width of the current breakpoint.
{{"demo": "FixedContainer.js", "iframe": true, "defaultCodeOpen": false}}
```jsx
<Container fixed>
```
| 3,743 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/AutoGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function AutoGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={3}>
<Grid xs>
<Item>xs</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,744 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/AutoGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function AutoGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={3}>
<Grid xs>
<Item>xs</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,745 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/AutoGrid.tsx.preview | <Grid container spacing={3}>
<Grid xs>
<Item>xs</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid> | 3,746 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/AutoGridNoWrap.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
const Item = styled('div')(({ theme }) => ({
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
borderRadius: 4,
}));
const message = `Truncation should be conditionally applicable on this long line of text
as this is a much longer line than what the container can support. `;
export default function AutoGridNoWrap() {
return (
<Box sx={{ flexGrow: 1, overflow: 'hidden', px: 3, maxWidth: 400 }}>
<Item
sx={{
my: 1,
mx: 'auto',
p: 2,
}}
>
<Grid container wrap="nowrap" spacing={2}>
<Grid>
<Avatar>W</Avatar>
</Grid>
<Grid xs>
<Typography noWrap>{message}</Typography>
</Grid>
</Grid>
</Item>
<Item
sx={{
my: 1,
mx: 'auto',
p: 2,
}}
>
<Grid container wrap="nowrap" spacing={2}>
<Grid>
<Avatar>W</Avatar>
</Grid>
<Grid xs>
<Typography
sx={{
display: '-webkit-box',
WebkitLineClamp: '3',
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
}}
>
{message}
</Typography>
</Grid>
</Grid>
</Item>
</Box>
);
}
| 3,747 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/AutoGridNoWrap.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
const Item = styled('div')(({ theme }) => ({
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
borderRadius: 4,
}));
const message = `Truncation should be conditionally applicable on this long line of text
as this is a much longer line than what the container can support. `;
export default function AutoGridNoWrap() {
return (
<Box sx={{ flexGrow: 1, overflow: 'hidden', px: 3, maxWidth: 400 }}>
<Item
sx={{
my: 1,
mx: 'auto',
p: 2,
}}
>
<Grid container wrap="nowrap" spacing={2}>
<Grid>
<Avatar>W</Avatar>
</Grid>
<Grid xs>
<Typography noWrap>{message}</Typography>
</Grid>
</Grid>
</Item>
<Item
sx={{
my: 1,
mx: 'auto',
p: 2,
}}
>
<Grid container wrap="nowrap" spacing={2}>
<Grid>
<Avatar>W</Avatar>
</Grid>
<Grid xs>
<Typography
sx={{
display: '-webkit-box',
WebkitLineClamp: '3',
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
}}
>
{message}
</Typography>
</Grid>
</Grid>
</Item>
</Box>
);
}
| 3,748 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/BasicGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function BasicGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,749 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/BasicGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function BasicGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,750 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/BasicGrid.tsx.preview | <Grid container spacing={2}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid> | 3,751 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/ColumnsGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function ColumnsGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2} columns={16}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,752 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/ColumnsGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function ColumnsGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2} columns={16}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,753 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/ColumnsGrid.tsx.preview | <Grid container spacing={2} columns={16}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid> | 3,754 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/CustomBreakpointsGrid.js | import * as React from 'react';
import { ThemeProvider, createTheme } from '@mui/system';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function CustomBreakpointsGrid() {
return (
<ThemeProvider
theme={createTheme({
breakpoints: {
values: {
laptop: 1024,
tablet: 640,
mobile: 0,
desktop: 1280,
},
},
})}
>
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={{ mobile: 1, tablet: 2, laptop: 3 }}>
{Array.from(Array(4)).map((_, index) => (
<Grid mobile={6} tablet={4} laptop={3} key={index}>
<Item>{index + 1}</Item>
</Grid>
))}
</Grid>
</Box>
</ThemeProvider>
);
}
| 3,755 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/FullWidthGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function FullWidthGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,756 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/FullWidthGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function FullWidthGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,757 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/FullWidthGrid.tsx.preview | <Grid container spacing={2}>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid> | 3,758 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/NestedGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
borderRadius: '4px',
}));
export default function NestedGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid xs={12} md={5} lg={4}>
<Item>Email subscribe section</Item>
</Grid>
<Grid container xs={12} md={7} lg={8} spacing={4}>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-a"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category A
</Box>
<Box component="ul" aria-labelledby="category-a" sx={{ pl: 2 }}>
<li>Link 1.1</li>
<li>Link 1.2</li>
<li>Link 1.3</li>
</Box>
</Item>
</Grid>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-b"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category B
</Box>
<Box component="ul" aria-labelledby="category-b" sx={{ pl: 2 }}>
<li>Link 2.1</li>
<li>Link 2.2</li>
<li>Link 2.3</li>
</Box>
</Item>
</Grid>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-c"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category C
</Box>
<Box component="ul" aria-labelledby="category-c" sx={{ pl: 2 }}>
<li>Link 3.1</li>
<li>Link 3.2</li>
<li>Link 3.3</li>
</Box>
</Item>
</Grid>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-d"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category D
</Box>
<Box component="ul" aria-labelledby="category-d" sx={{ pl: 2 }}>
<li>Link 4.1</li>
<li>Link 4.2</li>
<li>Link 4.3</li>
</Box>
</Item>
</Grid>
</Grid>
<Grid
xs={12}
container
justifyContent="space-between"
alignItems="center"
flexDirection={{ xs: 'column', sm: 'row' }}
sx={{ fontSize: '12px' }}
>
<Grid sx={{ order: { xs: 2, sm: 1 } }}>
<Item>© Copyright</Item>
</Grid>
<Grid container columnSpacing={1} sx={{ order: { xs: 1, sm: 2 } }}>
<Grid>
<Item>Link A</Item>
</Grid>
<Grid>
<Item>Link B</Item>
</Grid>
<Grid>
<Item>Link C</Item>
</Grid>
</Grid>
</Grid>
</Grid>
</Box>
);
}
| 3,759 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/NestedGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
borderRadius: '4px',
}));
export default function NestedGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid xs={12} md={5} lg={4}>
<Item>Email subscribe section</Item>
</Grid>
<Grid container xs={12} md={7} lg={8} spacing={4}>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-a"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category A
</Box>
<Box component="ul" aria-labelledby="category-a" sx={{ pl: 2 }}>
<li>Link 1.1</li>
<li>Link 1.2</li>
<li>Link 1.3</li>
</Box>
</Item>
</Grid>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-b"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category B
</Box>
<Box component="ul" aria-labelledby="category-b" sx={{ pl: 2 }}>
<li>Link 2.1</li>
<li>Link 2.2</li>
<li>Link 2.3</li>
</Box>
</Item>
</Grid>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-c"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category C
</Box>
<Box component="ul" aria-labelledby="category-c" sx={{ pl: 2 }}>
<li>Link 3.1</li>
<li>Link 3.2</li>
<li>Link 3.3</li>
</Box>
</Item>
</Grid>
<Grid xs={6} lg={3}>
<Item>
<Box
id="category-d"
sx={{ fontSize: '12px', textTransform: 'uppercase' }}
>
Category D
</Box>
<Box component="ul" aria-labelledby="category-d" sx={{ pl: 2 }}>
<li>Link 4.1</li>
<li>Link 4.2</li>
<li>Link 4.3</li>
</Box>
</Item>
</Grid>
</Grid>
<Grid
xs={12}
container
justifyContent="space-between"
alignItems="center"
flexDirection={{ xs: 'column', sm: 'row' }}
sx={{ fontSize: '12px' }}
>
<Grid sx={{ order: { xs: 2, sm: 1 } }}>
<Item>© Copyright</Item>
</Grid>
<Grid container columnSpacing={1} sx={{ order: { xs: 1, sm: 2 } }}>
<Grid>
<Item>Link A</Item>
</Grid>
<Grid>
<Item>Link B</Item>
</Grid>
<Grid>
<Item>Link C</Item>
</Grid>
</Grid>
</Grid>
</Grid>
</Box>
);
}
| 3,760 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/OffsetGrid.js | import * as React from 'react';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function OffsetGrid() {
return (
<Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs={6} xsOffset={3} md={2} mdOffset={0}>
<Item>1</Item>
</Grid>
<Grid xs={4} md={2} mdOffset="auto">
<Item>2</Item>
</Grid>
<Grid xs={4} xsOffset={4} md={2} mdOffset={0}>
<Item>3</Item>
</Grid>
<Grid xs md={6} mdOffset={2}>
<Item>4</Item>
</Grid>
</Grid>
);
}
| 3,761 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/OffsetGrid.tsx | import * as React from 'react';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function OffsetGrid() {
return (
<Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs={6} xsOffset={3} md={2} mdOffset={0}>
<Item>1</Item>
</Grid>
<Grid xs={4} md={2} mdOffset="auto">
<Item>2</Item>
</Grid>
<Grid xs={4} xsOffset={4} md={2} mdOffset={0}>
<Item>3</Item>
</Grid>
<Grid xs md={6} mdOffset={2}>
<Item>4</Item>
</Grid>
</Grid>
);
}
| 3,762 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/OffsetGrid.tsx.preview | <Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs={6} xsOffset={3} md={2} mdOffset={0}>
<Item>1</Item>
</Grid>
<Grid xs={4} md={2} mdOffset="auto">
<Item>2</Item>
</Grid>
<Grid xs={4} xsOffset={4} md={2} mdOffset={0}>
<Item>3</Item>
</Grid>
<Grid xs md={6} mdOffset={2}>
<Item>4</Item>
</Grid>
</Grid> | 3,763 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/OverflowGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function OverflowGrid() {
return (
<Box
sx={(theme) => ({
display: 'flex',
flexDirection: 'column',
gap: 3,
'& > div': {
overflow: 'auto hidden',
'&::-webkit-scrollbar': { height: 10, WebkitAppearance: 'none' },
'&::-webkit-scrollbar-thumb': {
borderRadius: 8,
border: '2px solid',
borderColor: theme.palette.mode === 'dark' ? '' : '#E7EBF0',
backgroundColor: 'rgba(0 0 0 / 0.5)',
},
},
})}
>
<Box
sx={{
width: 200,
}}
>
<Grid container spacing={3}>
<Grid xs={12}>
<Item>Scroll bar appears</Item>
</Grid>
</Grid>
</Box>
<Box sx={{ width: 200, overflow: 'scroll' }}>
<Grid container spacing={3} disableEqualOverflow>
<Grid xs={12}>
<Item>`disableEqualOverflow` prevents scrollbar</Item>
</Grid>
</Grid>
</Box>
</Box>
);
}
| 3,764 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/OverflowGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function OverflowGrid() {
return (
<Box
sx={(theme) => ({
display: 'flex',
flexDirection: 'column',
gap: 3,
'& > div': {
overflow: 'auto hidden',
'&::-webkit-scrollbar': { height: 10, WebkitAppearance: 'none' },
'&::-webkit-scrollbar-thumb': {
borderRadius: 8,
border: '2px solid',
borderColor: theme.palette.mode === 'dark' ? '' : '#E7EBF0',
backgroundColor: 'rgba(0 0 0 / 0.5)',
},
},
})}
>
<Box
sx={{
width: 200,
}}
>
<Grid container spacing={3}>
<Grid xs={12}>
<Item>Scroll bar appears</Item>
</Grid>
</Grid>
</Box>
<Box sx={{ width: 200, overflow: 'scroll' }}>
<Grid container spacing={3} disableEqualOverflow>
<Grid xs={12}>
<Item>`disableEqualOverflow` prevents scrollbar</Item>
</Grid>
</Grid>
</Box>
</Box>
);
}
| 3,765 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/ResponsiveGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function ResponsiveGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}>
{Array.from(Array(6)).map((_, index) => (
<Grid xs={2} sm={4} key={index}>
<Item>{index + 1}</Item>
</Grid>
))}
</Grid>
</Box>
);
}
| 3,766 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/ResponsiveGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function ResponsiveGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}>
{Array.from(Array(6)).map((_, index) => (
<Grid xs={2} sm={4} key={index}>
<Item>{index + 1}</Item>
</Grid>
))}
</Grid>
</Box>
);
}
| 3,767 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/ResponsiveGrid.tsx.preview | <Grid container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}>
{Array.from(Array(6)).map((_, index) => (
<Grid xs={2} sm={4} key={index}>
<Item>{index + 1}</Item>
</Grid>
))}
</Grid> | 3,768 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/RowAndColumnSpacing.js | import * as React from 'react';
import styled from '@mui/system/styled';
import Grid from '@mui/system/Unstable_Grid';
import Box from '@mui/system/Box';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function RowAndColumnSpacing() {
return (
<Box sx={{ width: '100%' }}>
<Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
<Grid xs={6}>
<Item>1</Item>
</Grid>
<Grid xs={6}>
<Item>2</Item>
</Grid>
<Grid xs={6}>
<Item>3</Item>
</Grid>
<Grid xs={6}>
<Item>4</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,769 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/RowAndColumnSpacing.tsx | import * as React from 'react';
import styled from '@mui/system/styled';
import Grid from '@mui/system/Unstable_Grid';
import Box from '@mui/system/Box';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function RowAndColumnSpacing() {
return (
<Box sx={{ width: '100%' }}>
<Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
<Grid xs={6}>
<Item>1</Item>
</Grid>
<Grid xs={6}>
<Item>2</Item>
</Grid>
<Grid xs={6}>
<Item>3</Item>
</Grid>
<Grid xs={6}>
<Item>4</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,770 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/RowAndColumnSpacing.tsx.preview | <Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
<Grid xs={6}>
<Item>1</Item>
</Grid>
<Grid xs={6}>
<Item>2</Item>
</Grid>
<Grid xs={6}>
<Item>3</Item>
</Grid>
<Grid xs={6}>
<Item>4</Item>
</Grid>
</Grid> | 3,771 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/SpacingGrid.js | import * as React from 'react';
import Grid from '@mui/system/Unstable_Grid';
import FormLabel from '@mui/material/FormLabel';
import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import Paper from '@mui/material/Paper';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
export default function SpacingGrid() {
const [spacing, setSpacing] = React.useState(2);
const handleChange = (event) => {
setSpacing(Number(event.target.value));
};
const jsx = `
<Grid container spacing={${spacing}}>
`;
return (
<Grid sx={{ flexGrow: 1 }} container spacing={2}>
<Grid xs={12}>
<Grid container justifyContent="center" spacing={spacing}>
{[0, 1, 2].map((value) => (
<Grid key={value}>
<Paper
sx={{
height: 140,
width: 100,
backgroundColor: (theme) =>
theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
}}
/>
</Grid>
))}
</Grid>
</Grid>
<Grid xs={12}>
<Paper sx={{ p: 2 }}>
<Grid container>
<Grid>
<FormControl component="fieldset">
<FormLabel component="legend">spacing</FormLabel>
<RadioGroup
name="spacing"
aria-label="spacing"
value={spacing.toString()}
onChange={handleChange}
row
>
{[0, 0.5, 1, 2, 3, 4, 8, 12].map((value) => (
<FormControlLabel
key={value}
value={value.toString()}
control={<Radio />}
label={value.toString()}
/>
))}
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Paper>
<HighlightedCode code={jsx} language="jsx" />
</Grid>
</Grid>
);
}
| 3,772 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/SpacingGrid.tsx | import * as React from 'react';
import Grid from '@mui/system/Unstable_Grid';
import FormLabel from '@mui/material/FormLabel';
import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import Paper from '@mui/material/Paper';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
export default function SpacingGrid() {
const [spacing, setSpacing] = React.useState(2);
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSpacing(Number((event.target as HTMLInputElement).value));
};
const jsx = `
<Grid container spacing={${spacing}}>
`;
return (
<Grid sx={{ flexGrow: 1 }} container spacing={2}>
<Grid xs={12}>
<Grid container justifyContent="center" spacing={spacing}>
{[0, 1, 2].map((value) => (
<Grid key={value}>
<Paper
sx={{
height: 140,
width: 100,
backgroundColor: (theme) =>
theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
}}
/>
</Grid>
))}
</Grid>
</Grid>
<Grid xs={12}>
<Paper sx={{ p: 2 }}>
<Grid container>
<Grid>
<FormControl component="fieldset">
<FormLabel component="legend">spacing</FormLabel>
<RadioGroup
name="spacing"
aria-label="spacing"
value={spacing.toString()}
onChange={handleChange}
row
>
{[0, 0.5, 1, 2, 3, 4, 8, 12].map((value) => (
<FormControlLabel
key={value}
value={value.toString()}
control={<Radio />}
label={value.toString()}
/>
))}
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Paper>
<HighlightedCode code={jsx} language="jsx" />
</Grid>
</Grid>
);
}
| 3,773 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/VariableWidthGrid.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function VariableWidthGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={3}>
<Grid xs="auto">
<Item>Variable width item</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,774 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/VariableWidthGrid.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Grid from '@mui/system/Unstable_Grid';
import styled from '@mui/system/styled';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
border: '1px solid',
borderColor: theme.palette.mode === 'dark' ? '#444d58' : '#ced7e0',
padding: theme.spacing(1),
borderRadius: '4px',
textAlign: 'center',
}));
export default function VariableWidthGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={3}>
<Grid xs="auto">
<Item>Variable width item</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
</Box>
);
}
| 3,775 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/VariableWidthGrid.tsx.preview | <Grid container spacing={3}>
<Grid xs="auto">
<Item>Variable width item</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid> | 3,776 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/grid/grid.md | ---
productId: system
title: React Grid component
githubLabel: 'component: Grid'
---
# Grid
<p class="description">The responsive layout grid adapts to screen size and orientation, ensuring consistency across layouts.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
The `Grid` component works well for a layout with known columns. The columns can be configured in multiple breakpoints which you have to specify the column span of each child.
## How it works
The grid system is implemented with the `Grid` component:
- It uses [CSS's Flexible Box module](https://www.w3.org/TR/css-flexbox-1/) for high flexibility.
- The grid is always a flex item. Use the `container` prop to add flex container to it.
- Item widths are set in percentages, so they're always fluid and sized relative to their parent element.
- There are five default grid breakpoints: xs, sm, md, lg, and xl. If you need custom breakpoints, check out [custom breakpoints grid](#custom-breakpoints).
- Integer values can be given to each breakpoint, indicating how many of the 12 available columns are occupied by the component when the viewport width satisfies the [breakpoint constraints](/material-ui/customization/breakpoints/#default-breakpoints).
- It uses negative margin and padding technique to create [gap-like](https://developer.mozilla.org/en-US/docs/Web/CSS/gap) between children.
- It **does not** have the concept of rows. Meaning, you can't make the children span to multiple rows. If you need to do that, we recommend to use [CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout) instead.
- It **does not** offer auto-placement children feature. It will try to fit the children one by one and if there is not enough space, the rest of the children will start on the next line and so on. If you need the auto-placement feature, we recommend to use [CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Auto-placement_in_grid_layout) instead.
:::warning
The Grid component shouldn't be confused with a data grid; it is closer to a layout grid. For a data grid head to [the Data Grid component](/x/react-data-grid/).
:::
## Fluid grids
Fluid grids use columns that scale and resize content. A fluid grid's layout can use breakpoints to determine if the layout needs to change dramatically.
### Basic grid
In order to create a grid layout, you need a container. Use `container` prop to create a grid container that wraps the grid items (the `Grid` is always an item).
Column widths are integer values between 1 and 12; they apply at any breakpoint and indicate how many columns are occupied by the component.
A value given to a breakpoint applies to all the other breakpoints wider than it (unless overridden, as you can read later in this page). For example, `xs={12}` sizes a component to occupy the whole viewport width regardless of its size.
{{"demo": "BasicGrid.js", "bg": true}}
### Multiple breakpoints
Components may have multiple widths defined, causing the layout to change at the defined breakpoint. Width values given to larger breakpoints override those given to smaller breakpoints.
For example, `xs={12} sm={6}` sizes a component to occupy half of the viewport width (6 columns) when viewport width is [600 or more pixels](/material-ui/customization/breakpoints/#default-breakpoints). For smaller viewports, the component fills all 12 available columns.
{{"demo": "FullWidthGrid.js", "bg": true}}
## Spacing
To control space between children, use the `spacing` prop.
The spacing value can be any positive number, including decimals and any string.
The prop is converted into a CSS property using the [`theme.spacing()`](/material-ui/customization/spacing/) helper.
{{"demo": "SpacingGrid.js", "bg": true, "hideToolbar": true}}
### Row & column spacing
The `rowSpacing` and `columnSpacing` props allow for specifying the row and column gaps independently.
It's similar to the `row-gap` and `column-gap` properties of [CSS Grid](/system/grid/#row-gap-amp-column-gap).
{{"demo": "RowAndColumnSpacing.js", "bg": true}}
## Responsive values
You can switch the props' value based on the active breakpoint.
For instance, we can implement the [recommended](https://m2.material.io/design/layout/responsive-layout-grid.html) responsive layout grid of Material Design.
{{"demo": "ResponsiveGrid.js", "bg": true}}
Responsive values is supported by:
- `columns`
- `columnSpacing`
- `direction`
- `rowSpacing`
- `spacing`
- all the [other props](#system-props) of the system
## Auto-layout
The Auto-layout makes the _items_ equitably share the available space.
That also means you can set the width of one _item_ and the others will automatically resize around it.
{{"demo": "AutoGrid.js", "bg": true}}
### Variable width content
Set one of the size breakpoint props to `"auto"` instead of `true` / a `number` to size
a column based on the natural width of its content.
{{"demo": "VariableWidthGrid.js", "bg": true}}
## Nested Grid
The grid container that renders inside another grid container is a nested grid which inherits the [`columns`](#columns) and [`spacing`](#spacing) from the top. The deep nested grid will inherit the props from the upper nested grid if it receives those props.
{{"demo": "NestedGrid.js", "bg": true}}
## Columns
You can change the default number of columns (12) with the `columns` prop.
{{"demo": "ColumnsGrid.js", "bg": true}}
## Offset
Move the item to the right by using offset props which can be:
- number, for example, `mdOffset={2}` - when used the item is moved to the right by 2 columns starts from `md` breakpoint and up.
- `"auto"` - when used, the item is moved to the right edge of the grid container.
{{"demo": "OffsetGrid.js", "bg": true}}
## Custom breakpoints
If you specify custom breakpoints to the theme, you can use those names as grid item props in responsive values.
{{"demo": "CustomBreakpointsGrid.js", "bg": true}}
:::info
The custom breakpoints affect both the size and offset props:
```diff
-<Grid xs={6} xsOffset={2}>
+<Grid mobile={6} mobileOffset={2}>
```
:::
### TypeScript
You have to set module augmentation on the theme breakpoints interface. The properties with `true` value will appear as `{key}`(size prop) and `{key}Offset`(offset prop).
```ts
declare module '@mui/system' {
interface BreakpointOverrides {
// Your custom breakpoints
laptop: true;
tablet: true;
mobile: true;
desktop: true;
// Remove default breakpoints
xs: false;
sm: false;
md: false;
lg: false;
xl: false;
}
}
```
## Prevent scrollbar
If you use grid as a container in a small viewport, you might see a horizontal scrollbar because the negative margin is applied on all sides of the grid container.
To prevent the scrollbar, set `disableEqualOverflow` prop to `true`. It will enable negative margin only on the top and left sides of the grid which remove overflow on the right-hand side.
{{"demo": "OverflowGrid.js", "bg": true}}
:::warning
You should avoid adding borders or background to the grid when `disableEqualOverflow: true` because the negative margin (applied only at the top and left sides) makes the grid visually misaligned.
:::
## Limitations
### direction column and column-reverse
The column width (`xs`, ..., `xl`) and offset props are **not supported** within `direction="column"` and `direction="column-reverse"` containers.
They define the number of grids the component will use for a given breakpoint. They are intended to control **width** using `flex-basis` in `row` containers but they will impact height in `column` containers.
If used, these props may have undesirable effects on the height of the `Grid` item elements.
| 3,777 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/BasicStack.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function BasicStack() {
return (
<Box sx={{ width: '100%' }}>
<Stack spacing={2}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</Box>
);
}
| 3,778 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/BasicStack.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function BasicStack() {
return (
<Box sx={{ width: '100%' }}>
<Stack spacing={2}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</Box>
);
}
| 3,779 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/BasicStack.tsx.preview | <Stack spacing={2}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack> | 3,780 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/DirectionStack.js | import * as React from 'react';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function DirectionStack() {
return (
<div>
<Stack direction="row" spacing={2}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</div>
);
}
| 3,781 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/DirectionStack.tsx | import * as React from 'react';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function DirectionStack() {
return (
<div>
<Stack direction="row" spacing={2}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</div>
);
}
| 3,782 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/DirectionStack.tsx.preview | <Stack direction="row" spacing={2}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack> | 3,783 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/DividerStack.js | import * as React from 'react';
import Box from '@mui/system/Box';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function DividerStack() {
return (
<div>
<Stack
direction="row"
divider={
<Box
component="hr"
sx={{
border: (theme) =>
`1px solid ${theme.palette.mode === 'dark' ? '#262B32' : '#fff'}`,
}}
/>
}
spacing={2}
>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</div>
);
}
| 3,784 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/DividerStack.tsx | import * as React from 'react';
import Box from '@mui/system/Box';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function DividerStack() {
return (
<div>
<Stack
direction="row"
divider={
<Box
component="hr"
sx={{
border: (theme) =>
`1px solid ${theme.palette.mode === 'dark' ? '#262B32' : '#fff'}`,
}}
/>
}
spacing={2}
>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</div>
);
}
| 3,785 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/FlexboxGapStack.js | import * as React from 'react';
import Stack from '@mui/system/Stack';
import Box from '@mui/system/Box';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
flexGrow: 1,
}));
export default function FlexboxGapStack() {
return (
<Box sx={{ width: 200 }}>
<Stack spacing={{ xs: 1, sm: 2 }} direction="row" useFlexGap flexWrap="wrap">
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Long content</Item>
</Stack>
</Box>
);
}
| 3,786 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/FlexboxGapStack.tsx | import * as React from 'react';
import Stack from '@mui/system/Stack';
import Box from '@mui/system/Box';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
flexGrow: 1,
}));
export default function FlexboxGapStack() {
return (
<Box sx={{ width: 200 }}>
<Stack spacing={{ xs: 1, sm: 2 }} direction="row" useFlexGap flexWrap="wrap">
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Long content</Item>
</Stack>
</Box>
);
}
| 3,787 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/FlexboxGapStack.tsx.preview | <Stack spacing={{ xs: 1, sm: 2 }} direction="row" useFlexGap flexWrap="wrap">
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Long content</Item>
</Stack> | 3,788 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/InteractiveStack.js | import * as React from 'react';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
import FormControlLabel from '@mui/material/FormControlLabel';
import Paper from '@mui/material/Paper';
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import Grid from '@mui/system/Unstable_Grid';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function InteractiveStack() {
const [direction, setDirection] = React.useState('row');
const [justifyContent, setJustifyContent] = React.useState('center');
const [alignItems, setAlignItems] = React.useState('center');
const [spacing, setSpacing] = React.useState(2);
const jsx = `
<Stack
direction="${direction}"
justifyContent="${justifyContent}"
alignItems="${alignItems}"
spacing={${spacing}}
>
`;
return (
<Stack sx={{ flexGrow: 1 }}>
<Stack
direction={direction}
justifyContent={justifyContent}
alignItems={alignItems}
spacing={spacing}
sx={{ height: 240 }}
>
{[0, 1, 2].map((value) => (
<Item
key={value}
sx={{
p: 2,
pt: value + 1,
pb: value + 1,
}}
>
{`Item ${value + 1}`}
</Item>
))}
</Stack>
<Paper sx={{ p: 2 }}>
<Grid container spacing={3}>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">direction</FormLabel>
<RadioGroup
row
name="direction"
aria-label="direction"
value={direction}
onChange={(event) => {
setDirection(event.target.value);
}}
>
<FormControlLabel value="row" control={<Radio />} label="row" />
<FormControlLabel
value="row-reverse"
control={<Radio />}
label="row-reverse"
/>
<FormControlLabel
value="column"
control={<Radio />}
label="column"
/>
<FormControlLabel
value="column-reverse"
control={<Radio />}
label="column-reverse"
/>
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">alignItems</FormLabel>
<RadioGroup
row
name="alignItems"
aria-label="align items"
value={alignItems}
onChange={(event) => {
setAlignItems(event.target.value);
}}
>
<FormControlLabel
value="flex-start"
control={<Radio />}
label="flex-start"
/>
<FormControlLabel
value="center"
control={<Radio />}
label="center"
/>
<FormControlLabel
value="flex-end"
control={<Radio />}
label="flex-end"
/>
<FormControlLabel
value="stretch"
control={<Radio />}
label="stretch"
/>
<FormControlLabel
value="baseline"
control={<Radio />}
label="baseline"
/>
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">justifyContent</FormLabel>
<RadioGroup
row
name="justifyContent"
aria-label="justifyContent"
value={justifyContent}
onChange={(event) => {
setJustifyContent(event.target.value);
}}
>
<FormControlLabel
value="flex-start"
control={<Radio />}
label="flex-start"
/>
<FormControlLabel
value="center"
control={<Radio />}
label="center"
/>
<FormControlLabel
value="flex-end"
control={<Radio />}
label="flex-end"
/>
<FormControlLabel
value="space-between"
control={<Radio />}
label="space-between"
/>
<FormControlLabel
value="space-around"
control={<Radio />}
label="space-around"
/>
<FormControlLabel
value="space-evenly"
control={<Radio />}
label="space-evenly"
/>
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">spacing</FormLabel>
<RadioGroup
row
name="spacing"
aria-label="spacing"
value={spacing.toString()}
onChange={(event) => {
setSpacing(Number(event.target.value));
}}
>
{[0, 0.5, 1, 2, 3, 4, 8, 12].map((value) => (
<FormControlLabel
key={value}
value={value.toString()}
control={<Radio />}
label={value}
/>
))}
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Paper>
<HighlightedCode code={jsx} language="jsx" />
</Stack>
);
}
| 3,789 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/InteractiveStack.tsx | import * as React from 'react';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
import FormControlLabel from '@mui/material/FormControlLabel';
import Paper from '@mui/material/Paper';
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import Grid from '@mui/system/Unstable_Grid';
import Stack, { StackProps } from '@mui/system/Stack';
import { styled } from '@mui/system';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function InteractiveStack() {
const [direction, setDirection] = React.useState<StackProps['direction']>('row');
const [justifyContent, setJustifyContent] = React.useState('center');
const [alignItems, setAlignItems] = React.useState('center');
const [spacing, setSpacing] = React.useState(2);
const jsx = `
<Stack
direction="${direction}"
justifyContent="${justifyContent}"
alignItems="${alignItems}"
spacing={${spacing}}
>
`;
return (
<Stack sx={{ flexGrow: 1 }}>
<Stack
direction={direction}
justifyContent={justifyContent}
alignItems={alignItems}
spacing={spacing}
sx={{ height: 240 }}
>
{[0, 1, 2].map((value) => (
<Item
key={value}
sx={{
p: 2,
pt: value + 1,
pb: value + 1,
}}
>
{`Item ${value + 1}`}
</Item>
))}
</Stack>
<Paper sx={{ p: 2 }}>
<Grid container spacing={3}>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">direction</FormLabel>
<RadioGroup
row
name="direction"
aria-label="direction"
value={direction}
onChange={(event) => {
setDirection(event.target.value as StackProps['direction']);
}}
>
<FormControlLabel value="row" control={<Radio />} label="row" />
<FormControlLabel
value="row-reverse"
control={<Radio />}
label="row-reverse"
/>
<FormControlLabel
value="column"
control={<Radio />}
label="column"
/>
<FormControlLabel
value="column-reverse"
control={<Radio />}
label="column-reverse"
/>
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">alignItems</FormLabel>
<RadioGroup
row
name="alignItems"
aria-label="align items"
value={alignItems}
onChange={(event) => {
setAlignItems(event.target.value);
}}
>
<FormControlLabel
value="flex-start"
control={<Radio />}
label="flex-start"
/>
<FormControlLabel
value="center"
control={<Radio />}
label="center"
/>
<FormControlLabel
value="flex-end"
control={<Radio />}
label="flex-end"
/>
<FormControlLabel
value="stretch"
control={<Radio />}
label="stretch"
/>
<FormControlLabel
value="baseline"
control={<Radio />}
label="baseline"
/>
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">justifyContent</FormLabel>
<RadioGroup
row
name="justifyContent"
aria-label="justifyContent"
value={justifyContent}
onChange={(event) => {
setJustifyContent(event.target.value);
}}
>
<FormControlLabel
value="flex-start"
control={<Radio />}
label="flex-start"
/>
<FormControlLabel
value="center"
control={<Radio />}
label="center"
/>
<FormControlLabel
value="flex-end"
control={<Radio />}
label="flex-end"
/>
<FormControlLabel
value="space-between"
control={<Radio />}
label="space-between"
/>
<FormControlLabel
value="space-around"
control={<Radio />}
label="space-around"
/>
<FormControlLabel
value="space-evenly"
control={<Radio />}
label="space-evenly"
/>
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl component="fieldset">
<FormLabel component="legend">spacing</FormLabel>
<RadioGroup
row
name="spacing"
aria-label="spacing"
value={spacing.toString()}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setSpacing(Number((event.target as HTMLInputElement).value));
}}
>
{[0, 0.5, 1, 2, 3, 4, 8, 12].map((value) => (
<FormControlLabel
key={value}
value={value.toString()}
control={<Radio />}
label={value}
/>
))}
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Paper>
<HighlightedCode code={jsx} language="jsx" />
</Stack>
);
}
| 3,790 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/ResponsiveStack.js | import * as React from 'react';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function ResponsiveStack() {
return (
<div>
<Stack
direction={{ xs: 'column', sm: 'row' }}
spacing={{ xs: 1, sm: 2, md: 4 }}
>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</div>
);
}
| 3,791 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/ResponsiveStack.tsx | import * as React from 'react';
import Stack from '@mui/system/Stack';
import { styled } from '@mui/system';
const Item = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#262B32' : '#fff',
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
}));
export default function ResponsiveStack() {
return (
<div>
<Stack
direction={{ xs: 'column', sm: 'row' }}
spacing={{ xs: 1, sm: 2, md: 4 }}
>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack>
</div>
);
}
| 3,792 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/ResponsiveStack.tsx.preview | <Stack
direction={{ xs: 'column', sm: 'row' }}
spacing={{ xs: 1, sm: 2, md: 4 }}
>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
</Stack> | 3,793 |
0 | petrpan-code/mui/material-ui/docs/data/system/components | petrpan-code/mui/material-ui/docs/data/system/components/stack/stack.md | ---
productId: system
title: React Stack component
components: Stack
githubLabel: 'component: Stack'
---
# Stack
<p class="description">Stack is a container component for arranging elements vertically or horizontally.</p>
## Introduction
The Stack component manages the layout of its immediate children along the vertical or horizontal axis, with optional spacing and dividers between each child.
:::info
Stack is ideal for one-dimensional layouts, while Grid is preferable when you need both vertical _and_ horizontal arrangement.
:::
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
## Basics
```jsx
import Stack from '@mui/joy/Stack';
```
The Stack component acts as a generic container, wrapping around the elements to be arranged.
Use the `spacing` prop to control the space between children.
The spacing value can be any number, including decimals, or a string.
(The prop is converted into a CSS property using the [`theme.spacing()`](/material-ui/customization/spacing/) helper.)
{{"demo": "BasicStack.js", "bg": true}}
### Stack vs. Grid
`Stack` is concerned with one-dimensional layouts, while [Grid](/system/react-grid/) handles two-dimensional layouts. The default direction is `column` which stacks children vertically.
## Direction
By default, Stack arranges items vertically in a column.
Use the `direction` prop to position items horizontally in a row:
{{"demo": "DirectionStack.js", "bg": true}}
## Dividers
Use the `divider` prop to insert an element between each child, as shown below:
{{"demo": "DividerStack.js", "bg": true}}
## Responsive values
You can switch the `direction` or `spacing` values based on the active breakpoint.
{{"demo": "ResponsiveStack.js", "bg": true}}
## Flexbox gap
To use [flexbox `gap`](https://developer.mozilla.org/en-US/docs/Web/CSS/gap) for the spacing implementation, set the `useFlexGap` prop to true.
It removes the [known limitations](#limitations) of the default implementation that uses CSS nested selector. However, CSS flexbox gap is not fully supported in some browsers.
We recommend checking the [support percentage](https://caniuse.com/?search=flex%20gap) before using it.
{{"demo": "FlexboxGapStack.js", "bg": true}}
## Interactive demo
Below is an interactive demo that lets you explore the visual results of the different settings:
{{"demo": "InteractiveStack.js", "hideToolbar": true, "bg": true}}
## System props
As a CSS utility component, the `Stack` supports all [`system`](/system/properties/) properties. You can use them as props directly on the component.
For instance, a margin-top:
```jsx
<Stack mt={2}>
```
## Limitations
### Margin on the children
Customizing the margin on the children is not supported by default.
For instance, the top-margin on the `button` component below will be ignored.
```jsx
<Stack>
<button style={{ marginTop: '30px' }}>...</button>
</Stack>
```
:::success
To overcome this limitation, set [`useFlexGap`](#flexbox-gap) prop to true to switch to CSS flexbox gap implementation.
You can learn more about this limitation by visiting this [RFC](https://github.com/mui/material-ui/issues/33754).
:::
### white-space: nowrap
The initial setting on flex items is `min-width: auto`.
This causes a positioning conflict when children use `white-space: nowrap;`.
You can reproduce the issue with:
```jsx
<Stack direction="row">
<span style={{ whiteSpace: 'nowrap' }}>
```
In order for the item to stay within the container you need to set `min-width: 0`.
```jsx
<Stack direction="row" sx={{ minWidth: 0 }}>
<span style={{ whiteSpace: 'nowrap' }}>
```
## Anatomy
The Stack component is composed of a single root `<div>` element:
```html
<div class="MuiStack-root">
<!-- Stack contents -->
</div>
```
| 3,794 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/display/Block.js | import * as React from 'react';
import Box from '@mui/material/Box';
export default function Block() {
return (
<div style={{ width: '100%' }}>
<Box
component="span"
sx={{
display: 'block',
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',
}}
>
block
</Box>
<Box
component="span"
sx={{
display: 'block',
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',
}}
>
block
</Box>
</div>
);
}
| 3,795 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/display/Block.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
export default function Block() {
return (
<div style={{ width: '100%' }}>
<Box
component="span"
sx={{
display: 'block',
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',
}}
>
block
</Box>
<Box
component="span"
sx={{
display: 'block',
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',
}}
>
block
</Box>
</div>
);
}
| 3,796 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/display/Hiding.js | import * as React from 'react';
import Box from '@mui/material/Box';
export default function Hiding() {
return (
<div style={{ width: '100%' }}>
<Box
sx={{
display: { xs: 'block', md: 'none' },
m: 1,
fontSize: '0.875rem',
fontWeight: '700',
}}
>
hide on screens wider than md
</Box>
<Box
sx={{
display: { xs: 'none', md: 'block' },
m: 1,
fontSize: '0.875rem',
fontWeight: '700',
}}
>
hide on screens smaller than md
</Box>
</div>
);
}
| 3,797 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/display/Hiding.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
export default function Hiding() {
return (
<div style={{ width: '100%' }}>
<Box
sx={{
display: { xs: 'block', md: 'none' },
m: 1,
fontSize: '0.875rem',
fontWeight: '700',
}}
>
hide on screens wider than md
</Box>
<Box
sx={{
display: { xs: 'none', md: 'block' },
m: 1,
fontSize: '0.875rem',
fontWeight: '700',
}}
>
hide on screens smaller than md
</Box>
</div>
);
}
| 3,798 |
0 | petrpan-code/mui/material-ui/docs/data/system | petrpan-code/mui/material-ui/docs/data/system/display/Inline.js | 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,799 |
Subsets and Splits