Skip to content

Commit e143727

Browse files
mapache-salvajemnajdova
authored andcommitted
[core][docs] Restore and revise the Box docs (mui#40622)
1 parent c4bd8a1 commit e143727

32 files changed

+401
-106
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import Box from '@mui/joy/Box';
3+
4+
export default function BoxBasic() {
5+
return (
6+
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
7+
This Box renders as an HTML section element.
8+
</Box>
9+
);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import Box from '@mui/joy/Box';
3+
4+
export default function BoxBasic() {
5+
return (
6+
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
7+
This Box renders as an HTML section element.
8+
</Box>
9+
);
10+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
This Box renders as an HTML section element.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { Box, ThemeProvider } from '@mui/joy';
3+
4+
export default function BoxSx() {
5+
return (
6+
<ThemeProvider
7+
theme={{
8+
colorSchemes: {
9+
light: {
10+
palette: {
11+
primary: {
12+
400: '#38bdf8',
13+
700: '#0369a1',
14+
},
15+
},
16+
},
17+
},
18+
}}
19+
>
20+
<Box
21+
sx={{
22+
width: 100,
23+
height: 100,
24+
borderRadius: 1,
25+
bgcolor: 'primary.700',
26+
'&:hover': {
27+
bgcolor: 'primary.400',
28+
},
29+
}}
30+
/>
31+
</ThemeProvider>
32+
);
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { Box, ThemeProvider } from '@mui/joy';
3+
4+
export default function BoxSx() {
5+
return (
6+
<ThemeProvider
7+
theme={{
8+
colorSchemes: {
9+
light: {
10+
palette: {
11+
primary: {
12+
400: '#38bdf8',
13+
700: '#0369a1',
14+
},
15+
},
16+
},
17+
},
18+
}}
19+
>
20+
<Box
21+
sx={{
22+
width: 100,
23+
height: 100,
24+
borderRadius: 1,
25+
bgcolor: 'primary.700',
26+
'&:hover': {
27+
bgcolor: 'primary.400',
28+
},
29+
}}
30+
/>
31+
</ThemeProvider>
32+
);
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import Box from '@mui/joy/Box';
3+
4+
export default function BoxSystemProps() {
5+
return (
6+
<Box
7+
height={200}
8+
width={200}
9+
my={4}
10+
display="flex"
11+
alignItems="center"
12+
gap={4}
13+
p={2}
14+
sx={{ border: '2px solid grey' }}
15+
>
16+
This Box uses MUI System props for quick customization.
17+
</Box>
18+
);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import Box from '@mui/joy/Box';
3+
4+
export default function BoxSystemProps() {
5+
return (
6+
<Box
7+
height={200}
8+
width={200}
9+
my={4}
10+
display="flex"
11+
alignItems="center"
12+
gap={4}
13+
p={2}
14+
sx={{ border: '2px solid grey' }}
15+
>
16+
This Box uses MUI System props for quick customization.
17+
</Box>
18+
);
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
This Box uses MUI System props for quick customization.

docs/data/joy/components/box/box.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,57 @@ components: Box
55
githubLabel: 'component: Box'
66
---
77

8+
<!-- This page's content is duplicated (with some product-specific details) across the Material UI, Joy UI, and MUI System docs. Any changes should be applied to all three pages at the same time. -->
9+
810
# Box
911

1012
<p class="description">The Box component is a generic, theme-aware container with access to CSS utilities from MUI System.</p>
1113

12-
:::warning
13-
Please refer to the [Box](/system/react-box/) component page in the MUI System docs for demos and details on usage.
14+
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
15+
16+
## Introduction
17+
18+
The Box component is a generic container for grouping other components.
19+
It's a fundamental building block when working with Joy UI—you can think of it as a `<div>` with extra built-in features, like access to your app's theme and the [`sx` prop](/system/getting-started/the-sx-prop/).
20+
21+
### Usage
22+
23+
The Box component differs from other containers available in Joy UI in that its usage is intended to be multipurpose and open-ended, just like a `<div>`.
24+
Components like [Stack](/joy-ui/react-stack/) and [Sheet](/joy-ui/react-sheet/), by contrast, feature usage-specific props that make them ideal for certain use cases: Stack for one-dimensional layouts, and Sheet for surfaces that need access to Joy UI's global variants.
25+
26+
## Basics
27+
28+
```jsx
29+
import Box from '@mui/joy/Box';
30+
```
31+
32+
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.
33+
The demo below replaces the `<div>` with a `<section>` element:
34+
35+
{{"demo": "BoxBasic.js", "defaultCodeOpen": true }}
36+
37+
## Customization
38+
39+
### With MUI System props
40+
41+
As a CSS utility component, the Box supports all [MUI System properties](/system/properties/).
42+
You can use them as props directly on the component.
43+
44+
{{"demo": "BoxSystemProps.js", "defaultCodeOpen": true }}
45+
46+
### With the sx prop
47+
48+
Use the [`sx` prop](/system/getting-started/the-sx-prop/) to quickly customize any Box instance using a superset of CSS that has access to all the style functions and theme-aware properties exposed in the MUI System package.
49+
The demo below shows how to apply colors from the theme using this prop:
50+
51+
{{"demo": "BoxSx.js", "defaultCodeOpen": true }}
52+
53+
## Anatomy
54+
55+
The Box component is composed of a single root `<div>` element:
1456

15-
The Box component is a part of the standalone [MUI System](/system/getting-started/) utility library.
16-
It is re-exported from `@mui/joy` for your convenience.
17-
:::
57+
```html
58+
<div className="MuiBox-root">
59+
<!-- contents of the Box -->
60+
</div>
61+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import Box from '@mui/material/Box';
3+
4+
export default function BoxBasic() {
5+
return (
6+
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
7+
This Box renders as an HTML section element.
8+
</Box>
9+
);
10+
}

0 commit comments

Comments
 (0)