Box
Box is the lowest-level component for binding theme-based styles to an individual element on the screen.
import { Box, useBoxStyles } from '@balance-web/box';Box is the lowest-level component for binding theme-based styles to an individual element on the screen. Internally, all Balance components are made up of Boxes.
Semantic elements
By default, Box renders a div element. You can customise this via the as
prop. Non-Balance props will be forwarded to the underlying element.
<Box as="span" aria-hidden>
...
</Box>Usage
Padding
The padding keys allow targeting each side as well as the x-axis and y-axis.
paddingpaddingToppaddingRightpaddingBottompaddingLeftpaddingXpadding-left and padding-rightpaddingYpadding-top and padding-bottom
Margin
The margin keys allow targeting each side as well as the x-axis and y-axis.
marginmarginTopmarginRightmarginBottommarginLeftmarginXmargin-left and margin-rightmarginYmargin-top and margin-bottom
Border
Apply a border to the box:
Border radius
Apply a border-radius to the box:
Box shadow
Apply a box-shadow to the box:
Height
Apply a height to the box:
Width
Apply a width to the box:
Combined
Mix and match style properties to achieve the desired aesthetic.
Responsive Props
Instead of manually managing media queries and adding nested style objects throughout a code base, we offer a convenient shorthand syntax for adding responsive styles with a mobile-first approach.
Each of the above style props accepts a value or array of values. To skip
certain breakpoints, you can pass null to any position in the array to avoid
generating unnecessary CSS.
While this approach has been widely adopted with great success, much like any new idea, it can seem odd or off-putting at first. We recommend giving it a chance.
Building on Box
useBoxStyles is the hook Box itself uses to turn its props into CSS —
reach for it if you're building a component with the same spacing/border/
background vocabulary but that doesn't want to render a Box underneath.
MarginProps, PaddingProps, ChildFlexProps and ChildGridProps are the
individual prop-group types it's built from, exported so you can compose the
same vocabulary into your own component's props without redeclaring it.