Box
is the most abstract layout component that allows to apply margin
and padding
properties according to the spacing system. By default, it renders a div
element.
The Box
component is useful because it helps with several common cases:
- Create a layout that uses Forma 36 spacing system
- Compose new component and allow to override element using the
as
property.
Import
import { Box } from '@contentful/f36-components';// orimport { Box } from '@contentful/f36-core';
Examples
Margins & Paddings
Margins and paddings for Box component are based on our spacing system.
Here is an overview of spacings that are available:
spacing2Xs
spacingXs
spacingXs
spacingS
spacingM
spacingL
spacingXl
spacing2Xl
spacing3Xl
spacing4Xl
Here is a good example that demonstrates how you can apply margin
and padding
properties to the Box
component:
as
property
If you want to keep all the styling you've applied to a component but just switch what's being ultimately rendered (be it a different HTML tag or a different custom component), you can use the "as" prop to do this at runtime.
Props (API reference)
- Name
as
HTML Tag or React Component (e.g. div, span, etc) - Name
children
ReactNode - Name
className
DescriptionCSS class to be appended to the root element
string - Name
display
DescriptionSets the display behavior of the element
"ruby""table""-moz-initial""inherit""initial""revert""unset""block""inline""run-in""-ms-flexbox""-ms-grid""-webkit-flex""flex""flow""flow-root""grid""ruby-base""ruby-base-container""ruby-text""ruby-text-container""table-caption""table-cell""table-column""table-column-group""table-footer-group""table-header-group""table-row""table-row-group""-ms-inline-flexbox""-ms-inline-grid""-webkit-inline-flex""inline-block""inline-flex""inline-grid""inline-list-item""inline-table""contents""list-item""none"string & {} - Name
margin
Descriptionsets margin to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginBottom
Descriptionsets margin-bottom to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginLeft
Descriptionsets margin-left to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginRight
Descriptionsets margin-right to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
marginTop
Descriptionsets margin-top to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
padding
Descriptionsets padding to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
paddingBottom
Descriptionsets padding-bottom to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
paddingLeft
Descriptionsets padding-left to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
paddingRight
Descriptionsets padding-right to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
paddingTop
Descriptionsets padding-top to one of the corresponding spacing tokens
"none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl" - Name
testId
DescriptionA [data-test-id] attribute used for testing purposes
string