# Container Components
Components for grouping and organizing content in OpenTUI.
## Box Component
The primary container component with borders, backgrounds, and layout capabilities.
### Basic Usage
```tsx
// React/Solid
Content inside box
// Core
const box = new BoxRenderable(renderer, {
id: "container",
})
box.add(child)
```
### Borders
```tsx
Simple border
Styled border
// Individual borders
Top and bottom only
```
**Border Styles:**
| Style | Appearance |
|-------|------------|
| `single` | `┌─┐│ │└─┘` |
| `double` | `╔═╗║ ║╚═╝` |
| `rounded` | `╭─╮│ │╰─╯` |
| `bold` | `┏━┓┃ ┃┗━┛` |
### Title
```tsx
Panel content
```
### Background
```tsx
Dark background
No background
```
### Layout
Boxes are flex containers by default:
```tsx
Item 1
Item 2
```
### Spacing
```tsx
Spaced content
```
### Dimensions
```tsx
Sized box
```
### Mouse Events
```tsx
{
console.log("Clicked at:", event.x, event.y)
}}
onMouseUp={(event) => {}}
onMouseMove={(event) => {}}
>
Clickable box
```
## ScrollBox Component
A scrollable container for content that exceeds the viewport.
### Basic Usage
```tsx
// React
{items.map((item, i) => (
{item}
))}
// Solid
{(item) => {item}}
// Core
const scrollbox = new ScrollBoxRenderable(renderer, {
id: "list",
height: 10,
})
items.forEach(item => {
scrollbox.add(new TextRenderable(renderer, { content: item }))
})
```
### Focus for Keyboard Scrolling
```tsx
{/* Use arrow keys to scroll */}
```
### Scrollbar Styling
```tsx
// React
{content}
```
### Scroll Position (Core)
```typescript
const scrollbox = new ScrollBoxRenderable(renderer, {
id: "list",
height: 20,
})
// Scroll programmatically
scrollbox.scrollTo(0) // Scroll to top
scrollbox.scrollTo(100) // Scroll to position
scrollbox.scrollBy(10) // Scroll relative
scrollbox.scrollToBottom() // Scroll to end
```
## Composition Patterns
### Card Component
```tsx
function Card({ title, children }) {
return (
{title && (
{title}
)}
{children}
)
}
```
### Panel Component
```tsx
function Panel({ title, children, width = 40 }) {
return (
{title && (
{title}
)}
{children}
)
}
```
### List Container
```tsx
function List({ items, renderItem }) {
return (
{items.map((item, i) => (
{renderItem(item, i)}
))}
)
}
```
## Nesting Containers
```tsx
{/* Header */}
Header
{/* Main area with sidebar */}
Sidebar
{/* Scrollable content */}
{/* Footer */}
Footer
```
## Gotchas
### Percentage Dimensions Need Parent Size
```tsx
// WRONG - parent has no explicit size
Won't work
// CORRECT
Works
```
### FlexGrow Needs Sized Parent
```tsx
// WRONG
Won't grow
// CORRECT
Will grow
```
### ScrollBox Needs Height
```tsx
// WRONG - no height constraint
{items}
// CORRECT
{items}
```
### Borders Add to Size
Borders take up space inside the box:
```tsx
{/* Inner content area is 8 chars (10 - 2 for borders) */}
```