본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Spacer 마이그레이션 가이드 (v2 → v3)

원문 보기 위키 갱신

이 문서는 HeroUI의 Spacer 컴포넌트가 v3에서 어떻게 바뀌었는지를 정리한 마이그레이션 가이드예요. Spacer는 v3에서 완전히 제거됐으므로, Tailwind CSS 마진 유틸리티로 대체해야 해요.

출처: HeroUI

본문

참고: Spacer 컴포넌트는 HeroUI v3에서 제거됐어요. 대신 Tailwind CSS margin 유틸리티를 직접 사용하세요.

핵심 변경 사항 (Key Changes)

1. 컴포넌트 제거 (Component Removal)

v2: @heroui/react의 <Spacer> 컴포넌트
v3: Tailwind CSS margin 유틸리티 (ml-*, mr-*, mt-*, mb-*, mx-*, my-*)

2. Props 매핑 (Props Mapping)

v2 Spacer 컴포넌트의 props는 다음과 같이 Tailwind 유틸리티에 매핑돼요.

v2 Prop v3 대응 설명
x={n} ml-{n} 또는 mx-{n} 수평 margin (왼쪽 또는 양쪽)
y={n} mt-{n} 또는 my-{n} 수직 margin (위 또는 양쪽)
isInline inline-block 또는 block 표시(display) 타입

3. 간격 스케일 (Spacing Scale)

v2의 간격 값은 Tailwind의 간격 스케일과 일치해요.

  • x={1} → ml-1 (0.25rem / 4px)
  • x={2} → ml-2 (0.5rem / 8px)
  • x={4} → ml-4 (1rem / 16px)
  • y={4} → mt-4 (1rem / 16px)
  • 기타 등등

마이그레이션 예제 (Migration Examples)

기본 간격 (Basic Spacing)

import { Spacer } from "@heroui/react";

{/* Vertical spacing */}
<div>
  <div>Item 1</div>
  <Spacer y={4} />
  <div>Item 2</div>
</div>

{/* Horizontal spacing */}
<div className="flex">
  <div>Item 1</div>
  <Spacer x={4} isInline />
  <div>Item 2</div>
</div>
{/* Vertical spacing */}
<div>
  <div>Item 1</div>
  <div className="mt-4">Item 2</div>
</div>

{/* Horizontal spacing */}
<div className="flex">
  <div>Item 1</div>
  <div className="ml-4">Item 2</div>
</div>

flex와 grid 레이아웃에서는 Spacer보다 gap을 쓰는 게 더 좋을 때가 많아요.

import { Spacer } from "@heroui/react";

{/* Horizontal layout */}
<div className="flex">
  <div>Item 1</div>
  <Spacer x={4} isInline />
  <div>Item 2</div>
</div>

{/* Vertical layout */}
<div className="flex flex-col">
  <Button>Button 1</Button>
  <Spacer y={2} />
  <Button>Button 2</Button>
</div>
{/* Horizontal layout */}
<div className="flex gap-4">
  <div>Item 1</div>
  <div>Item 2</div>
</div>

{/* Vertical layout */}
<div className="flex flex-col gap-2">
  <Button>Button 1</Button>
  <Button>Button 2</Button>
</div>

완전한 예제 (Complete Example)

import { Spacer, Button } from "@heroui/react";

export default function App() {
  return (
    <div>
      <h1>Title</h1>
      <Spacer y={4} />
      <p>Description text</p>
      <Spacer y={8} />
      <div className="flex">
        <Button>Cancel</Button>
        <Spacer x={4} isInline />
        <Button>Submit</Button>
      </div>
    </div>
  );
}
import { Button } from "@heroui/react";

export default function App() {
  return (
    <div>
      <h1>Title</h1>
      <p className="mt-4">Description text</p>
      <div className="mt-8 flex gap-4">
        <Button>Cancel</Button>
        <Button>Submit</Button>
      </div>
    </div>
  );
}

간격 스케일 레퍼런스 (Spacing Scale Reference)

Tailwind CSS 간격 스케일 (v2 Spacer 값과 일치):

값 크기 Tailwind 클래스
0 0px m-0, ml-0, mt-0, 등
px 1px m-px, ml-px, mt-px, 등
0.5 0.125rem (2px) m-0.5, ml-0.5, mt-0.5, 등
1 0.25rem (4px) m-1, ml-1, mt-1, 등
2 0.5rem (8px) m-2, ml-2, mt-2, 등
3 0.75rem (12px) m-3, ml-3, mt-3, 등
4 1rem (16px) m-4, ml-4, mt-4, 등
5 1.25rem (20px) m-5, ml-5, mt-5, 등
6 1.5rem (24px) m-6, ml-6, mt-6, 등
8 2rem (32px) m-8, ml-8, mt-8, 등
10 2.5rem (40px) m-10, ml-10, mt-10, 등
12 3rem (48px) m-12, ml-12, mt-12, 등
16 4rem (64px) m-16, ml-16, mt-16, 등
20 5rem (80px) m-20, ml-20, mt-20, 등

모범 사례 (Best Practices)

1. flex/grid 레이아웃에는 gap 사용

Spacer 컴포넌트 대신 gap 유틸리티를 사용하세요.

// ✅ Recommended
<div className="flex gap-4">
  <Button>Button 1</Button>
  <Button>Button 2</Button>
</div>

// ❌ Not recommended
<div className="flex">
  <Button>Button 1</Button>
  <div className="ml-4"><Button>Button 2</Button></div>
</div>

2. 수직 목록에는 space 유틸리티 사용

// ✅ Recommended
<div className="space-y-4">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

// Alternative
<div>
  <div>Item 1</div>
  <div className="mt-4">Item 2</div>
  <div className="mt-4">Item 3</div>
</div>

3. margin 유틸리티 직접 적용

Spacer 대신 요소에 margin을 직접 적용하세요.

// ✅ Recommended
<div className="mt-4">Content</div>

// ❌ Not recommended
<>
  <Spacer y={4} />
  <div>Content</div>
</>

요약 (Summary)

  1. 컴포넌트 제거: Spacer 컴포넌트는 v3에 더 이상 존재하지 않아요.
  2. 임포트 변경: import { Spacer } from "@heroui/react"를 제거하세요.
  3. Tailwind 유틸리티 사용: margin 유틸리티(ml-*, mt-*, mx-*, my-*)로 대체하세요.
  4. gap 사용: flex/grid 레이아웃에는 gap-* 유틸리티를 선호하세요.
  5. space 사용: 일관된 간격을 위해 space-y-*와 space-x-*를 선호하세요.

마이그레이션 단계 (Migration Steps)

  1. 임포트 제거: @heroui/react 임포트에서 Spacer를 제거하세요.
  2. Spacer 교체: <Spacer x={n} />를 ml-{n} 또는 mx-{n} 클래스로 교체하세요.
  3. Spacer 교체: <Spacer y={n} />를 mt-{n} 또는 my-{n} 클래스로 교체하세요.
  4. gap 사용: flex/grid 레이아웃에는 Spacer 대신 gap-{n}을 사용하세요.
  5. space 사용: 수직/수평 목록에는 space-y-{n} 또는 space-x-{n}을 사용하세요.

일반적인 패턴 (Common Patterns)

간격이 있는 수직 스택 (Vertical Stack with Spacing)

// Using space-y utility
<div className="space-y-4">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

간격이 있는 수평 행 (Horizontal Row with Spacing)

// Using gap utility
<div className="flex gap-4">
  <Button>Button 1</Button>
  <Button>Button 2</Button>
  <Button>Button 3</Button>
</div>

특정 요소 사이의 커스텀 간격 (Custom Spacing Between Specific Elements)

<div>
  <div>Item 1</div>
  <div className="mt-8">Item 2 (with custom spacing)</div>
  <div className="mt-4">Item 3</div>
</div>

더 알아보기 (Learn more)