import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Box } from './box';
# Box
The `Box` is a utility component that accepts many helper props to make styling easier.
## Props
## Usage
The following describes the props and example usage for this component.
### Margin
The margin props `margin`, `marginTop`, `marginRight`, `marginBottom`, `marginLeft`, `marginInline`, `marginInlineStart`, and `marginInlineEnd` can be used to set the margins of the `Box` component. All of the margin props accept [responsive props](#responsive-props) in the form of array props
Accepted props are: `0, 1, 2, 4, 6, 8, 9, 10, 12, 'auto` or array of these values
```jsx
// Responsive props
```
### Padding
The padding props work very similarly to margin. The padding props `padding`, `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`, `paddingInline`, `paddingInlineStart`, and `paddingInlineEnd` can be used to set the paddings of the `Box` component. All of the padding props accept [responsive props](#responsive-props) in the form of array props
Accepted props are: `0, 1, 2, 4, 6, 8, 9, 10, 12` or array of these values
```jsx
// Responsive props
```
### Display
The `display` prop can be used to set the display of the `Box` component. All of the display props accept [responsive props](#responsive-props) in the form of array props.
Accepted props imported from the design system `Display` const are:
- `Display.Block`
- `Display.Flex`
- `Display.Grid`
- `Display.InlineBlock`
- `Display.InlineFlex`
- `Display.InlineGrid`
- `Display.Inline`
- `Display.ListItem`
- `Display.None`
or array of these values.
```jsx
import { Display } from '../../../helpers/constants/design-system';
import Box from '../ui/box';
```
### Color
The `color` prop can be used to set the color of the content in Box component. The `color` prop accepts [responsive props](#responsive-props) in the form of array props. Defaults to `Color.textDefault`.
Example of importing `TextColor` object with `Box` component
```jsx
import { TextColor } from '../../../helpers/constants/design-system';
import Box from '../ui/box';
Text goes here;
```
### Background Color
Use the `backgroundColor` prop along with the `Color` or `BackgroundColor` object from `ui/helpers/constants/design-system.js` to change background color. The `backgroundColor` prop accepts [responsive props](#responsive-props) in the form of array props.
Example of importing `BackgroundColor` object with `Box` component
```jsx
import {
BackgroundColor,
TextColor,
} from '../../../helpers/constants/design-system';
import Box from '../ui/box';
BackgroundColor.backgroundDefault
;
```
### Border Color
Use the `borderColor` prop along with the `Color` or `BorderColor` object from `ui/helpers/constants/design-system.js` to change border color. The `borderColor` prop accepts [responsive props](#responsive-props) in the form of array props.
Example of importing `BorderColor` object with `Box` component
```jsx
import {
BackgroundColor,
BorderColor,
TextColor,
} from '../../../helpers/constants/design-system';
import Box from '../ui/box';
BorderColor.borderDefault
;
```
### Border Radius
Use the `borderRadius` prop along with the `BorderRadius` object from `ui/helpers/constants/design-system.js` to change border radius. The `borderRadius` prop accepts [responsive props](#responsive-props) in the form of array props.
Example of importing `BorderRadius` object with `Box` component
```jsx
import { BorderRadius } from '../../../helpers/constants/design-system';
import Box from '../ui/box';
BorderRadius.none 0px
BorderRadius.XS 2px
BorderRadius.SM 4px
BorderRadius.MD 6px
BorderRadius.LG 8px
BorderRadius.XL 12px
BorderRadius.pill 9999px
BorderRadius.full 50%
```
### Responsive Props
The box component provides a responsive props api in the form of array props. Array props are inspired by [styled-systems array props](https://styled-system.com/guides/array-props). The responsive props follow a mobile first methodology with the first item in the array applying the style to the base level size e.g. `0px` and up. The second item overwrites the first items styles at the next breakpoint.
- All Box props accept the responsive props format
- To skip a breakpoint use `null` as the skipped item's value e.g. ``
```
// the responsive props
// is equivalent to the css
.box {
display: block;
@media screen and (max-width: $breakpoint-sm) {
display: flex;
}
}
```
```jsx
import {
BorderColor,
BackgroundColor,
} from '../../../helpers/constants/design-system';
import Box from '../ui/box';
responsive
props
example
;
```
### As
The polymorphic `as` prop allows you to change the root HTML element of the Box component. Defaults to `'div'`
```jsx
import Box from '../../ui/box';
div(default)
ul
li
button
header
```
### Width
Use the `width` prop to pass a singular `BlockSize` or for a responsive width pass an array up to 4 `BlockSize`
Responsive widths go from smallest to largest screen sizes
Example: [BlockSize.Half, BlockSize.ThreeFourths, BlockSize.OneFifth, BlockSize.ThreeSixths]
- BlockSize.Half is the default width for `base screen size (0px)` and up
- BlockSize.ThreeFourths is the width for `small screen size (576px) ` and up
- BlockSize.OneFifth is the width for `medium screen size (768px)` and up
- BlockSize.ThreeSixths is the width for `large screen size (1280px)` and up
```jsx
import {
BlockSize,
Display,
FlexWrap,
} from '../../../helpers/constants/design-system';
import Box from '../../ui/box';
<>
Static widths
BlockSize.Full
BlockSize.Half
BlockSize.Half
BlockSize.OneThird
BlockSize.OneThird
BlockSize.OneThird
BlockSize.OneFourth
BlockSize.OneFourth
BlockSize.OneFourth
BlockSize.OneFourth
Responsive widths
BlockSize.Full, BlockSize.Half, BlockSize.OneThird, BlockSize.OneFourth,
BlockSize.Full, BlockSize.Half, BlockSize.OneThird, BlockSize.OneFourth,
BlockSize.Full, BlockSize.Half, BlockSize.OneThird, BlockSize.OneFourth,
BlockSize.Full, BlockSize.Half, BlockSize.OneThird, BlockSize.OneFourth,
>;
```