# Box

Crate: `libero`
Import: `use libero::components::Box;`
Feature: `box` (on by default, turns on `use-element`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/layout/box.rs>
Index: [index.md](index.md) lists every other page
Description: The primitive every other component is built on, rendered as any tag via `component` and styled through `sx`.

The primitive every other component is built on. `component` picks the tag, and
attributes like `href` or `src` pass through to it. `Box` has no look of its
own. Everything visible comes from `sx` and `states`, see
[styling.md](styling.md). A `button` keeps the browser's own border, font,
padding and centring: reset them in `sx`, or use `Paper`, which does.
`hidden_from` and `visible_from`, on every component, hide it from a
breakpoint's width up or below it: set `hidden_from` to md and the box leaves a
desktop window.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::Box;
use libero::sx::sx;

#[component]
fn Demo() -> Element {
    rsx! {
        Box {
            sx: sx().padding("16px").background("muted.1").border_radius("md"),
            hidden_from: "xl",
            "Styled entirely via sx"
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `variables` | `Variables` | - | Custom properties set on the element's `style`, so `sx` can use a changing value without a new class per value. |
| `component` | `HtmlTag` | `div` | The element to render, any of the 111 HTML5 element names. The 28 outside the default set (document metadata, embedded and media content, `template`, `slot`, bidi and ruby) need the `full-polymorphism` feature and render as a `div` without it. |
| `style` | `String` | - | Raw `style` declarations, applied after `variables`. |
| `alt` | `String` | - | The `img` alt text. |
| `r#type` | `String` | - | The `button` type, such as `"submit"`. |
| `children` | `Element` | required | The element's content. |

Like every component, `Box` also takes the shared props `sx`, `class`, `style`,
`states`, `hidden_from`, `visible_from`, and any extra HTML attributes. It also takes the `img`, `a` and
`button` attributes, such as `src`, `href` and `target`.

## Accessibility

### Libero handles

- `Box` adds no roles, so the semantics are whatever tag `component` names.

### You must

- Use `component: "button"` for something clickable: a clickable `div` has no
  keyboard support.
- Set `r#type: "button"` on a `button` inside a form, or it submits the form.
- Give an `img` an `alt`, empty for a decorative one.
- Mark a `target: "_blank"` link as opening a new tab, or use `Anchor`, which
  does.
- Set `disabled`, `aria-disabled` and `aria-selected` yourself, or use the
  component that owns the state: the `disabled` and `selected` states only
  style the box.

### Example

A clickable tile with a short text label,
`Box { component: "button", r#type: "button", "Archive" }`: Tab reaches it and
Enter or Space press it, which a clickable `div` would not allow. A `button`
takes phrasing content only and its name is everything inside it, so keep a
card with a heading, paragraphs or other controls out of one.

## Theme defaults

None. The theme reaches a `Box` only through the values its `sx` names.

## CSS variables

None of its own. `variables` sets your own custom properties on the element.

## Data attributes

Only what you pass. The `states` prop renders as `data-state`, which `Sx::when`
matches. `Box` adds no state tokens itself.
