Stack
반응형 세로·가로 흐름(flow)을 만들어 주는 레이아웃 컴포넌트입니다. 아이템 사이 간격(gap), 정렬(align/justify), 줄바꿈(wrap), 패딩을 손쉽게 제어할 수 있어서 정렬된 UI를 빠르게 쌓아 올릴 때 유용해요.
출처: 문서
본문
Stack은 반응형 가로·세로 흐름을 만드는 레이아웃 컴포넌트입니다.
React 예시
기본 (Default)
아이템 사이에 간격이 있는 단순한 컨테이너입니다.
<Stack>
<Placeholder />
<Placeholder />
<Placeholder />
</Stack>
방향 (Direction)
direction을 'horizontal'로 설정하면 아이템을 인라인(가로)으로 배치합니다.
<Stack direction="horizontal">
<Placeholder />
<Placeholder />
<Placeholder />
</Stack>
간격 크기 (Gap size)
'condensed'로 간격을 줄이거나, 'none'으로 간격을 완전히 없앨 수 있습니다.
<Stack gap="condensed">
<Placeholder />
<Placeholder />
<Placeholder />
</Stack>
아이템 정렬 (Align items)
아이템을 세로로 가운데 정렬하려면 align을 'center'로 설정합니다.
<Stack align="center" direction="horizontal">
<Placeholder />
<Placeholder style={{height: 'var(--base-size-12)'}} />
<Placeholder />
</Stack>
아이템 분배 (Justify items)
이 예시는 'space-between' justify 변형을 사용합니다.
<Stack justify="space-between" direction="horizontal">
<Placeholder />
<Placeholder />
<Placeholder />
</Stack>
아이템 줄바꿈 (Wrap items)
기본적으로 Stack 아이템은 no-wrap으로 설정됩니다. 아이템이 다음 줄로 넘어가게 하려면 wrap을 'wrap'으로 설정합니다.
<Stack wrap="wrap" direction="horizontal">
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</Stack>
Stack 컨테이너에 패딩 추가 (Add padding to the Stack container)
padding 변형을 설정하면 아이템 주위에 패딩을 추가합니다.
<Stack padding="spacious">
<Placeholder />
<Placeholder />
<Placeholder />
</Stack>
아이템 확대·축소 (Shrink and grow items)
Stack.Item에 grow를 주면 남는 공간을 채우도록 확장할 수 있습니다.
<Stack direction="horizontal">
<Stack.Item>
<Placeholder />
</Stack.Item>
<Stack.Item grow>
<Placeholder />
</Stack.Item>
</Stack>
더 많은 예시 (More examples)
Stack 컴포넌트의 "Playground" 스토리에서 Stack 컴포넌트의 반응형 동작을 직접 확인해 보세요.
- Stack playground
- Stack.Item playground
Props
Stack
| Name | Default | Description |
|---|---|---|
| gap | — | 'none' | 'tight' | 'condensed' | 'cozy' | 'normal' | 'spacious' | ResponsiveValue<...> — 스택 안의 자식 요소 사이 간격을 지정합니다. |
| direction | — | 'horizontal' | 'vertical' | ResponsiveValue<...> — 스택 컨테이너의 방향을 지정합니다. |
| align | — | 'stretch' | 'start' | 'center' | 'end' | 'baseline' | ResponsiveValue<...> — 방향의 교차축에서 아이템 사이의 정렬을 지정합니다. |
| wrap | — | 'wrap' | 'nowrap' | ResponsiveValue<...> — 아이템을 한 줄로 강제할지, 여러 줄로 줄바꿈할 수 있게 할지 지정합니다. |
| justify | — | 'start' | 'center' | 'end' | 'space-between' | 'space-evenly' | ResponsiveValue<...> — 스태킹 방향으로 아이템을 어떻게 분배할지 지정합니다. |
| padding | — | 'none' | 'tight' | 'condensed' | 'cozy' | 'normal' | 'spacious' | ResponsiveValue<...> — 스택 컨테이너의 패딩을 지정합니다. |
| paddingBlock | — | 'none' | 'tight' | 'condensed' | 'cozy' | 'normal' | 'spacious' | ResponsiveValue<...> — 스택 컨테이너의 블록(세로) 패딩을 지정합니다. 둘 다 설정되면 padding의 블록 축을 재정의합니다. |
| paddingInline | — | 'none' | 'tight' | 'condensed' | 'cozy' | 'normal' | 'spacious' | ResponsiveValue<...> — 스택 컨테이너의 인라인(가로) 패딩을 지정합니다. 둘 다 설정되면 padding의 인라인 축을 재정의합니다. |
| className | — | string — 클래스 이름입니다. |
Stack.Item
| Name | Default | Description |
|---|---|---|
| grow | — | boolean | ResponsiveValue<boolean> — 아이템이 크기를 유지하거나 남는 공간을 채우도록 확장하게 합니다. |
| shrink | — | boolean | ResponsiveValue<boolean> — 아이템이 크기를 유지하거나 남는 공간에 맞게 축소되게 합니다. |
| className | — | string — 클래스 이름입니다. |