Box
Generic token-backed layout and surface primitive.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import the component from its dedicated entry point to keep the dependency and generated bundle explicit.
tsximport { Box } from "@tavojs/ui/box";Normal Tavo.js applications load component styles through the Tavo.js UI plugin. If the application manages component CSS manually, also import @tavojs/ui/css/box.
When to use
Use it when
Choose something else when
Examples
Box example
tsximport { Box } from "@tavojs/ui/box";
export function BoxExample1() {
return (
<>
<Box surface="raised" padding="lg" radius="lg" border>
Content
</Box>
<Box as="main" maxWidth="lg" paddingInline="lg" center fullWidth>
Page content
</Box>
</>
);
}Common props and defaults
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
as | string | Component<Record<string, unknown>> | — | Changes the rendered root element or component while preserving Tavo.js UI styling and public props. |
surface | "default" | "raised" | "subtle" | "primary" | "secondary" | "neutral" | — | Configures surface for this component. |
padding | "none" | "sm" | "md" | "lg" | — | Configures padding for this component. |
paddingInline | "none" | "sm" | "md" | "lg" | — | Configures paddingInline for this component. |
maxWidth | "sm" | "md" | "lg" | "xl" | "full" | — | Configures maxWidth for this component. |
center | boolean | — | Configures center for this component. |
fullWidth | boolean | — | Configures fullWidth for this component. |
radius | "none" | "sm" | "md" | "lg" | — | Configures radius for this component. |
shadow | boolean | — | Configures shadow for this component. |
Complete TypeScript API
Import from @tavojs/ui/box. Published exports: Box, BoxProps.
BoxProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by Box. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by Box. |
id | string | No | Inherited id attribute accepted by Box. |
role | string | No | Inherited role attribute accepted by Box. |
style | Record<string, unknown> | No | Inherited style attribute accepted by Box. |
title | string | No | Inherited title attribute accepted by Box. |
tabIndex | number | No | Inherited tabIndex attribute accepted by Box. |
hidden | boolean | No | Inherited hidden attribute accepted by Box. |
disabled | boolean | No | Inherited disabled attribute accepted by Box. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by Box. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by Box. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by Box. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by Box. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by Box. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by Box. |
as | PolymorphicAs | No | Changes the rendered root element or component while preserving Tavo.js UI styling and public props. |
surface | "none" | "default" | "raised" | "subtle" | "neutral" | "primary" | "secondary" | No | Configures surface for this component. |
padding | ResponsiveValue<"none" | Spacing> | No | Configures padding for this component. |
paddingInline | ResponsiveValue<"none" | Spacing> | No | Configures paddingInline for this component. |
maxWidth | ResponsiveValue<"sm" | "md" | "lg" | "xl" | "full"> | No | Configures maxWidth for this component. |
center | boolean | No | Configures center for this component. |
fullWidth | boolean | No | Configures fullWidth for this component. |
radius | ResponsiveValue<"sm" | "md" | "lg" | "none" | "surface"> | No | Configures radius for this component. |
border | boolean | "strong" | No | Inherited border attribute accepted by Box. |
shadow | boolean | No | Configures shadow for this component. |
minHeight | string | No | Inherited minHeight attribute accepted by Box. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | No component state contract is exposed; the application owns the rendered content and surrounding behavior. |
| DOM target | The public root follows the as/component prop. Root attributes, className, style, and supported events are forwarded there. |
Anatomy and related components
Limitations
Avoid Box when for interactive form state; combine with form, feedback, or data components instead.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Layout primitives are semantic-neutral unless a component prop selects an element role.
Choose semantic elements such as main, nav, aside, or section when the region has document meaning.
Keep heading order and landmark labels app-owned.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | layout |
| Component import | @tavojs/ui/box |
| Explicit CSS import | @tavojs/ui/css/box |
| Preview | Interactive preview available on this page |