Skip to content

Box

const Box: ForwardRefExoticComponent<BoxProps & RefAttributes<GlyphNode>>;

Generic layout container — the building block of every Glyph UI.

Box maps directly to a Yoga flexbox node, so all CSS-like flex properties (flexDirection, gap, padding, alignItems, …) work out of the box.

<Box style={{ flexDirection: "row", gap: 1, padding: 1 }}>
<Text>Hello</Text>
<Text>World</Text>
</Box>
// Centered card with a border
<Box
style={{
border: "round",
borderColor: "cyan",
padding: 1,
alignItems: "center",
justifyContent: "center",
width: 40,
height: 10,
}}
>
<Text style={{ bold: true }}>Welcome!</Text>
</Box>

PropertyTypeDescription
children?ReactNodeChild elements to render inside the box.
focusable?booleanWhen true, the box participates in the focus (Tab) order.
onClick?MouseEventHandlerCalled on mouse click (mouseup).
onMouseDown?MouseEventHandlerCalled on mouse button press.
onMouseEnter?MouseEventHandlerCalled when the mouse cursor enters the box.
onMouseLeave?MouseEventHandlerCalled when the mouse cursor leaves the box.
onMouseMove?MouseEventHandlerCalled on mouse movement over the box.
onMouseUp?MouseEventHandlerCalled on mouse button release.
onWheel?MouseEventHandlerCalled on mouse wheel scroll.
style?StyleFlexbox style object controlling layout, colors, borders, and more.