Skip to content

Box

A bordered container with an optional title and child component.

Constructor

ts
new Box(title: string | null, child: Component | null, options?: BoxOptions)
ParamTypeDefaultDescription
titlestring | nullTitle shown in the top border. null for no title
childComponent | nullChild component rendered inside the box
optionsBoxOptions{}Additional options

BoxOptions

PropertyTypeDefaultDescription
charsBoxCharSetBoxChars.singleBorder character set
paddingnumber1Inner padding (characters)

Methods

render()

ts
render(width: number, height: number): CharGrid

Renders the box border and child. The child receives (width - 2 - padding*2, height - 2 - padding*2).

setTitle()

ts
setTitle(title: string | null): void

setChild()

ts
setChild(child: Component | null): void

Examples

ts
// basic box
new Box('Status', new Text('All systems go'))

// no title
new Box(null, new Text('Untitled content'))

// double border
new Box('Alert', child, { chars: BoxChars.double })

// extra padding
new Box('Spacious', child, { padding: 3 })