# Box

A minimal polymorphic structural wrapper.

`Box` is the lowest-level Zenos layout primitive. It gives a semantic element a stable slot and optional elevation while leaving spacing, sizing, borders, and display behavior to the consumer.

```tsx
import { PulseIcon } from "@phosphor-icons/react";
import { Badge, Box, Stack, Text } from "@zentara-co/zenos-ui";

function BoxExample() {
  return (
    <Box
      as="section"
      aria-labelledby="workspace-summary"
      elevation="container"
      className="w-full max-w-2xl rounded-2xl p-5 sm:p-6"
    >
      <div className="flex flex-col gap-5">
        <div className="flex flex-wrap items-start justify-between gap-4">
          <div className="flex items-center gap-3">
            <span className="grid size-10 place-items-center rounded-full bg-background-accent-purple-subtlest-default text-text-accent-purple-bolder">
              <PulseIcon aria-hidden="true" className="size-5" />
            </span>
            <Stack gap="1">
              <Text id="workspace-summary" type="heading" size="h5">
                Workspace summary
              </Text>
              <Text size="s" color="subtle">
                Activity across all environments
              </Text>
            </Stack>
          </div>
          <Badge variant="default" color="success">
            Healthy
          </Badge>
        </div>

        <div className="grid grid-cols-1 gap-4 border-t border-border-default pt-5 sm:grid-cols-3">
          {[
            ["Projects", "18"],
            ["Contributors", "42"],
            ["Deployments", "126"],
          ].map(([label, value]) => (
            <Stack key={label} gap="1">
              <Text size="s" color="subtle">
                {label}
              </Text>
              <Text type="heading" size="h4">
                {value}
              </Text>
            </Stack>
          ))}
        </div>
      </div>
    </Box>
  );
}
```

## Import

```tsx
import { Box } from "@zentara-co/zenos-ui";
```

## Elevation

Elevation describes the surface's relationship to surrounding content. It applies semantic surface tokens and, where appropriate, shadows and interaction states.

```tsx
import { Box, Grid, Stack, Text } from "@zentara-co/zenos-ui";

function BoxElevationExample() {
  const elevations = [
    { value: "sunken", level: "−1", description: "Recessed regions" },
    { value: "surface", level: "0", description: "Page surface" },
    { value: "container", level: "+1", description: "Grouped content" },
    { value: "raised", level: "+2", description: "Floating controls" },
    { value: "overlay", level: "+3", description: "Temporary layers" },
  ] as const;

  return (
    <Grid columns={{ base: 1, sm: 2, lg: 5 }} gap="3" className="w-full">
      {elevations.map(({ value, level, description }) => (
        <Box
          key={value}
          elevation={value}
          className="flex min-h-36 flex-col justify-between rounded-xl p-4"
        >
          <Text
            size="s"
            color="subtle"
            className={value === "surface" ? "dark:text-text-contrary/70" : undefined}
          >
            Level {level}
          </Text>
          <Stack gap="1">
            <Text
              type="heading"
              size="h6"
              className={value === "surface" ? "capitalize dark:text-text-contrary" : "capitalize"}
            >
              {value}
            </Text>
            <Text
              size="s"
              color="subtle"
              className={value === "surface" ? "dark:text-text-contrary/70" : undefined}
            >
              {description}
            </Text>
          </Stack>
        </Box>
      ))}
    </Grid>
  );
}
```

Use the levels consistently:

- `sunken` for recessed wells and inset regions
- `surface` for the standard content plane
- `container` for grouped content on a surface
- `raised` for elements lifted above nearby content
- `overlay` for the highest temporary surfaces

Elevation adds visual hierarchy; it does not add layout, dialog behavior, or stacking context.

## Polymorphism

Use `as` to choose the correct semantic element. Native attributes and the forwarded ref follow that element, so an anchor accepts `href`, an article retains article semantics, and a section can use `aria-labelledby`.

```tsx
import { ArrowRightIcon, ShieldPlusIcon } from "@phosphor-icons/react";
import { Badge, Box, Grid, Stack, Text } from "@zentara-co/zenos-ui";

function BoxPolymorphicExample() {
  return (
    <Grid columns={{ base: 1, md: 2 }} gap="4" className="w-full max-w-3xl">
      <Box as="article" elevation="container" className="rounded-xl p-5">
        <Stack gap="4">
          <div className="flex items-center justify-between gap-3">
            <span className="grid size-9 place-items-center rounded-full bg-background-accent-orange-subtlest-default text-text-accent-orange-bolder">
              <ShieldPlusIcon aria-hidden="true" className="size-5" />
            </span>
            <Badge variant="outline" color="warning">
              Review
            </Badge>
          </div>
          <Stack gap="1">
            <Text type="heading" size="h6">
              Incident report
            </Text>
            <Text size="s" color="subtle">
              Rendered as a semantic article with its own heading.
            </Text>
          </Stack>
        </Stack>
      </Box>
      <Box
        as="a"
        href="#box-api"
        elevation="raised"
        className="group flex min-h-36 flex-col justify-between rounded-xl p-5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
      >
        <ArrowRightIcon
          aria-hidden="true"
          className="size-5 self-end text-icon-subtle transition-transform group-hover:translate-x-1 rtl:rotate-180 rtl:group-hover:-translate-x-1 motion-reduce:transition-none"
        />
        <Stack gap="1">
          <Text type="heading" size="h6">
            Read the Box API
          </Text>
          <Text size="s" color="subtle">
            A native link with href and visible focus behavior.
          </Text>
        </Stack>
      </Box>
    </Grid>
  );
}
```

## Responsibility

Use Box when semantic wrapping, elevation, or a stable customization hook is enough. Use Stack, Grid, Center, Container, or Section when the structure has a repeated layout rule. One-off application styling belongs in `className`:

```tsx
<Box as="aside" className="rounded-xl border border-border p-4">
  ...
</Box>
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | div | Rendered semantic element and source of native prop and ref types. |
| elevation | sunken \| surface \| container \| raised \| overlay | — | Optional semantic surface level, including interaction states and shadows. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Box adds no role or interaction behavior. Choose `as` for the content's meaning and preserve native semantics. If styling Box as an interactive surface, render an actual link or button rather than adding click behavior to a `div`, and keep a visible focus indicator.

Source: https://zenos-ui.pages.dev/layout/box/