Stack

Places its children in a column or a row with even space between them.

Usage

Code
import { HStack, Stack, VStack } from '@leverui/components';
Code
<Stack>
  <div />
  <div />
</Stack>

Examples

Horizontal

Use the direction prop to change the direction of the stack.

HStack

Alternatively, you can use the HStack to create a horizontal stack and align its children horizontally.

VStack

Use the VStack to create a vertical stack and align its children vertically.

Separator

Use the separator prop to add a separator between the stack items.

Responsive Direction

Use the direction prop to change the direction of the stack responsively.

Props

PropDefaultTypeDescription
directioncolumnrow, column, or reversedWhich way the children flow.
gap2Spacing token or CSS lengthSpace between children. 2 is 8px.
align—CSS align-items valueAlignment across the direction.
justify—CSS justify-content valueAlignment along the direction.
wrap—CSS flex-wrap valueWhether children wrap onto new lines.
separator—functionRenders a divider between each pair of children.
renderChildren—functionReturns the children, for lists that change.
asdivNative HTML tagHTML tag to render.
asChild—Solid render callbackRender your own element in place of the default.
unstyledfalsebooleanTurns off the default layout rules.

Responsive: direction, gap, align, justify, and wrap.

HStack is a row with its items centered vertically. VStack is a column with its items centered horizontally. Both take the same props and ignore direction.

Separator function

separator receives { class } and returns the divider. Put that class on the element you return. StackSeparator is the ready-made divider.

Code
<Stack separator={(props) => <StackSeparator {...props} />}>
  <div />
  <div />
</Stack>

StackSeparator is an empty div, so screen readers skip it.

Dynamic lists

When a signal adds or removes children, pass them through renderChildren so the dividers follow.

Code
<Stack
  separator={(props) => <StackSeparator {...props} />}
  renderChildren={() => <For each={items()}>{(item) => <Row item={item} />}</For>}
/>

Customize with CSS

Classes: .leverui-stack on the root, .leverui-stack-separator on the separator. Style them in CSS loaded after the Lever UI stylesheet, or add your own class or style. unstyled turns off the default layout rules but keeps the root class and the HTML semantics.

Code
.article-actions .leverui-stack-separator {
  border-color: currentColor;
}