Card
Card는 관련 콘텐츠를 그룹화하는 스타일이 적용된 컨테이너 컴포넌트입니다. 기본적으로 의미론이 없는 div 요소로 렌더링되며, 카드를 독립적인 영역으로 쓸지 아니면 컬렉션(목록)의 한 항목으로 쓸지에 따라 올바른 마크업 패턴이 달라집니다. 이 페이지에서는 아이콘·이미지·메타데이터·액션·컴팩트·padding·시맨틱 섹션·목록 안 사용 등 다양한 사용법과 props를 설명합니다.
출처: 문서
본문
Card는 관련 콘텐츠를 그룹화하는 스타일이 적용된 컨테이너 컴포넌트입니다. 기본적으로 자체 의미론이 없는 div 요소를 렌더링합니다. 올바른 마크업 패턴은 Card를 독립적인 영역으로 사용하는지, 아니면 컬렉션(목록)의 한 항목으로 사용하는지에 따라 달라집니다.
React 예시
기본 (Default)
아이콘, 제목, 설명, 메타데이터가 있는 기본적인 Card입니다.
<div style={{maxWidth: '400px'}}>
<Card>
<Card.Icon icon={RocketIcon} />
<Card.Heading>Card Heading</Card.Heading>
<Card.Description>This is a description of the card providing supplemental information.</Card.Description>
<Card.Metadata>
<PeopleIcon size={16} /> 3 contributors
</Card.Metadata>
</Card>
</div>
이미지와 함께 (With image)
아이콘 대신 카드 헤더에 꽉 차는(edge-to-edge) 이미지를 렌더링하려면 Card.Image를 사용하세요.
<div style={{maxWidth: '400px'}}>
<Card>
<Card.Image src="https://github.com/octocat.png" alt="Octocat" />
<Card.Heading>Card with Image</Card.Heading>
<Card.Description>This card uses an edge-to-edge image instead of an icon.</Card.Description>
</Card>
</div>
메타데이터와 함께 (With metadata)
설명 아래에 보충 메타데이터 콘텐츠를 표시하려면 Card.Metadata를 사용하세요.
<div style={{maxWidth: '400px'}}>
<Card>
<Card.Icon icon={RepoIcon} />
<Card.Heading>primer/react</Card.Heading>
<Card.Description>
{"GitHub's design system implemented as React components for building consistent user interfaces."}
</Card.Description>
<Card.Metadata>
<StarIcon size={16} />
1.2k stars
</Card.Metadata>
</Card>
</div>
액션과 함께 (With action)
카드 오른쪽 위 모서리에 단일 대화형 컨트롤을 배치하려면 Card.Action을 사용하세요. 컨트롤 라벨은 카드 맥락을 포함해야 합니다.
<div style={{maxWidth: '400px'}}>
<Card>
<Card.Icon icon={RepoIcon} />
<Card.Heading>primer/react</Card.Heading>
<Card.Description>
{"GitHub's design system implemented as React components for building consistent user interfaces."}
</Card.Description>
<Card.Metadata>
<StarIcon size={16} />
1.2k stars
</Card.Metadata>
<Card.Action>
<ActionMenu>
<ActionMenu.Anchor>
<IconButton icon={KebabHorizontalIcon} aria-label="More options for primer/react" variant="invisible" />
</ActionMenu.Anchor>
<ActionMenu.Overlay>
<ActionList>
<ActionList.Item>Star</ActionList.Item>
<ActionList.Item>Watch</ActionList.Item>
<ActionList.Item>Fork</ActionList.Item>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</Card.Action>
</Card>
</div>
컴팩트 (Compact)
더 촘촘한 레이아웃을 위해 layout="compact"를 설정하세요. 더 좁은 간격, 배경 컨테이너가 없는 아이콘, 더 작은 제목을 사용합니다. 공간이 제약된 맥락이나 다른 조밀한 콘텐츠 옆에서 카드를 표시할 때 사용하세요.
<div style={{maxWidth: '400px'}}>
<Card layout="compact">
<Card.Icon icon={RepoIcon} />
<Card.Heading>primer/react</Card.Heading>
<Card.Description>
The compact layout uses tighter spacing, an icon without a background container, and a smaller title.
</Card.Description>
<Card.Metadata>
<StarIcon size={16} />
1.2k stars
</Card.Metadata>
</Card>
</div>
Padding
padding prop은 Card의 내부 padding을 제어합니다. 사용 가능한 값은 normal(기본값), condensed, none입니다.
<Stack direction="horizontal" gap="normal">
<div style={{maxWidth: '300px'}}>
<Card padding="normal">
<Card.Icon icon={RocketIcon} />
<Card.Heading>Normal padding</Card.Heading>
<Card.Description>This card uses the default normal padding.</Card.Description>
</Card>
</div>
<div style={{maxWidth: '300px'}}>
<Card padding="condensed">
<Card.Icon icon={RocketIcon} />
<Card.Heading>Condensed padding</Card.Heading>
<Card.Description>This card uses condensed padding.</Card.Description>
</Card>
</div>
<div style={{maxWidth: '300px'}}>
<Card padding="none">
<Card.Icon icon={RocketIcon} />
<Card.Heading>No padding</Card.Heading>
<Card.Description>This card uses no padding.</Card.Description>
</Card>
</div>
</Stack>
시맨틱 섹션 (Semantic section)
카드가 독립적인 랜드마크로 노출되어야 할 때 as="section"을 설정하세요. 이렇게 사용하면 Card.Heading이 aria-labelledby로 섹션에 자동으로 연결됩니다.
<div style={{maxWidth: '400px'}}>
<Card as="section">
<Card.Icon icon={RepoIcon} />
<Card.Heading>primer/react</Card.Heading>
<Card.Description>
This card is rendered as a section landmark and uses its heading for accessible labeling.
</Card.Description>
</Card>
</div>
목록 안에서 (In a list)
카드의 컬렉션을 렌더링할 때는 각 Card를 <li> 안에 배치해 목록이 그룹화를 제공하도록 하세요. 의미론과 대화형 컨트롤 라벨링에 대한 자세한 내용은 accessibility guidance 를 참고하세요.
<ul
aria-label="Repositories"
style={{
display: 'flex',
flexDirection: 'column',
gap: 8,
margin: 0,
padding: 0,
listStyle: 'none',
maxWidth: '400px',
}}
>
<li>
<Card>
<Card.Icon icon={RepoIcon} />
<Card.Description>primer/react</Card.Description>
<Card.Metadata>
<Button leadingVisual={StarIcon} size="small">
Star <VisuallyHidden>primer/react</VisuallyHidden>
</Button>
<Button leadingVisual={RepoForkedIcon} size="small">
Fork <VisuallyHidden>primer/react</VisuallyHidden>
</Button>
</Card.Metadata>
</Card>
</li>
<li>
<Card>
<Card.Icon icon={RepoIcon} />
<Card.Description>primer/css</Card.Description>
<Card.Metadata>
<Button leadingVisual={StarIcon} size="small">
Star <VisuallyHidden>primer/css</VisuallyHidden>
</Button>
<Button leadingVisual={RepoForkedIcon} size="small">
Fork <VisuallyHidden>primer/css</VisuallyHidden>
</Button>
</Card.Metadata>
</Card>
</li>
<li>
<Card>
<Card.Icon icon={RepoIcon} />
<Card.Description>primer/octicons</Card.Description>
<Card.Metadata>
<Button leadingVisual={StarIcon} size="small">
Star <VisuallyHidden>primer/octicons</VisuallyHidden>
</Button>
<Button leadingVisual={RepoForkedIcon} size="small">
Fork <VisuallyHidden>primer/octicons</VisuallyHidden>
</Button>
</Card.Metadata>
</Card>
</li>
</ul>
사용자 정의 콘텐츠 (Custom content)
하위 컴포넌트(Card.Icon, Card.Heading 등)를 사용하지 않으면 Card는 임의의 children을 담는 평범한 스타일 컨테이너로 렌더링됩니다.
<div style={{maxWidth: '400px'}}>
<Card>
<div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
<h3 style={{margin: 0}}>Custom Content Card</h3>
<p style={{margin: 0}}>This card uses arbitrary custom content instead of the built-in subcomponents.</p>
<ul style={{margin: 0, paddingLeft: '16px'}}>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
</div>
</Card>
</div>
더 많은 코드 예시 (More code examples)
Card Storybook stories 를 참고하세요.
Props
Card
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| children | Required | 카드의 콘텐츠입니다. Card.* 하위 컴포넌트(예: Card.Heading, Card.Description, Card.Metadata) 혹은 임의의 커스텀 콘텐츠를 제공하세요. children이 없는 카드는 렌더링되지 않습니다 |
| className | string | 커스텀 스타일링용 CSS 클래스 이름을 지정합니다 |
| padding | 'normal' | 'none' | 'condensed' | 'normal' — Card의 내부 padding을 제어합니다 |
| borderRadius | 'large' | 'medium' | 'large' — Card의 테두리(border radius)를 제어합니다 |
| as | 'div' | 'div' | 'section' — 렌더링할 HTML 요소입니다. 화면 낭독기가 Card를 라벨링된 영역으로 선언하도록 독립형(목록 밖) Card에는 'section'을 사용하세요. Card.Heading이 있으면 aria-labelledby가 자동으로 연결됩니다. Card가 카드 목록의 <li> 안에 있으면 기본 'div'를 사용하세요 |
Card.Icon
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| icon | React.ElementType | 렌더링할 Octicon 또는 사용자 정의 SVG 아이콘을 지정합니다 |
| aria-label | string | 아이콘의 접근 가능한 라벨입니다. 생략하면 아이콘은 장식용으로 취급됩니다 |
Card.Image
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| src | string | 이미지 소스 URL입니다 |
| alt | "" | 접근성을 위한 대체 텍스트입니다. 기본값은 빈 문자열(장식용)입니다 |
Card.Heading
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| as | 'h3' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' — 렌더링할 제목 레벨입니다. 부모 Card가 as="section"을 사용하면 제목의 id가 섹션의 aria-labelledby에 자동으로 연결됩니다 |
Card.Description
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| children | Required | 카드의 설명 텍스트입니다. <p> 요소 안에 렌더링되므로 흐르는 텍스트 콘텐츠여야 합니다 |
Card.Action
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| children | Required | 카드 오른쪽 위 모서리를 위한 대화형 컨트롤입니다 |
Card.Metadata
| 이름 (Name) | 기본값 (Default) | 설명 (Description) |
|---|---|---|
| children | Required | 카드 하단을 위한 메타데이터 콘텐츠입니다. 일반 텍스트, 아이콘, 다른 Primer 컴포넌트 등 어떤 콘텐츠든 받습니다 |
더 알아보기 (Learn more)
- Card 접근성: 시맨틱 구조와 랜드마크 라벨링 지침을 확인하세요.
- Primer Product 가이드: 다른 컴포넌트와 원칙을 둘러보세요.