Stack
Flex layout as props, on a closed spacing scale.
Installation
Needs the arene setup first.
Install the packages it imports:
Set up the token layer, if you have not already. Stack reads the space
scale through the shared lib/spacing.ts helper. Copy that helper too. See Installation.
Paste the shared spacing helper and the component into your project.
Change the @/ imports if your project uses different aliases.
Usage
Use Stack when the styling is only the layout. Give an element with its own
background, border or type a stylex.create() block, and put its layout there.
Direction
Stack runs vertically. HStack and VStack fix direction. Pass
direction yourself only when the value is computed.
Alignment
Use justify and align for justify-content and align-items, without the
flex- prefixes.
Spacing
Every spacing prop takes a step off the scale. Each step is 0.25rem times its
number, so gap={3} is 0.75rem. An off-scale value is a type error.
Padding props resolve most-specific-first, per edge. An edge prop beats its axis
prop, which beats padding.
Sizing
width, height, maxWidth and minHeight take a number, read as pixels, or
a CSS length string. Stack writes them to the element's inline style.
Scrolling
Set scrollable on a flex child that has to scroll. It sets overflow: auto
and the min-height: 0 the child needs, or its automatic minimum size holds it
at content height and the scrollbar never appears. Pair it with grow.
Composition
Use render to choose a semantic element.
Project
API reference
Pass render to replace a part's element or compose it with another component.
Stack
| Prop | Type | Default |
|---|---|---|
direction | "horizontal" | "vertical" | "vertical" |
justify | "start" | "center" | "end" | "between" | "around" | "evenly" | — |
align | "start" | "center" | "end" | "stretch" | "baseline" | — |
gap | SpacingStep | — |
padding | SpacingStep | — |
paddingInline | SpacingStep | — |
paddingInlineStart | SpacingStep | — |
paddingInlineEnd | SpacingStep | — |
paddingBlock | SpacingStep | — |
paddingBlockStart | SpacingStep | — |
paddingBlockEnd | SpacingStep | — |
wrap | "nowrap" | "wrap" | "wrap-reverse" | — |
grow | boolean | false |
scrollable | boolean | false |
width | string | number | — |
height | string | number | — |
maxWidth | string | number | — |
minHeight | string | number | — |
xstyle | StyleXStyles | — |
style | CSSProperties | — |
className | string | — |
Pass element-specific props on the render element, such as render={<Link to="/" />}.
Use a type argument such as VStack<"fieldset"> when passing a fieldset ref.
HStack, VStack
Stack with direction fixed. They take every other Stack prop.
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="stack" | root | Targets the layout |
data-orientation | root | Mirrors direction |