# Stack

## Introduction

The Stack component is a layout component that arranges child elements in one dimension, either vertically or horizontally, with consistent spacing. Built on Flexbox, it provides a simple and intuitive API for creating complex layouts with ease. It is useful across many UI patterns, including navigation bars, form layouts, and card internals.

```tsx
<Stack {...args}>
    <StackItem>첫 번째 아이템</StackItem>
    <StackItem>두 번째 아이템</StackItem>
    <StackItem>세 번째 아이템</StackItem>
  </Stack>
```

| Field          | Description | Default  |
| -------------- | ----------- | -------- |
| direction      | 배치 방향       | "column" |
| spacing        | 요소 간 간격     | 2        |
| alignItems     | 교차축 정렬      | —        |
| justifyContent | 주축 정렬       | —        |

## Usage

```tsx
import { Stack } from '@ceed/cds';

function MyComponent() {
  return (
    <Stack spacing={2}>
      <div>첫 번째 아이템</div>
      <div>두 번째 아이템</div>
      <div>세 번째 아이템</div>
    </Stack>
  );
}
```

## Examples

### Basic Usage

The basic usage for vertical (`column`) and horizontal (`row`) layouts.

```tsx
<div
    style={{
      display: "flex",
      gap: "3rem",
      flexWrap: "wrap"
    }}
  >
    <div>
      <Typography
        level="title-md"
        sx={{
          mb: 2
        }}
      >
        세로 스택 (Column)
      </Typography>
      <Stack spacing={2}>
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
        <StackItem>Item 3</StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-md"
        sx={{
          mb: 2
        }}
      >
        가로 스택 (Row)
      </Typography>
      <Stack direction="row" spacing={2}>
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
        <StackItem>Item 3</StackItem>
      </Stack>
    </div>
  </div>
```

### Directions

You can use different layout directions.

```tsx
<div
    style={{
      display: "flex",
      flexDirection: "column",
      gap: "3rem"
    }}
  >
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        Row (가로)
      </Typography>
      <Stack direction="row" spacing={2}>
        <StackItem>1</StackItem>
        <StackItem>2</StackItem>
        <StackItem>3</StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        Row Reverse (가로 역순)
      </Typography>
      <Stack direction="row-reverse" spacing={2}>
        <StackItem>1</StackItem>
        <StackItem>2</StackItem>
        <StackItem>3</StackItem>
      </Stack>
    </div>

    <div
      style={{
        display: "flex",
        gap: "3rem"
      }}
    >
      <div>
        <Typography
          level="title-sm"
          sx={{
            mb: 1
          }}
        >
          Column (세로)
        </Typography>
        <Stack direction="column" spacing={2}>
          <StackItem>1</StackItem>
          <StackItem>2</StackItem>
          <StackItem>3</StackItem>
        </Stack>
      </div>

      <div>
        <Typography
          level="title-sm"
          sx={{
            mb: 1
          }}
        >
          Column Reverse (세로 역순)
        </Typography>
        <Stack direction="column-reverse" spacing={2}>
          <StackItem>1</StackItem>
          <StackItem>2</StackItem>
          <StackItem>3</StackItem>
        </Stack>
      </div>
    </div>
  </div>
```

### Different Spacing

You can apply different spacing values.

```tsx
<div
    style={{
      display: "flex",
      flexDirection: "column",
      gap: "3rem"
    }}
  >
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        간격 없음 (spacing=0)
      </Typography>
      <Stack direction="row" spacing={0}>
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
        <StackItem>Item 3</StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        작은 간격 (spacing=1)
      </Typography>
      <Stack direction="row" spacing={1}>
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
        <StackItem>Item 3</StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        중간 간격 (spacing=2)
      </Typography>
      <Stack direction="row" spacing={2}>
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
        <StackItem>Item 3</StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        큰 간격 (spacing=4)
      </Typography>
      <Stack direction="row" spacing={4}>
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
        <StackItem>Item 3</StackItem>
      </Stack>
    </div>
  </div>
```

### Alignment

You can control element alignment in different ways.

```tsx
<div
    style={{
      display: "flex",
      flexDirection: "column",
      gap: "3rem"
    }}
  >
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        Center Alignment
      </Typography>
      <Stack
        direction="row"
        spacing={2}
        alignItems="center"
        justifyContent="center"
        sx={{
          minHeight: 120,
          bgcolor: "neutral.50",
          borderRadius: "md",
          p: 2
        }}
      >
        <StackItem
          sx={{
            height: 40
          }}
        >
          짧은 아이템
        </StackItem>
        <StackItem
          sx={{
            height: 80
          }}
        >
          중간 아이템
        </StackItem>
        <StackItem
          sx={{
            height: 60
          }}
        >
          다른 아이템
        </StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        Space Between
      </Typography>
      <Stack
        direction="row"
        spacing={0}
        justifyContent="space-between"
        sx={{
          bgcolor: "neutral.50",
          borderRadius: "md",
          p: 2
        }}
      >
        <StackItem>왼쪽</StackItem>
        <StackItem>가운데</StackItem>
        <StackItem>오른쪽</StackItem>
      </Stack>
    </div>

    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 1
        }}
      >
        Flex End
      </Typography>
      <Stack
        direction="row"
        spacing={2}
        justifyContent="flex-end"
        sx={{
          bgcolor: "neutral.50",
          borderRadius: "md",
          p: 2
        }}
      >
        <StackItem>Item 1</StackItem>
        <StackItem>Item 2</StackItem>
      </Stack>
    </div>
  </div>
```

### Responsive Direction

You can change the layout direction based on screen size.

```tsx
<div>
    <Typography
      level="title-md"
      sx={{
        mb: 2
      }}
    >
      반응형 방향 (화면 크기에 따라 세로↔가로 전환)
    </Typography>
    <Stack
      direction={{
        xs: "column",
        sm: "row"
      }}
      spacing={2}
      sx={{
        p: 2,
        bgcolor: "background.level1",
        borderRadius: "md"
      }}
    >
      <Box
        sx={{
          flex: 1,
          p: 2,
          bgcolor: "primary.100",
          borderRadius: "sm"
        }}
      >
        <Typography level="body-sm">
          작은 화면: 세로 배치
          <br />큰 화면: 가로 배치
        </Typography>
      </Box>
      <Box
        sx={{
          flex: 1,
          p: 2,
          bgcolor: "success.100",
          borderRadius: "sm"
        }}
      >
        <Typography level="body-sm">
          반응형 레이아웃으로
          <br />
          자동 조정됩니다
        </Typography>
      </Box>
      <Box
        sx={{
          flex: 1,
          p: 2,
          bgcolor: "warning.100",
          borderRadius: "sm"
        }}
      >
        <Typography level="body-sm">
          브라우저 크기를
          <br />
          조절해보세요
        </Typography>
      </Box>
    </Stack>
  </div>
```

### Nested Stacks

You can nest Stack components to build more complex layouts.

```tsx
<div>
    <Typography
      level="title-md"
      sx={{
        mb: 2
      }}
    >
      중첩된 스택
    </Typography>
    <Stack spacing={3}>
      <Box
        sx={{
          p: 2,
          bgcolor: "primary.50",
          borderRadius: "md"
        }}
      >
        <Typography
          level="title-sm"
          sx={{
            mb: 2
          }}
        >
          세로 스택 안의 가로 스택
        </Typography>
        <Stack direction="row" spacing={2}>
          <StackItem
            sx={{
              bgcolor: "primary.200"
            }}
          >
            Item 1
          </StackItem>
          <StackItem
            sx={{
              bgcolor: "primary.200"
            }}
          >
            Item 2
          </StackItem>
          <StackItem
            sx={{
              bgcolor: "primary.200"
            }}
          >
            Item 3
          </StackItem>
        </Stack>
      </Box>

      <Box
        sx={{
          p: 2,
          bgcolor: "success.50",
          borderRadius: "md"
        }}
      >
        <Typography
          level="title-sm"
          sx={{
            mb: 2
          }}
        >
          또 다른 가로 스택
        </Typography>
        <Stack direction="row" spacing={2} justifyContent="center">
          <StackItem
            sx={{
              bgcolor: "success.200"
            }}
          >
            중앙
          </StackItem>
          <StackItem
            sx={{
              bgcolor: "success.200"
            }}
          >
            정렬
          </StackItem>
        </Stack>
      </Box>
    </Stack>
  </div>
```

### Real World Examples

Examples that demonstrate real-world use cases.

```tsx
<div
    style={{
      display: "flex",
      flexDirection: "column",
      gap: "3rem",
      maxWidth: 600
    }}
  >
    {/* Navigation Bar */}
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        내비게이션 바
      </Typography>
      <Stack
        direction="row"
        spacing={0}
        justifyContent="space-between"
        alignItems="center"
        sx={{
          p: 2,
          bgcolor: "background.body",
          border: "1px solid",
          borderColor: "divider",
          borderRadius: "md"
        }}
      >
        <Typography level="title-md">로고</Typography>
        <Stack direction="row" spacing={2}>
          <Button variant="plain" size="sm">
            홈
          </Button>
          <Button variant="plain" size="sm">
            소개
          </Button>
          <Button variant="plain" size="sm">
            연락처
          </Button>
        </Stack>
        <Button size="sm">로그인</Button>
      </Stack>
    </div>

    {/* Profile Card */}
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        프로필 카드
      </Typography>
      <Box
        sx={{
          p: 3,
          bgcolor: "background.body",
          border: "1px solid",
          borderColor: "divider",
          borderRadius: "lg"
        }}
      >
        <Stack spacing={2}>
          <Stack direction="row" spacing={2} alignItems="center">
            <Avatar size="lg" />
            <Stack spacing={0.5}>
              <Typography level="title-md">홍길동</Typography>
              <Typography
                level="body-sm"
                sx={{
                  color: "text.secondary"
                }}
              >
                프론트엔드 개발자
              </Typography>
            </Stack>
          </Stack>

          <Typography level="body-md">
            사용자 경험을 중시하는 프론트엔드 개발자입니다. React와 TypeScript를 주로 사용합니다.
          </Typography>

          <Stack direction="row" spacing={1}>
            <Chip size="sm" variant="soft">
              React
            </Chip>
            <Chip size="sm" variant="soft">
              TypeScript
            </Chip>
            <Chip size="sm" variant="soft">
              Next.js
            </Chip>
          </Stack>

          <Stack direction="row" spacing={1} justifyContent="flex-end">
            <Button size="sm" variant="outlined" startDecorator={<BookmarkIcon />}>
              저장
            </Button>
            <Button size="sm" variant="outlined" startDecorator={<ShareIcon />}>
              공유
            </Button>
          </Stack>
        </Stack>
      </Box>
    </div>

    {/* Article Card */}
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        아티클 카드
      </Typography>
      <Box
        sx={{
          p: 3,
          bgcolor: "background.body",
          border: "1px solid",
          borderColor: "divider",
          borderRadius: "lg"
        }}
      >
        <Stack spacing={2}>
          <Stack direction="row" justifyContent="space-between" alignItems="flex-start">
            <Stack spacing={1}>
              <Typography level="title-lg">React 18의 새로운 기능들</Typography>
              <Typography
                level="body-sm"
                sx={{
                  color: "text.secondary"
                }}
              >
                2024년 1월 15일 • 5분 읽기
              </Typography>
            </Stack>
            <Button
              variant="plain"
              size="sm"
              sx={{
                color: "warning.500"
              }}
            >
              <StarIcon />
            </Button>
          </Stack>

          <Typography level="body-md">
            React 18에서 도입된 Concurrent Features와 새로운 Hooks에 대해 자세히 알아보겠습니다.
            Suspense, useTransition, useDeferredValue 등...
          </Typography>

          <Stack direction="row" spacing={1}>
            <Chip size="sm" variant="outlined">
              React
            </Chip>
            <Chip size="sm" variant="outlined">
              JavaScript
            </Chip>
            <Chip size="sm" variant="outlined">
              개발
            </Chip>
          </Stack>

          <Stack direction="row" justifyContent="space-between" alignItems="center">
            <Stack direction="row" spacing={1} alignItems="center">
              <Avatar size="sm" />
              <Typography level="body-sm">김개발</Typography>
            </Stack>
            <Stack direction="row" spacing={1}>
              <Button size="sm" variant="plain">
                좋아요 24
              </Button>
              <Button size="sm" variant="plain">
                댓글 5
              </Button>
            </Stack>
          </Stack>
        </Stack>
      </Box>
    </div>

    {/* Form Layout */}
    <div>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        폼 레이아웃
      </Typography>
      <Box
        sx={{
          p: 3,
          bgcolor: "background.body",
          border: "1px solid",
          borderColor: "divider",
          borderRadius: "lg"
        }}
      >
        <Stack spacing={3}>
          <Typography level="title-md">문의하기</Typography>

          <Stack spacing={2}>
            <Stack spacing={1}>
              <Typography level="body-sm" fontWeight="500">
                이름
              </Typography>
              <Box
                sx={{
                  p: 1.5,
                  bgcolor: "background.level1",
                  borderRadius: "sm"
                }}
              >
                <Typography
                  level="body-sm"
                  sx={{
                    color: "text.secondary"
                  }}
                >
                  이름을 입력하세요
                </Typography>
              </Box>
            </Stack>

            <Stack spacing={1}>
              <Typography level="body-sm" fontWeight="500">
                이메일
              </Typography>
              <Box
                sx={{
                  p: 1.5,
                  bgcolor: "background.level1",
                  borderRadius: "sm"
                }}
              >
                <Typography
                  level="body-sm"
                  sx={{
                    color: "text.secondary"
                  }}
                >
                  이메일을 입력하세요
                </Typography>
              </Box>
            </Stack>

            <Stack spacing={1}>
              <Typography level="body-sm" fontWeight="500">
                메시지
              </Typography>
              <Box
                sx={{
                  p: 1.5,
                  minHeight: 80,
                  bgcolor: "background.level1",
                  borderRadius: "sm"
                }}
              >
                <Typography
                  level="body-sm"
                  sx={{
                    color: "text.secondary"
                  }}
                >
                  메시지를 입력하세요
                </Typography>
              </Box>
            </Stack>
          </Stack>

          <Stack direction="row" spacing={2} justifyContent="flex-end">
            <Button variant="outlined">취소</Button>
            <Button>전송</Button>
          </Stack>
        </Stack>
      </Box>
    </div>
  </div>
```

## Key Props

### direction

Sets the layout direction of the elements.

```tsx
<Stack direction="row">가로 배치</Stack>
<Stack direction="column">세로 배치</Stack>
<Stack direction="row-reverse">가로 역순</Stack>
<Stack direction="column-reverse">세로 역순</Stack>

// responsive direction
<Stack direction={{ xs: 'column', sm: 'row' }}>
  반응형 배치
</Stack>
```

### spacing

Sets the spacing between elements.

| Value | Size | Description              |
| ----- | ---- | ------------------------ |
| `0`   | 0px  | No spacing               |
| `0.5` | 4px  | Very small spacing       |
| `1`   | 8px  | Small spacing            |
| `1.5` | 12px | Small-to-medium spacing  |
| `2`   | 16px | Medium spacing (default) |
| `3`   | 24px | Large spacing            |
| `4`   | 32px | Very large spacing       |
| `5`   | 40px | Extra large spacing      |
| `6`   | 48px | Maximum spacing          |

```tsx
<Stack spacing={2}>기본 간격</Stack>
<Stack spacing={0}>간격 없음</Stack>
<Stack spacing={4}>큰 간격</Stack>

// responsive spacing
<Stack spacing={{ xs: 1, sm: 2, md: 3 }}>
  반응형 간격
</Stack>
```

### alignItems

Sets alignment along the cross axis.

```tsx
<Stack alignItems="center">중앙 정렬</Stack>
<Stack alignItems="flex-start">시작점 정렬</Stack>
<Stack alignItems="flex-end">끝점 정렬</Stack>
<Stack alignItems="stretch">늘이기</Stack>
<Stack alignItems="baseline">베이스라인 정렬</Stack>
```

### justifyContent

Sets alignment along the main axis.

```tsx
<Stack justifyContent="center">중앙 정렬</Stack>
<Stack justifyContent="space-between">양끝 정렬</Stack>
<Stack justifyContent="space-around">균등 분할</Stack>
<Stack justifyContent="space-evenly">균등 간격</Stack>
<Stack justifyContent="flex-end">끝점 정렬</Stack>
```

## Responsive Behavior

Stack supports responsive values for all props:

```tsx
<Stack
  direction={{ xs: 'column', md: 'row' }}
  spacing={{ xs: 1, sm: 2, md: 3 }}
  alignItems={{ xs: 'stretch', md: 'center' }}
>
  {/* different layouts for different screen sizes */}
</Stack>
```

## Common Use Cases

### Navigation Bar

```tsx
<Stack direction="row" justifyContent="space-between" alignItems="center" sx={{ p: 2 }}>
  <Typography level="title-lg">Logo</Typography>
  <Stack direction="row" spacing={2}>
    <Button variant="plain">Home</Button>
    <Button variant="plain">About</Button>
    <Button variant="plain">Contact</Button>
  </Stack>
  <Button>Login</Button>
</Stack>
```

### Form Layout

```tsx
<Stack spacing={3}>
  <Typography level="title-lg">Contact Form</Typography>

  <Stack spacing={2}>
    <FormControl>
      <FormLabel>Name</FormLabel>
      <Input placeholder="Enter your name" />
    </FormControl>

    <FormControl>
      <FormLabel>Email</FormLabel>
      <Input type="email" placeholder="Enter your email" />
    </FormControl>

    <FormControl>
      <FormLabel>Message</FormLabel>
      <Textarea placeholder="Enter your message" minRows={3} />
    </FormControl>
  </Stack>

  <Stack direction="row" spacing={2} justifyContent="flex-end">
    <Button variant="outlined">Cancel</Button>
    <Button>Send</Button>
  </Stack>
</Stack>
```

### Card Content

```tsx
<Card sx={{ maxWidth: 400 }}>
  <CardContent>
    <Stack spacing={2}>
      <Stack direction="row" justifyContent="space-between" alignItems="center">
        <Typography level="title-lg">Product Name</Typography>
        <Chip variant="soft">New</Chip>
      </Stack>

      <Typography level="body-md">Product description goes here...</Typography>

      <Stack direction="row" spacing={1}>
        <Chip size="sm" variant="outlined">
          Tag 1
        </Chip>
        <Chip size="sm" variant="outlined">
          Tag 2
        </Chip>
      </Stack>

      <Stack direction="row" justifyContent="space-between" alignItems="center">
        <Typography level="title-lg" color="primary">
          $99.99
        </Typography>
        <Button>Add to Cart</Button>
      </Stack>
    </Stack>
  </CardContent>
</Card>
```

### User Profile

```tsx
<Stack spacing={3}>
  <Stack direction="row" spacing={2} alignItems="center">
    <Avatar size="lg" src="/avatar.jpg" />
    <Stack>
      <Typography level="title-lg">John Doe</Typography>
      <Typography level="body-sm" color="neutral">
        Frontend Developer
      </Typography>
    </Stack>
  </Stack>

  <Typography level="body-md">Passionate about creating great user experiences...</Typography>

  <Stack direction="row" spacing={1}>
    <Chip variant="soft">React</Chip>
    <Chip variant="soft">TypeScript</Chip>
    <Chip variant="soft">Next.js</Chip>
  </Stack>

  <Stack direction="row" spacing={2}>
    <Button variant="outlined" fullWidth>
      Follow
    </Button>
    <Button fullWidth>Message</Button>
  </Stack>
</Stack>
```

### List Layout

```tsx
<Stack spacing={2}>
  {items.map((item) => (
    <Stack
      key={item.id}
      direction="row"
      spacing={2}
      alignItems="center"
      sx={{
        p: 2,
        bgcolor: 'background.level1',
        borderRadius: 'md',
      }}
    >
      <Avatar src={item.avatar} />
      <Stack sx={{ flex: 1 }}>
        <Typography level="title-sm">{item.name}</Typography>
        <Typography level="body-xs" color="neutral">
          {item.description}
        </Typography>
      </Stack>
      <Typography level="body-xs" color="neutral">
        {item.time}
      </Typography>
    </Stack>
  ))}
</Stack>
```

### Button Group

```tsx
<Stack direction="row" spacing={1}>
  <Button variant="outlined">Cancel</Button>
  <Button variant="outlined">Save Draft</Button>
  <Button>Publish</Button>
</Stack>

<Stack direction="row" spacing={0} sx={{ border: '1px solid', borderColor: 'divider', borderRadius: 'sm' }}>
  <Button variant="plain" sx={{ borderRadius: 0, borderRight: '1px solid', borderColor: 'divider' }}>
    Bold
  </Button>
  <Button variant="plain" sx={{ borderRadius: 0, borderRight: '1px solid', borderColor: 'divider' }}>
    Italic
  </Button>
  <Button variant="plain" sx={{ borderRadius: 0 }}>
    Underline
  </Button>
</Stack>
```

## Best Practices

1. **Choose appropriate spacing**: Use spacing values that match the content hierarchy.

2. **Design responsively**: Use responsive props so layouts work well across different screen sizes.

3. **Use meaningful alignment**: Use `alignItems` and `justifyContent` to create intentional alignment.

4. **Minimize nesting**: Avoid excessive nesting and only nest Stack when it is actually needed.

5. **Consider performance**: Use virtualization when rendering many items.

6. **Consider accessibility**:
   - Arrange elements to preserve a logical tab order
   - Use appropriate semantic tags alongside Stack

7. **Maintain consistency**: Use consistent spacing values across the project.

## When to Use Stack vs Other Layout Components

### Stack vs Flexbox (Box)

- **Stack**: For simple one-dimensional layouts with consistent spacing
- **Box with flex**: For cases that need more complex Flexbox behavior

### Stack vs Grid

- **Stack**: One-dimensional layouts (vertical or horizontal)
- **Grid**: Two-dimensional layouts (rows and columns)

### Stack vs Space (if available)

- **Stack**: Provides both a container and spacing
- **Space**: Provides spacing only (between children)

## Props and Customization

### Key Props

| Prop             | Type                                                     | Default    | Description                               |
| ---------------- | -------------------------------------------------------- | ---------- | ----------------------------------------- |
| `children`       | `ReactNode`                                              | -          | Stack children                            |
| `direction`      | `'row' \| 'row-reverse' \| 'column' \| 'column-reverse'` | `'column'` | Flex direction                            |
| `spacing`        | `number \| string`                                       | `0`        | Gap between children                      |
| `alignItems`     | `string`                                                 | -          | CSS align-items                           |
| `justifyContent` | `string`                                                 | -          | CSS justify-content                       |
| `flexWrap`       | `'nowrap' \| 'wrap' \| 'wrap-reverse'`                   | `'nowrap'` | Flex wrapping behavior                    |
| `divider`        | `ReactNode`                                              | -          | Element inserted between each child       |
| `component`      | `ElementType`                                            | `'div'`    | Root element type                         |
| `useFlexGap`     | `boolean`                                                | `false`    | Use CSS gap instead of margin for spacing |
| `sx`             | `SxProps`                                                | -          | Custom styles                             |

> **Note**: Stack accepts all Joy UI Stack props.

## Troubleshooting

### Common Issues

1. **Spacing is not applied**
   - Make sure the elements are direct children
   - Check whether a Fragment or another wrapper is interfering

2. **Alignment is different from what you expected**
   - Remember that the main axis and cross axis change based on `direction`
   - Understand the difference between `alignItems` and `justifyContent`

3. **Responsive behavior is not working**
   - Check that object syntax like `{ xs: 'column', md: 'row' }` is correct
   - Verify that the breakpoint values are correct

Stack is an intuitive and powerful layout tool. Its simple API makes complex layouts easy to build, so it fits a wide range of UI patterns.
