Stack
Stack is a primitive component based on flexbox that manages the vertical layout of direct children.
Usage
Stack arranges children vertically with consistent spacing.
import { Stack } from '@hardwater/teardrop';
<Stack gap="medium">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</Stack>
Gap
Control spacing between children:
<Stack gap="small">Tight spacing</Stack>
<Stack gap="medium">Default spacing</Stack>
<Stack gap="large">Comfortable spacing</Stack>
Alignment
Align Items
<Stack align="stretch">Stretch (default)</Stack>
<Stack align="start">Align start</Stack>
<Stack align="center">Align center</Stack>
<Stack align="end">Align end</Stack>
Justify Content
<Stack justify="start">Justify start (default)</Stack>
<Stack justify="center">Justify center</Stack>
<Stack justify="end">Justify end</Stack>
<Stack justify="space-between">Space between</Stack>
Direction
<Stack direction="column">Column (default)</Stack>
<Stack direction="row">Row (horizontal)</Stack>
Wrapping
<Stack wrap>Wrap children</Stack>
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
gap | SpacingToken | - | Spacing between children |
align | 'stretch' | 'start' | 'center' | 'end' | 'stretch' | Align items |
justify | 'start' | 'center' | 'end' | 'space-between' | 'start' | Justify content |
direction | 'column' | 'row' | 'column' | Flex direction |
wrap | boolean | false | Wrap children |
as | string | Component | 'div' | Element or component to render as |
Examples
Form Layout
<Stack gap="large">
<Input label="Email" />
<Input label="Password" type="password" />
<Button variant="primary">Sign in</Button>
</Stack>
Card Content
<Stack gap="small">
<Heading level={2}>Card Title</Heading>
<Text>Card description</Text>
<Button>Action</Button>
</Stack>
Centered Content
<Stack gap="medium" align="center" justify="center" minHeight={400}>
<Heading>Centered Content</Heading>
<Text>This content is centered</Text>
</Stack>
Responsive Stack
<Stack
direction={{ mobile: 'column', desktop: 'row' }}
gap={{ mobile: 'small', desktop: 'medium' }}
>
<Box>Item 1</Box>
<Box>Item 2</Box>
</Stack>
Best Practices
- Consistent gaps - Use the same gap value for similar relationships
- Semantic HTML - Use
asprop for semantic elements (<section>,<nav>, etc.) - Composition - Combine with Box for padding and backgrounds
- Responsive - Adjust direction and gap for different screen sizes
Related
- Box - Container component
- Inline - Horizontal layout
- Spacing Tokens