Skip to content

Box

The zero-opinion layout primitive — a <div> (or any element via as) wired up to the full LayoutProps surface. Every other primitive composes Box.

  • stable
  • since v0.1.0
  • 3.41 kB
  • primitive
  • layout

Polymorphic via as, so semantics travel with the component. asChild defers rendering to a child component while merging Box's layout class and inline style.

Preview
Open
tsx

Every spacing, sizing, colour, position, and flex/grid prop exposed by the layout system lives on Box. Each accepts a token value, a raw CSS length, or a responsive map keyed by breakpoint. The same prop surface is composed into Stack, Inline, Flex, Grid, and every Cynosure component that derives from Box.

Preview
Open
tsx

Render any intrinsic element (or React component) while keeping the LayoutProps surface. The component’s TypeScript type follows as so attribute autocomplete stays accurate — as="a" gives you href, as="button" gives you type, and so on.

Preview
Open
tsx

Pass the layout class + style straight onto a single child — useful when wrapping a third-party component, an <a> from a router, or another Cynosure primitive that you want to extend without an extra wrapper element.

Preview
Open
tsx

Every layout prop accepts a { base, sm, md, lg, xl, 2xl } map. Values cascade upward (a md value applies from the md breakpoint until overridden), so you typically only set the breakpoints that change.

Preview
Open
tsx
PropTypeDefaultDescription
className
string
Additional class names appended after Cynosure's base classes.
style
CSSProperties
Inline style overrides merged after computed layout styles.
children
ReactNode
Rendered content.
padding
Padding on all four sides. Token from the spacing scale.
paddingX
Horizontal padding (left + right). Overrides `padding` on the X axis.
paddingY
Vertical padding (top + bottom). Overrides `padding` on the Y axis.
paddingTop
Padding on the top edge. Beats `padding` / `paddingY`.
paddingRight
Padding on the right (inline-end in RTL) edge.
paddingBottom
Padding on the bottom edge.
paddingLeft
Padding on the left (inline-start in RTL) edge.
margin
Margin on all four sides. Accepts the spacing scale or `"auto"`.
marginX
Horizontal margin (left + right). Use `"auto"` to centre.
marginY
Vertical margin (top + bottom).
marginTop
Margin on the top edge.
marginRight
Margin on the right edge.
marginBottom
Margin on the bottom edge.
marginLeft
Margin on the left edge.
width
Element width. Accepts a `SpaceToken`, `LengthValue`, or named alias.
height
Element height. Accepts a `SpaceToken`, `LengthValue`, or named alias.
minWidth
Minimum width — useful for preventing flex children from collapsing.
maxWidth
Maximum width — `"prose"` caps to a comfortable reading measure.
minHeight
Minimum height.
maxHeight
Maximum height.
background
Background colour. Use a `ColorToken` like `"bg.surface"` for theme awareness.
color
Text colour. Inherits unless set.
borderColor
Border colour. Pair with `borderWidth` to make the border visible.
borderWidth
Border thickness in scale steps.
borderStyle
Border line style.
borderRadius
Corner rounding token.
boxShadow
Drop-shadow token from the elevation scale.
opacity
Responsive<number | `${number}`>
Opacity 0–1. Use sparingly — prefer surface tokens over translucency.
overflow
How content that exceeds the box is handled.
overflowX
Horizontal-axis overflow control. Overrides `overflow` for the X axis.
overflowY
Vertical-axis overflow control.
display
CSS `display` value. `"contents"` removes the element's box from layout.
position
CSS `position`. Pair with `top`/`right`/`bottom`/`left` for placement.
top
Top inset (when positioned). Accepts a `SpaceToken`, `"auto"`, `"0"`, or `LengthValue`.
right
Right inset (when positioned).
bottom
Bottom inset (when positioned).
left
Left inset (when positioned).
zIndex
Stacking-context layer token (`"modal"`, `"tooltip"`, …).
gridColumn
Responsive<string>
Grid-column shorthand (e.g. `"1 / 3"`, `"span 2"`).
gridRow
Responsive<string>
Grid-row shorthand.
gridArea
Responsive<string>
Named grid area.
flex
Responsive<"1" | "none" | "auto" | "initial" | (string & {})>
Shorthand: `1 | auto | none | initial | <css>`. Resolves to `flex` on the child.
flexGrow
Responsive<number | `${number}`>
Grow factor inside a flex container.
flexShrink
Responsive<number | `${number}`>
Shrink factor inside a flex container.
flexBasis
Responsive<SizeValue | "content">
Initial main-axis size before grow/shrink.
alignSelf
Override `align-items` for a single child.
justifySelf
Override `justify-items` for a single child (grid).
order
Responsive<number | `${number}`>
Flex/grid child reorder index.
asChild
boolean
When `true`, renders the primitive's single React child via `Slot`, forwarding className/style/ref/event handlers onto it.
as
ElementType
"div"
Rendered intrinsic element or component.
ref
ForwardedRef<Element>
  • Reach for Box whenever you need a styled wrapper but don’t want to think about flex / grid direction. For row/column flow, prefer Inline or Stack; for centered single children, prefer Center.
  • Use as to keep semantics tight: as="section" for landmark regions, as="article" for self-contained cards, as="aside" for complementary content.
  • Combine asChild with Link from your router to inherit Box’s layout props without adding an extra DOM node.