# Stack

## Usage

Import the component from its dedicated entry. The component loads its structural styles.

Import the theme in your application entry:

```ts
import '@astryx-vue/themes/neutral.css'
```

Component usage:

```vue
<script setup lang="ts">
import { HStack, Stack, StackItem, VStack } from '@astryx-vue/core/Stack'
</script>
```

### Anatomy

- **Stack container**: Layout container that arranges content along one flex axis.
- **Item**: Optional StackItem wrapper that controls one item in the stack.
- **Content**: Caller-supplied content rendered by a Stack or StackItem.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Use the gap prop for spacing between items; don't add margins manually. |
| Do | Use StackItem with size="fill" to make one item stretch and fill the leftover space. |
| Don't | Nest stacks inside stacks; try wrap="wrap" first to let items flow to the next line. |

## Examples

### Alignment

Buttons sit at the start, the center, and the end of a row.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Card } from '@astryx-vue/core/Card'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'

const rows = [
  { label: 'Start (left)', align: 'start' },
  { label: 'Center', align: 'center' },
  { label: 'End (right)', align: 'end' },
] as const
</script>

<template>
  <VStack :gap="3" width="100%" style="max-width: 500px">
    <Card v-for="row in rows" :key="row.label" :padding="4">
      <VStack :gap="4">
        <Text color="secondary" type="supporting">
          {{ row.label }}
        </Text>
        <HStack :gap="1" :h-align="row.align">
          <Button label="Cancel" size="sm" variant="secondary" />
          <Button label="Save" size="sm" variant="primary" />
        </HStack>
      </VStack>
    </Card>
  </VStack>
</template>
```

### Fill item

An avatar, a name, and a button share a row. The name stretches to fill the space between them.

```vue
<script setup lang="ts">
import { Avatar } from '@astryx-vue/core/Avatar'
import { Button } from '@astryx-vue/core/Button'
import { HStack, StackItem, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'

const users = [
  { name: 'Olivia Chen', role: 'Engineering Lead' },
  { name: 'Marcus Rivera', role: 'Product Designer' },
  { name: 'Aisha Patel', role: 'Marketing Manager' },
]
</script>

<template>
  <VStack :gap="3" width="100%" style="max-width: 300px">
    <HStack v-for="user in users" :key="user.name" align="center" :gap="3">
      <StackItem size="static">
        <Avatar :name="user.name" size="md" />
      </StackItem>
      <StackItem size="fill">
        <VStack :gap="0">
          <Text type="body" weight="bold">
            {{ user.name }}
          </Text>
          <Text color="secondary" type="supporting">
            {{ user.role }}
          </Text>
        </VStack>
      </StackItem>
      <StackItem size="static">
        <Button label="View" size="sm" variant="secondary" />
      </StackItem>
    </HStack>
  </VStack>
</template>
```

## Stack Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `direction` | `'horizontal' \| 'vertical'` | `'vertical'` | Direction in which children are arranged. |
| `gap` | `SpacingStep` | — | Space between adjacent children. |
| `padding` | `SpacingStep` | — | Padding on every side of the container. |
| `paddingInline` | `SpacingStep` | — | Inline-axis padding. Overrides padding on this axis. |
| `paddingBlock` | `SpacingStep` | — | Block-axis padding. Overrides padding on this axis. |
| `paddingBlockStart` | `SpacingStep` | — | Block-start (top) padding. Overrides `paddingBlock` and `padding` on that edge only. |
| `paddingBlockEnd` | `SpacingStep` | — | Block-end (bottom) padding. Overrides `paddingBlock` and `padding` on that edge only. |
| `paddingInlineStart` | `SpacingStep` | — | Inline-start (left in LTR) padding. Overrides `paddingInline` and `padding` on that edge only. |
| `paddingInlineEnd` | `SpacingStep` | — | Inline-end (right in LTR) padding. Overrides `paddingInline` and `padding` on that edge only. |
| `hAlign` | `StackAlignment` | — | Controls horizontal main- or cross-axis alignment according to direction. |
| `vAlign` | `StackAlignment` | — | Controls vertical main- or cross-axis alignment according to direction. |
| `justify` | `StackMainAlignment` | — | Alias for main-axis alignment. |
| `align` | `StackCrossAlignment` | — | Alias for cross-axis alignment. |
| `wrap` | `'nowrap' \| 'wrap' \| 'wrap-reverse'` | `'nowrap'` | Controls how children wrap. |
| `width` | `number \| string` | — | Container width. Numbers are interpreted as pixels. |
| `height` | `number \| string` | — | Container height. Numbers are interpreted as pixels. |
| `maxWidth` | `number \| string` | — | Maximum container width. |
| `minHeight` | `number \| string` | — | Minimum container height. |
| `isScrollable` | `boolean` | `false` | Enables automatic overflow scrolling. |
| `as` | `string \| Component` | `'div'` | Root element or Vue component. |

`SpacingStep` accepts these values:

```ts
type SpacingStep = 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10
```

## HStack Props

`HStack` uses a fixed horizontal direction.

- The component supports shared `Stack` props.
- The component does not expose `direction`.
- The table below defines alignment.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `hAlign` | `StackMainAlignment` | — | Horizontal main-axis alignment. |
| `vAlign` | `StackCrossAlignment` | `'stretch'` | Vertical cross-axis alignment. |

## VStack Props

`VStack` uses a fixed vertical direction.

- The component supports shared `Stack` props.
- The component does not expose `direction`.
- The table below defines alignment.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `hAlign` | `StackCrossAlignment` | `'stretch'` | Horizontal cross-axis alignment. |
| `vAlign` | `StackMainAlignment` | — | Vertical main-axis alignment. |

## StackItem Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `'static' \| 'fill'` | `'static'` | Keeps the intrinsic size or fills the remaining space. |
| `crossAlignSelf` | `'start' \| 'center' \| 'end' \| 'stretch'` | — | Overrides cross-axis alignment for this item. |
| `isScrollable` | `boolean` | `false` | Enables automatic overflow scrolling. |
| `as` | `string \| Component` | `'div'` | Root element or Vue component. |

## Slots

Stack, HStack, VStack, and StackItem all receive content through the default slot.

## Native attributes

The root element receives:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes.
- `class`.
- `style`.
- Native event listeners.
