|
2 | 2 | title: Box |
3 | 3 | --- |
4 | 4 |
|
5 | | -The Box component serves as a wrapper component for most layout related needs. Use Box to set values such as `display`, `width`, `height`, and more. See the LAYOUT section of our [System Props](/system-props) documentation for the full list of available props. In practice, this component is used frequently as a wrapper around other components to achieve Box Model related styling. |
6 | | - |
7 | | -## Default example |
8 | | - |
9 | | -```jsx live live |
10 | | -<Box> |
11 | | - Box can be used to create both{' '} |
12 | | - <Box as="span" color="text.inverse" bg="bg.successInverse"> |
13 | | - inline |
14 | | - </Box>{' '} |
15 | | - and |
16 | | - <Box color="text.inverse" bg="bg.dangerInverse"> |
17 | | - block-level elements, |
| 5 | +import {Props} from '../src/props' |
| 6 | +import {Box} from '@primer/components' |
| 7 | + |
| 8 | +Box is a low-level utility component that accepts [styled system props](https://styled-system.com/table/) to enable custom theme-aware styling. |
| 9 | + |
| 10 | +```jsx live |
| 11 | +<Box color="text.secondary" bg="bg.tertiary" p={3}> |
| 12 | + Hello |
| 13 | +</Box> |
| 14 | +``` |
| 15 | + |
| 16 | +## Props |
| 17 | + |
| 18 | +<Props of={Box} /> |
| 19 | + |
| 20 | +Box also accepts all [styled system props](https://styled-system.com/table/). |
| 21 | + |
| 22 | +## Examples |
| 23 | + |
| 24 | +### Border on all sides |
| 25 | + |
| 26 | +```jsx live |
| 27 | +<Box borderColor="border.primary" borderWidth={1} borderStyle="solid" p={3}> |
| 28 | + Hello |
| 29 | +</Box> |
| 30 | +``` |
| 31 | + |
| 32 | +### Border on one side |
| 33 | + |
| 34 | +```jsx live |
| 35 | +<Box borderColor="border.primary" borderBottomWidth={1} borderBottomStyle="solid" pb={3}> |
| 36 | + Hello |
| 37 | +</Box> |
| 38 | +``` |
| 39 | + |
| 40 | +### Flexbox |
| 41 | + |
| 42 | +Use Box to create [flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox) layouts. |
| 43 | + |
| 44 | +```jsx live |
| 45 | +<Box display="flex"> |
| 46 | + <Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid"> |
| 47 | + 1 |
18 | 48 | </Box> |
19 | | - <Box color="text.inverse" bg="bg.warningInverse" width={[1, 1, 1 / 2]}> |
20 | | - elements with fixed or responsive width and height, |
| 49 | + <Box flexGrow={1} p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid"> |
| 50 | + 2 |
21 | 51 | </Box> |
22 | | - <Box color="text.inverse" bg="bg.infoInverse" p={4} mt={2}> |
23 | | - and more! |
| 52 | + <Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid"> |
| 53 | + 3 |
24 | 54 | </Box> |
25 | 55 | </Box> |
26 | 56 | ``` |
27 | 57 |
|
28 | | -## System props |
| 58 | +### Grid |
29 | 59 |
|
30 | | -Box components get the `COMMON`, `LAYOUT`, and `FLEX` categories of system props. Read our [System Props](/system-props) doc page for a full list of available props. |
| 60 | +Use Box to create [grid](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids) layouts. |
31 | 61 |
|
32 | | -## Component props |
33 | | - |
34 | | -| Prop name | Type | Default | Description | |
35 | | -| :-------- | :----- | :-----: | :---------------------------------- | |
36 | | -| as | String | `div` | sets the HTML tag for the component | |
| 62 | +```jsx live |
| 63 | +<Box display="grid" gridTemplateColumns="1fr 1fr" gridGap={3}> |
| 64 | + <Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid"> |
| 65 | + 1 |
| 66 | + </Box> |
| 67 | + <Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid"> |
| 68 | + 2 |
| 69 | + </Box> |
| 70 | + <Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid"> |
| 71 | + 3 |
| 72 | + </Box> |
| 73 | +</Box> |
| 74 | +``` |
0 commit comments