Box
The base layout primitive. Handles spacing, layout, colour, borders, and theme skins, shapes, and shadows.
Box is a styled div built with styled-components and styled-system. Use it for layout, spacing, surfaces and any container that needs theme-aware styles. Every other element (Text, Button, Field) extends it, so the props on this page are available everywhere.
Import#
import { Box } from "@reactberry/system/elements";
Usage#
import { Box, Text } from "@reactberry/system/elements";
export default function StatCard() {
return (
<Box display="flex" flexDirection="column" gap="xs" p="m" skin="card" shape="rounded" $shadow="small">
<Text fontSize="s" color="secondary">Monthly revenue</Text>
<Text fontSize="xl" fontWeight="600">$48,250</Text>
</Box>
);
}
Examples#
Skins and shapes#
skin applies a background, border colour and text colour from theme.skins; shape sets the border radius from theme.shapes.
Interactive states#
hover and focus take a skin path. For raw styles per state, use interactive.
Hover or focus this card.
Lifts on hover, ring on keyboard focus.
Responsive layout#
Style props accept arrays or breakpoint objects. This row stacks on narrow screens.
$9/mo
$29/mo
$79/mo
API#
Box#
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | "div" | Element or component to render. |
gap | string | string[] | — | CSS |
skin | string | — | Dot path into |
shape | string | — | Key in |
$size | string | — | Key in |
$shadow | string | — | Key in |
aspect | number | string | — | CSS |
cursor | string | — | CSS |
transform | string | string[] | — | CSS |
placeItems | string | — | CSS |
hover | string | — | Skin path from |
focus | string | — | Skin path from |
interactive | { hover?, focus?, focusWithin?, focusVisible?, active?, disabled?, visited? } | — | Style props per state. camelCase keys become pseudo-classes such as |
disabled | boolean | — | Sets |
Box also accepts these styled-system groups. Values resolve against the theme where a scale exists, otherwise they pass through as raw CSS. All of them accept arrays or breakpoint objects; breakpoint keys are xs, sm, md, lg and xl, with _ as the base.
color—color,bg/backgroundColor,opacity; maps totheme.colorsspace—m,pand their directional variants (mt,px, and so on); maps totheme.spacelayout—width,height,minWidth,maxWidth,size,display,overflow,verticalAlign;sizemaps totheme.sizesflexbox—alignItems,justifyContent,flexDirection,flex,flexWrap,order, and related propsgrid—gridTemplateColumns,gridArea,gridGap, and related propsposition—position,top,right,bottom,left,zIndexbackground—backgroundImage,backgroundSize,backgroundPosition,backgroundRepeatborder—border,borderColor,borderWidth,borderRadius, and directional variantsshadow—boxShadow,textShadow
Other props, such as id, role and event handlers, are passed to the rendered element.
Theme tokens#
Space aliases (theme.space):
mini0.125rem,xxxs0.25rem,xxs0.375rem,xs0.5rem,s0.75rem,m1rem,l1.5rem,xl2rem,xxl2.5rem,xxxl3rem- Long names (
xsmall,small,medium,large,xlarge) match the short ones;xxlargeis 3rem andxxxlargeis 4rem
Size aliases for size (theme.sizes):
xs0.5rem,s0.75rem,m1rem,l1.125rem,xl1.25rem
Shapes (theme.shapes):
square0px,roundedSmall4px,rounded8px,roundedLarge16px,pill32px,circle50%roundedTop,roundedBottom,roundedLeft,roundedRightround one side by 6px
Control sizes for $size (theme.controlSizes):
xxxsmall— height 1.5rem, padding 0.125rem 0.5remxxsmall— height 1.75rem, padding 0.125rem 0.5remxsmall— height 2rem, padding 0.25rem 0.75remsmall— height 2.25rem, padding 0.25rem 0.75remmedium— height 2.5rem, padding 0.5rem 1remlarge— height 3rem, padding 0.5rem 2remxlarge— height 4rem, padding 0.5rem 2.5rem
Shadows for $shadow (theme.shadows):
xxsmall,xsmall,small,medium,large
Skins#
Skins resolve by dot path, so nested entries are available as card.shade or translucent.dark. The default light theme includes:
- Surfaces —
base,surface,panel,card,overlay, each with.shadeand.tint - Signals —
error,success,warning,info,brand,accent,neutral,signal, each with.static,.interactiveand.subtleentries (for exampleerror.static);brandandaccentalso have.light - Colour pairs —
red,orange,yellow,green,teal,blue,purple,pink,gray,primary - States —
highlight,focused,minimal,outlined(with.success) - Special —
transparent,translucent(with.light,.dark,.yellow),gradient,contrast - Hover —
hover.default,hover.subtle,hover.dim,hover.brand,hover.error,hover.info,hover.warning,hover.success,hover.contrast,hover.lighten,hover.accent
The dark theme defines a smaller set. Check src/themes/default/modes/dark/skins.js before relying on a specific key.
Accessibility#
Boxrenders a plaindivwith no role. Passas(for exampleas="section"oras="nav") for semantic elements.focusstyles only show on focusable elements. AddtabIndex={0}to adivthat should receive focus.
Notes#
Boxdoes not apply typography props such asfontSize,fontWeightorlineHeight. UseTextfor those.- Use
size(orwidth/height) for dimensions.$sizeapplies control height and padding. - Most signal skins, such as
error, only define nested entries, so use a leaf path likeerror.staticrather thanerroralone. - Prefer theme aliases (
p="m") over raw values (p="16px").