Stack
A layout component for stacking elements vertically or horizontally with consistent spacing.
import { Stack } from "@ninna-ui/layout"pnpm add @ninna-ui/layoutRequires @ninna-ui/core (auto-installed) + CSS setup.
Usage
Import and use the Stack component in your application.
import { Stack, HStack, VStack } from "@ninna-ui/layout";
export default function Example() { return ( <Stack gap="4"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </Stack> );}Basic
Basic stack layout with default column direction.
Direction
Stack supports row and column directions. Use HStack and VStack as shortcuts.
Column (default)
Row
HStack (shorthand for row)
VStack (shorthand for column)
Gap Spacing
Control the spacing between items with the gap prop.
gap="0"
gap="1"
gap="2"
gap="4"
gap="6"
gap="8"
Alignment
Align items on the cross axis using the align prop.
align="start"
align="center"
align="end"
align="stretch"
align="baseline"
Justify
Distribute items along the main axis using the justify prop.
justify="start"
justify="center"
justify="end"
justify="between"
justify="around"
justify="evenly"
With Divider
Stack items separated by dividers.
Responsive
Combine with responsive classes for adaptive layouts.
Stack can be combined with responsive classes for adaptive layouts
Use Cases
Common patterns using Stack for layouts.
API Reference
Complete list of props for the Stack component.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
direction | 'row' | 'column' | 'row-reverse' | 'column-reverse' | 'column' | Direction of the stack layout |
gap | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '8' | '10' | '12' | '16' | '4' | Gap between items |
align | 'start' | 'center' | 'end' | 'stretch' | 'baseline' | - | Align items on cross axis |
justify | 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly' | - | Justify items on main axis |
wrap | boolean | false | Whether items should wrap |
className | string | - | Additional CSS classes |
children* | React.ReactNode | - | Stack content |
Accessibility
- Stack is a pure layout component with no semantic meaning
- Use appropriate semantic HTML elements as children
- For navigation, wrap in a nav element
- For lists, consider using List component instead