Skip to content

Box

Box is the base layout component in @suis-ui/kit. It renders a div by default, can render another element through as, and maps SUIS spacing, color, text, border, radius, and size tokens to props.

Usage

tsx
import { Box } from '@suis-ui/kit';

<Box direction="row" align="center" gap="md" p="lg" bg="surface.main" r="md">
  Content
</Box>

The actual primitive structure can be read as a lightweight tree:

text
Box
└── Polymorphic

Native props for the selected element are also supported.

tsx
<Box as="section" aria-labelledby="profile-title" p="lg">
  <h2 id="profile-title">Profile</h2>
</Box>

Props

Element Props

NameTypeDefaultDescription
asValidComponentdivHTML element or Solid component to render.
propsRecord<string, unknown>-Escape hatch props merged last into the inner Polymorphic.

Box is polymorphic, so it also accepts native props for the element selected by as. For example, as="a" allows href and target. Use props only when the typed props do not express the required attribute cleanly.

Layout Props

NameTypeDefaultDescription
posone of: relative, absolute, fixed, sticky-Sets position.
directionone of: row, row-reverse, column, column-reversecolumnFlex direction. Pass null to skip the default.
justifyCSS justify-content preset-Main axis alignment.
alignCSS align-items preset-Cross axis alignment.
wrapone of: nowrap, wrap, wrap-reverse-Flex wrapping.
gapspace token-Flex gap.

justify supports flex-start, flex-end, center, space-between, space-around, and space-evenly. align supports flex-start, flex-end, center, baseline, and stretch. gap accepts a SUIS space token.

Spacing Props

NameTypeDefaultDescription
p, px, py, pt, pb, pl, prspace token-Padding shortcuts.
m, mx, my, mt, mb, ml, mrspace token-Margin shortcuts.

Spacing props accept SUIS space tokens. p and m apply to all sides, while x, y, t, b, l, and r suffixes target axes or individual sides.

Size And Position Props

NameTypeDefaultDescription
w, hstring-Width and height.
minW, minH, maxW, maxHstring-Minimum and maximum width/height.
flexstring, number, boolean-Flex value. true becomes flex: 1.
top, right, bottom, leftstring-Inset values for positioned elements.
zstring, number-z-index.

Size and position props accept CSS length strings rather than token keys. For example, w="min(100%, 720px)" and maxH="50vh" are valid.

Color Props

NameTypeDefaultDescription
ccolor tokeninheritText color. Pass null to skip the default.
bgcolor token-Background color.
bc, blc, brc, btc, bbccolor token-Border color for all sides or individual sides.

Color props accept SUIS color tokens. c sets text color, bg sets background, and the bc family sets border colors.

Border Props

NameTypeDefaultDescription
bd, bdl, bdr, bdt, bdbline-size token-Border width for all sides or individual sides. Border style is solid.

Border width props accept line-size tokens. Directional border colors are set with blc, brc, btc, and bbc.

Radius, Text, And Effect Props

NameTypeDefaultDescription
r, tlr, trr, blr, brrradius token-Border radius for all corners or individual corners.
textfont tokenbodySemantic text style. Pass null to skip the default.
shadowshadow token-Box shadow.
overflowoverflow preset-overflow, overflow-x, or overflow-y preset.

Radius props accept SUIS radius tokens. text applies a full font token, and shadow applies a shadow token. overflow supports auto, hidden, visible, scroll, xAuto, xHidden, xVisible, xScroll, yAuto, yHidden, yVisible, and yScroll.

Box does not have a dedicated component.box token. It directly maps theme token maps to recipe variants.

ts
boxStyle({
  gap: 'md',
  p: 'lg',
  bg: 'surface.main',
  text: 'body',
});

Size and position props that need arbitrary CSS lengths are applied through inline CSS variables.

tsx
<Box w="min(100%, 720px)" maxH="50vh" overflow="yAuto" />

Prefer Box props before adding custom class, classList, or style. Use the props escape hatch only when a needed attribute or component-specific prop is not represented by the typed props.

Examples

Basic Stack

tsx
import { Box, Button } from '@suis-ui/kit';

<Box gap="md" p="lg" bg="surface.main" r="lg" shadow="sm">
  <Box as="h2" text="title" m="none">
    Account
  </Box>
  <Box c="text.caption">
    Manage profile and notification settings.
  </Box>
  <Button variant="primary">Save</Button>
</Box>

Horizontal Layout

tsx
<Box direction="row" align="center" justify="space-between" gap="md">
  <Box>
    <Box text="title">Storage</Box>
    <Box text="caption" c="text.caption">24 GB used</Box>
  </Box>
  <Button variant="secondary" size="sm">
    Upgrade
  </Button>
</Box>

Polymorphic Element

tsx
<Box
  as="a"
  href="/settings"
  direction="row"
  align="center"
  gap="sm"
  p="md"
  r="md"
  bg="surface.high"
>
  Open settings
</Box>

Positioned Element

tsx
<Box pos="relative" p="lg" bg="surface.main" r="lg">
  <Box pos="absolute" top="8px" right="8px" z={1}>
    New
  </Box>
  Card content
</Box>

Escape Hatch

tsx
<Box
  as="div"
  props={{ role: 'presentation', 'data-testid': 'layout-shell' }}
/>