카드(Card) v2 → v3 마이그레이션
HeroUI v2의 Card를 v3로 옮길 때 필요한 구조·컴포넌트 이름·props·변형(variant) 변경을 정리한 가이드예요. v2에서는 CardHeader, CardBody, CardFooter처럼 분리된 컴포넌트를 사용했는데, v3에서는 점 표기법(dot notation)의 합성 컴포넌트 패턴으로 바뀌었어요. 구조가 어떻게 달라지는지 차근차근 살펴볼게요.
출처: HeroUI
본문
참고: 완전한 API 레퍼런스, 스타일링 가이드, 고급 예제는 v3 Card 문서를 참고하세요. 이 가이드는 HeroUI v2에서 마이그레이션하는 부분에만 집중합니다.
구조 변화
v2에서는 Card가 CardHeader, CardBody, CardFooter처럼 분리된 컴포넌트를 사용했어요:
import { Card, CardHeader, CardBody, CardFooter } from "@heroui/react";
export default function App() {
return (
<Card>
<CardHeader>Header</CardHeader>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
</Card>
);
}
v3에서는 Card가 명시적인 하위 컴포넌트를 쓰는 합성 컴포넌트 패턴을 사용해요:
import { Card } from "@heroui/react";
export default function App() {
return (
<Card>
<Card.Header>
<Card.Title>Title</Card.Title>
<Card.Description>Description</Card.Description>
</Card.Header>
<Card.Content>Body content</Card.Content>
<Card.Footer>Footer</Card.Footer>
</Card>
);
}
주요 변경 사항
1. 컴포넌트 구조
v2: 분리된 컴포넌트: CardHeader, CardBody, CardFooter
v3: 합성 컴포넌트: Card.Header, Card.Title, Card.Description, Card.Content, Card.Footer
2. 컴포넌트 이름 변경
| v2 Component | v3 Component | Notes |
|---|---|---|
CardHeader |
Card.Header |
Same functionality |
CardBody |
Card.Content |
Renamed |
CardFooter |
Card.Footer |
Same functionality |
| - | Card.Title |
New subcomponent for header titles |
| - | Card.Description |
New subcomponent for header descriptions |
3. Prop 변경
| v2 Prop | v3 Location | Notes |
|---|---|---|
shadow |
- | Removed (use Tailwind e.g. shadow-sm, shadow-md) |
radius |
- | Removed (use Tailwind e.g. rounded-lg) |
fullWidth |
- | Removed (use Tailwind w-full) |
isHoverable |
- | Removed (use Tailwind hover classes) |
isPressable |
- | Use button or link wrapper inside Card |
isBlurred, isFooterBlurred |
- | Removed (use Tailwind backdrop-blur-*) |
isDisabled |
- | Removed (handle with conditional rendering) |
disableAnimation, disableRipple |
- | Removed |
allowTextSelectionOnPress |
- | Removed (not applicable) |
classNames |
- | Use className on parts |
4. 변형(variants)
v2: variant prop 없음 (스타일링은 shadow/radius 사용)
v3: variant prop 사용: transparent, default, secondary, tertiary
마이그레이션 예제
카드 구조
v2:
{/* Basic structure */}
<Card>
<CardHeader>Header</CardHeader>
<CardBody>Body content</CardBody>
<CardFooter>Footer</CardFooter>
</Card>
{/* With title and description */}
<Card>
<CardHeader className="pb-0 pt-2 px-4 flex-col items-start">
<p className="text-tiny uppercase font-bold">Daily Mix</p>
<small className="text-default-500">12 Tracks</small>
<h4 className="font-bold text-large">Frontend Radio</h4>
</CardHeader>
<CardBody>Content</CardBody>
</Card>
v3:
{/* Basic structure */}
<Card>
<Card.Header>
<Card.Title>Header</Card.Title>
</Card.Header>
<Card.Content>Body content</Card.Content>
<Card.Footer>Footer</Card.Footer>
</Card>
{/* With title and description */}
<Card>
<Card.Header>
<Card.Title>Frontend Radio</Card.Title>
<Card.Description>Daily Mix • 12 Tracks</Card.Description>
</Card.Header>
<Card.Content>Content</Card.Content>
</Card>
누를 수 있는(Pressable) 카드
v2:
<Card
isPressable
shadow="sm"
onPress={() => console.log("pressed")}
>
<CardBody>Clickable card</CardBody>
</Card>
v3:
<Card className="shadow-sm">
<button
type="button"
className="w-full cursor-pointer text-left"
onClick={() => console.log("pressed")}
>
<Card.Content>Clickable card</Card.Content>
</button>
</Card>
이미지가 있는 카드
v2:
<Card className="py-4">
<CardHeader className="pb-0 pt-2 px-4 flex-col items-start">
<h4 className="font-bold text-large">Frontend Radio</h4>
</CardHeader>
<CardBody className="overflow-visible py-2">
<Image
alt="Card background"
className="object-cover rounded-xl"
src="https://example.com/image.jpg"
width={270}
/>
</CardBody>
</Card>
v3:
<Card className="py-4">
<Card.Header>
<Card.Title>Frontend Radio</Card.Title>
</Card.Header>
<Card.Content className="overflow-visible py-2">
<img
alt="Card background"
className="object-cover rounded-xl w-full"
src="https://example.com/image.jpg"
/>
</Card.Content>
</Card>
블러(Blurred) 푸터 카드
v2:
import { Card, CardFooter, Image, Button } from "@heroui/react";
<Card isFooterBlurred className="border-none" radius="lg">
<Image
alt="Woman listing to music"
className="object-cover"
height={200}
src="https://example.com/image.jpg"
width={200}
/>
<CardFooter className="justify-between before:bg-white/10 border-white/20 border-1 overflow-hidden py-1 absolute before:rounded-xl rounded-large bottom-1 w-[calc(100%_-_8px)] shadow-small ml-1 z-10">
<p className="text-tiny text-white/80">Available soon.</p>
<Button className="text-tiny text-white bg-black/20" size="sm">
Notify me
</Button>
</CardFooter>
</Card>
v3:
import { Card, Button } from "@heroui/react";
<Card className="border-none rounded-lg relative overflow-hidden">
<img
alt="Woman listing to music"
className="object-cover w-full h-[200px]"
src="https://example.com/image.jpg"
/>
<Card.Footer className="justify-between backdrop-blur-md bg-white/10 border-white/20 border overflow-hidden py-1 absolute rounded-lg bottom-1 w-[calc(100%_-_8px)] shadow-sm ml-1 z-10">
<p className="text-tiny text-white/80">Available soon.</p>
<Button className="text-tiny text-white bg-black/20" size="sm">
Notify me
</Button>
</Card.Footer>
</Card>
카드 변형(Card Variants)
v2:
{/* v2 doesn't have variants, uses shadow/radius */}
<Card shadow="md" radius="lg">
<CardBody>Content</CardBody>
</Card>
v3:
<Card variant="default">
<Card.Content>Content</Card.Content>
</Card>
<Card variant="secondary">
<Card.Content>Content</Card.Content>
</Card>
스타일링 변경
v2: classNames Prop
<Card
classNames={{
base: "custom-base",
header: "custom-header",
body: "custom-body",
footer: "custom-footer"
}}
/>
v3: 직접 className Props 사용
<Card className="custom-base">
<Card.Header className="custom-header">
<Card.Title>Title</Card.Title>
</Card.Header>
<Card.Content className="custom-body">
Content
</Card.Content>
<Card.Footer className="custom-footer">
Footer
</Card.Footer>
</Card>
컴포넌트 구조(Anatomy)
v3 Card는 다음과 같은 구조를 가져요:
Card (Root)
├── Card.Header (optional)
│ ├── Card.Title (optional)
│ └── Card.Description (optional)
├── Card.Content (optional)
└── Card.Footer (optional)
요약
- 컴포넌트 구조: 분리된 컴포넌트 대신 합성 컴포넌트를 반드시 사용
- CardBody → Card.Content: 컴포넌트 이름 변경됨
- 새 하위 컴포넌트: 구조화된 헤더를 위한
Card.Title과Card.Description - 제거된 Props: 스타일링 props 다수가 제거됨 — Tailwind CSS 클래스 사용
- 누를 수 있는 카드:
isPressable대신 Card 안에 button 또는 link 사용 - 블러 효과: props 대신 Tailwind
backdrop-blur-*클래스 사용 - 변형(variants): 의미적 중요도 수준을 위한 새 variant 시스템
- classNames 제거: 개별 컴포넌트에
classNameprops 사용