pub fn Box(props: BoxProps) -> impl IntoViewExpand description
Generic layout wrapper for spacing, sizing, and surface styling on a single node.
Box is a theme-aware container for one element—like a <div> with optional token-based padding, margin, width, and extra CSS. Use it when a single wrapper needs spacing or sizing without distributing gaps between siblings. foreground sets theme text color — not the CSS color shorthand prop. For even gaps between children, prefer Stack or Flex.
§When to use
- One wrapper needs padding, margin, max-width, or surface styling - A card-like region without the full
MaterialAPI - Custom layout chrome whereStack/Flexare too opinionated
§Usage
- Put content in the default slot. 2. Set typed
padding,margin,background,radius, and related token props. 3. Pass additional rules throughstylewhen you need escape-hatch CSS. 4. Add utility classes throughclasswhen needed.
§Best Practices
§Do’s
- Use
SpacingInsetforpadding/margin* UseThemeColor,BorderRadius, andShadowfor surface styling * PairBoxwith typography presets (Body1) for readable demo and app copy
§Don’ts
- Do not use
Boxto space multiple siblings — preferStackorFlex* Avoid hard-coded hex colors; useThemeColortokens
§Examples
§Default
A bordered box with sample text—the quickest way to see the container bounds.
use crate::Box;
use orbital_base_components::{BorderRadius, SpacingInset, StrokeWidth, ThemeColor};
view! {
<div data-testid="box-preview">
<Box
padding=SpacingInset::all_m()
background=ThemeColor::NeutralBackground1
foreground=ThemeColor::NeutralForeground1
border_color=ThemeColor::NeutralStroke1
radius=BorderRadius::Medium
border_style="dashed"
border_width=StrokeWidth::Thin
>
"This Box wraps content with theme-aware spacing and stroke tokens."
</Box>
</div>
}§Padding
The padding prop adds inner space without extra wrapper markup.
use crate::Box;
use orbital_base_components::{BorderRadius, SpacingInset, StrokeWidth, ThemeColor};
view! {
<div data-testid="box-padding">
<Box
padding=SpacingInset::all_l()
foreground=ThemeColor::NeutralForeground1
border_color=ThemeColor::NeutralStroke1
radius=BorderRadius::Medium
border_style="dashed"
border_width=StrokeWidth::Thin
>
"Extra padding keeps content away from the dashed border."
</Box>
</div>
}§Margin
The margin prop offsets the box from surrounding layout—visible against a tinted backdrop.
use crate::Box;
use orbital_base_components::{BorderRadius, SpacingInset, StrokeWidth, ThemeColor};
view! {
<div data-testid="box-margin" style="padding: var(--orb-space-inline-sm); background: var(--orb-color-surface-subtle); border-radius: var(--orb-radius-md);">
<Box
margin=SpacingInset::all_l()
padding=SpacingInset::all_m()
foreground=ThemeColor::NeutralForeground1
border_color=ThemeColor::NeutralStroke1
radius=BorderRadius::Medium
border_style="dashed"
border_width=StrokeWidth::Thin
>
"Margin pushes this box away from the outer frame."
</Box>
</div>
}§Width
Constrain width on forms, side panels, and compact callouts.
use crate::Box;
use orbital_base_components::{BorderRadius, SpacingInset, StrokeWidth, ThemeColor};
view! {
<div data-testid="box-width">
<Box
width="280px"
padding=SpacingInset::all_m()
foreground=ThemeColor::NeutralForeground1
border_color=ThemeColor::NeutralStroke1
radius=BorderRadius::Medium
border_style="dashed"
border_width=StrokeWidth::Thin
>
"A fixed width keeps this callout readable in wide layouts."
</Box>
</div>
}§Surface styling
Combine typed surface props for a subtle raised panel.
use crate::Box;
use orbital_base_components::{BorderRadius, Shadow, SpacingInset, StrokeWidth, ThemeColor};
view! {
<div data-testid="box-surface">
<Box
padding=SpacingInset::all_l()
background=ThemeColor::NeutralBackground1
foreground=ThemeColor::NeutralForeground1
border_color=ThemeColor::NeutralStroke1
radius=BorderRadius::Medium
border_width=StrokeWidth::Thin
shadow=Shadow::Shadow4
>
"Surface tokens give the box a resting elevation on the page canvas."
</Box>
</div>
}§Optional Props
- class:
impl Into<MaybeProp<String>>- Extra CSS class names merged onto the root element.
- style:
impl Into<MaybeProp<String>>- Additional inline CSS declarations merged after typed token props.
- padding:
impl Into<MaybeProp<SpacingInset>>- Theme-aware padding using Orbital spacing tokens.
- margin:
impl Into<MaybeProp<SpacingInset>>- Theme-aware margin using Orbital spacing tokens.
- width:
impl Into<MaybeProp<String>>- CSS width value (for example
280px,100%, ormin(100%, 480px)).
- CSS width value (for example
- background:
impl Into<MaybeProp<ThemeColor>>- Background fill from the active theme palette.
- foreground:
impl Into<MaybeProp<ThemeColor>>- Text color from the active theme palette.
- border_color:
impl Into<MaybeProp<ThemeColor>>- Border color from the active theme palette.
- radius:
impl Into<MaybeProp<BorderRadius>>- Border radius token.
- border_width:
impl Into<MaybeProp<StrokeWidth>>- Border width token (defaults to thin when
border_coloris set).
- Border width token (defaults to thin when
- border_style:
impl Into<MaybeProp<String>>- Border style (for example
solidordashed).
- Border style (for example
- shadow:
impl Into<MaybeProp<Shadow>>- Elevation shadow token.
- children:
Children