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

Alert 마이그레이션 가이드

원문 보기 위키 갱신

이 문서는 HeroUI v2에서 v3로 Alert 컴포넌트를 옮길 때 어떻게 바꿔야 하는지 설명해요.

참고: v3 Alert 문서에서 완전한 API 레퍼런스, 스타일링 가이드, 고급 예제를 확인할 수 있어요. 이 가이드는 HeroUI v2에서 마이그레이션하는 데만 집중해요.

출처: HeroUI

본문

구조 변경

v2에서는 Alert가 제목, 설명, 아이콘 등 여러 요소를 props로 받는 단일 컴포넌트였어요.

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

export default function App() {
  return (
    <Alert 
      title="This is an alert"
      description="Thanks for subscribing to our newsletter!"
    />
  );
}

v3에서는 Alert가 명시적인 하위 컴포넌트를 사용하는 복합(compound) 컴포넌트 패턴으로 바뀌었어요.

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

export default function App() {
  return (
    <Alert>
      <Alert.Indicator />
      <Alert.Content>
        <Alert.Title>This is an alert</Alert.Title>
        <Alert.Description>
          Thanks for subscribing to our newsletter!
        </Alert.Description>
      </Alert.Content>
    </Alert>
  );
}

주요 변경 사항

1. 컴포넌트 구조

v2: props를 받는 단일 Alert 컴포넌트
v3: 복합 컴포넌트: Alert, Alert.Indicator, Alert.Content, Alert.Title, Alert.Description

2. 색상/상태 props

v2 Color v3 Status 비고
default default 동일
primary accent 이름 변경
secondary default default 상태 사용
success success 동일
warning warning 동일
danger danger 동일

3. 제거된 변형(variants)

v2 변형: solid, bordered, flat, faded
v3: variant prop이 없어요 — Tailwind CSS 클래스를 사용해 비슷한 효과를 낼 수 있어요.

v2 변형 스타일을 v3에서 구현하려면:

  • v2 solid → v3 status + 배경색 클래스 추가
  • v2 bordered → v3 status + border 클래스 추가
  • v2 flat → v3 기본값 (추가 클래스 불필요)
  • v2 faded → v3 status + 불투명도/배경 클래스 추가

4. prop 변경 사항

v2 Prop v3 위치 비고
variant - 제거됨 (Tailwind CSS 사용)
radius - 제거됨 (예: rounded-lg 같은 Tailwind 사용)
startContent - <Alert.Indicator /> 앞에 콘텐츠 배치
endContent - <Alert.Content /> 뒤에 콘텐츠 배치
hideIcon - <Alert.Indicator /> 생략
hideIconWrapper - 제거됨 (v3에는 래퍼 없음)
icon Alert.Indicator 아이콘을 <Alert.Indicator />의 자식으로 렌더링
isVisible, isDefaultVisible, onVisibleChange - 제거됨 (조건부 렌더링으로 처리)
isClosable, onClose, closeButtonProps - 제거됨 (CloseButton 직접 추가)
title Alert.Title <Alert.Content> 안에서 <Alert.Title> 사용
description Alert.Description <Alert.Content> 안에서 <Alert.Description> 사용

5. 아이콘 처리

v2: icon prop 또는 hideIcon prop 사용
v3: 사용자 지정 자식을 가진 <Alert.Indicator />를 사용하거나 완전히 생략해요.

마이그레이션 예제

아이콘 처리

import { Icon } from '@iconify/react';

{/* With custom icon */}
<Alert 
  icon={<Icon icon="gravity-ui:box" />}
  title="Custom Icon Alert"
/>

{/* Without icon */}
<Alert hideIcon title="No Icon Alert" />
import { Icon } from '@iconify/react';

{/* With custom icon */}
<Alert>
  <Alert.Indicator>
    <Icon icon="gravity-ui:box" />
  </Alert.Indicator>
  <Alert.Content>
    <Alert.Title>Custom Icon Alert</Alert.Title>
  </Alert.Content>
</Alert>

{/* Without icon */}
<Alert>
  <Alert.Content>
    <Alert.Title>No Icon Alert</Alert.Title>
  </Alert.Content>
</Alert>

동작 버튼이 있는 경우 (end content)

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

<Alert
  title="You have no credits left"
  description="Upgrade to a paid plan to continue"
  endContent={
    <Button color="warning" size="sm" variant="flat">
      Upgrade
    </Button>
  }
/>
import { Alert, Button } from "@heroui/react";

<Alert status="warning">
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>You have no credits left</Alert.Title>
    <Alert.Description>
      Upgrade to a paid plan to continue
    </Alert.Description>
    <Button className="mt-2" size="sm" variant="primary">
      Upgrade
    </Button>
  </Alert.Content>
</Alert>

닫을 수 있는 Alert

<Alert
  title="Closable Alert"
  isClosable
  onClose={() => console.log("Closed")}
/>
import { Alert, CloseButton } from "@heroui/react";
import { useState } from "react";

const [isVisible, setIsVisible] = useState(true);

{isVisible && (
  <Alert>
    <Alert.Indicator />
    <Alert.Content>
      <Alert.Title>Closable Alert</Alert.Title>
    </Alert.Content>
    <CloseButton 
      aria-label="Close"
      onPress={() => setIsVisible(false)}
    />
  </Alert>
)}

스타일링 변경 사항

v2: classNames prop

<Alert 
  classNames={{
    base: "custom-base",
    title: "custom-title",
    description: "custom-description"
  }}
/>

v3: 직접 className prop

<Alert className="custom-base">
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title className="custom-title">Title</Alert.Title>
    <Alert.Description className="custom-description">
      Description
    </Alert.Description>
  </Alert.Content>
</Alert>

컴포넌트 구조

v3 Alert는 다음과 같은 구조를 따라요.

Alert (Root)
  ├── Alert.Indicator (optional)
  ├── Alert.Content (optional)
  │   ├── Alert.Title (optional)
  │   └── Alert.Description (optional)
  └── [Additional content like buttons, close button, etc.] (optional)

요약

  1. 컴포넌트 구조: props 대신 복합 컴포넌트를 사용해야 해요.
  2. 색상 → 상태: color prop이 status로 이름이 바뀌었고, primary → accent, secondary → default로 변경됐어요.
  3. 변형 제거: variant prop이 없어요 — Tailwind CSS 클래스를 사용해요.
  4. radius 제거: radius prop이 없어요 — Tailwind CSS 클래스를 사용해요.
  5. 내장 닫기 버튼 없음: CloseButton을 직접 추가해야 해요.
  6. 표시 제어 없음: 조건부 렌더링으로 표시 여부를 처리해요.
  7. 시작/끝 콘텐츠 prop 없음: 컴포넌트 트리에 콘텐츠를 직접 배치해요.
  8. 아이콘 처리: 자식을 가진 <Alert.Indicator />를 사용하거나 생략해요.

더 알아보기 (Learn more)