Action card 컴포넌트
action card 컴포넌트를 사용하면 실행 가능한 단일 콘텐츠를 구조화되고 시각적인 형식으로 표시할 수 있어요. 이 페이지에서는 action card의 단위 테스트 예시와 API, 사용 지침, 작성 지침, 접근성 지침을 다룹니다. 콘텐츠가 온전히 선택 가능한 액션으로 동작해야 할 때 사용하세요.
출처: 문서
본문
단위 테스트 예시
action card 선택하기
import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import ActionCard from '@cloudscape-design/components/action-card';
describe('<ActionCard />', () => {
it('renders the action-card component', () => {
const { container } = render(<ActionCard />);
const wrapper = createWrapper(container);
expect(wrapper.findActionCard()).toBeTruthy();
});
});
action card 슬롯 찾기
import ActionCard from '@cloudscape-design/components/action-card';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
describe('<ActionCard />', () => {
it('finds the header, content, and description slots', () => {
const { container } = render(
<ActionCard header="Card header" description="Card description">
Card content
</ActionCard>
);
const wrapper = createWrapper(container);
const actionCard = wrapper.findActionCard()!;
expect(actionCard.findHeader()!.getElement().textContent).toContain('Card header');
expect(actionCard.findDescription()!.getElement().textContent).toContain('Card description');
expect(actionCard.findContent()!.getElement().textContent).toContain('Card content');
});
it('finds the icon slot', () => {
const { container } = render(
<ActionCard header="Card header" icon={Icon}>
Card content
</ActionCard>
);
const wrapper = createWrapper(container);
const actionCard = wrapper.findActionCard()!;
expect(actionCard.findIcon()).toBeTruthy();
expect(actionCard.findIcon()!.getElement().textContent).toBe('Icon');
});
});
모든 action card 찾기
import ActionCard from '@cloudscape-design/components/action-card';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
describe('<ActionCard />', () => {
it('finds all action cards on the page', () => {
const { container } = render(
<>
<ActionCard header="First card">First card content</ActionCard>
<ActionCard header="Second card">Second card content</ActionCard>
<ActionCard header="Third card">Third card content</ActionCard>
</>
);
const wrapper = createWrapper(container);
const allActionCards = wrapper.findAllActionCards();
expect(allActionCards).toHaveLength(3);
expect(allActionCards[0].findHeader()!.getElement().textContent).toBe('First card');
expect(allActionCards[1].findHeader()!.getElement().textContent).toBe('Second card');
expect(allActionCards[2].findHeader()!.getElement().textContent).toBe('Third card');
});
});
단위 테스트 API
ActionCardWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| click | - | 내부 버튼이나 링크에 마우스 이벤트를 트리거하여 클릭을 수행합니다. 프로그램 방식의 이벤트는 disabled 속성을 무시하므로 요소가 비활성화되어 있어도 리스너를 트리거한다는 점에 유의하세요. | params: 선택 사항인 마우스 이벤트 속성, 예를 들어 보조 키 ( ctrlKey, metaKey ) 또는 마우스 button |
| findContent | ElementWrapper | null | action card의 콘텐츠 요소를 반환합니다. | - |
| findDescription | ElementWrapper | null | action card의 설명 요소를 반환합니다. | - |
| findHeader | ElementWrapper | null | action card의 헤더 요소를 반환합니다. | - |
| findIcon | ElementWrapper | null | action card의 아이콘 슬롯을 찾습니다. | - |
| isDisabled | boolean | action card가 비활성화되었는지 여부를 반환합니다. | - |
통합 테스트 API
ActionCardWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findContent | ElementWrapper | action card의 콘텐츠 요소를 반환합니다. | - |
| findDescription | ElementWrapper | action card의 설명 요소를 반환합니다. | - |
| findHeader | ElementWrapper | action card의 헤더 요소를 반환합니다. | - |
| findIcon | ElementWrapper | action card의 아이콘 슬롯을 찾습니다. | - |
일반 지침
권장 사항 (Do)
- 구조화된 콘텐츠가 액션으로서 온전히 선택 가능해야 할 때 action card를 사용하세요.
- 카드가 트리거하는 액션의 유형을 강조하기 위해 아이콘을 사용하세요. 예를 들어 사용자를 앞으로 이동시키는 action card에는 arrow-right나 angle-right 아이콘을 사용할 수 있어요.
- 메인 애플리케이션의 배경 위에 바로 표시되는 실행 가능한 항목에는 default variant를 사용하세요.
- 다른 컴포넌트 안에 중첩되는 항목 (예: selectable artifact previews ) 에는 embedded variant를 사용하세요.
권장하지 않는 사항 (Don't)
- action card 안에는 대화형 요소를 배치하지 마세요.
- 선택에는 action card를 사용하지 말고 item card 를 사용하세요.
- 폼에서 콘텐츠를 제출하는 데 action card를 사용하지 마세요. 대신 button 을 사용하세요.
- 콘텐츠가 액션을 시작하지 않을 때는 action card를 사용하지 마세요.
기능 (Features)
-
Variant
- **Default: ** 페이지나 레이아웃의 최상위 수준에서 사용자들이 개별 항목으로 상호작용하는 개별 객체나 엔티티를 나타낼 때 사용합니다.
- **Embedded: ** 컨테이너 같은 다른 컴포넌트 안에 중첩되어 개별 항목을 표시할 때 사용합니다.
-
Header - 선택 사항
action card의 제목을 표시하려면 헤더를 사용하세요.
-
Description - 선택 사항
action card 전체 콘텐츠에 적용되는 설명이나 메타데이터 같은 보조 콘텐츠를 표시하는 데 사용할 수 있어요.
-
Icon - 선택 사항
action card는 카드의 상호작용성과 기대 동작을 강조하기 위해 아이콘을 포함할 수 있어요. 아이콘은 사용자가 카드를 선택했을 때 어떤 액션이 일어날지 이해하도록 돕는 시각적 단서 역할을 하며, 두 가지 위치를 사용할 수 있어요.
- Top: action card에 전체 너비 미디어가 포함되거나, 콘텐츠 길이가 서로 다른 카드들에서 아이콘 위치를 일관되게 유지해야 할 때 상단 아이콘 배치를 사용하세요. 아이콘은 카드의 상단에 고정되며 카드가 포함하는 콘텐츠의 양과 관계없이 그 위치를 유지해요. 이렇게 하면 텍스트 양이 다른 여러 카드를 표시할 때 예측 가능한 시각적 정렬이 만들어져요.
- Center: 미디어가 없는 텍스트 중심의 action card에는 중앙 아이콘 배치를 사용하세요. 아이콘은 카드의 콘텐츠와 세로로 정렬되며, 콘텐츠 높이에 따라 확장되고 축소돼요. 이렇게 하면 비슷한 콘텐츠 구조를 가진 카드들에서 시각적 균형이 만들어져요.
-
Content - 선택 사항
action card의 주요 콘텐츠를 위한 영역입니다.
상태 (States)
-
Disabled
사용자가 액션을 시작하지 못하게 하거나, 항목을 활성화하려면 사용자가 여전히 액션을 수행해야 할 때 disabled 상태를 사용하세요.
작성 지침
일반 작성 지침
-
문장 케이스(sentence case)를 사용하되, 문맥에 맞게 고유명사와 브랜드명은 올바르게 대문자로 유지하세요.
-
현재 시제 동사와 능동태를 사용하세요.
-
글에서 please, thank you, 줄임표 ( ... ), 앰퍼샌드 ( & ), e.g., i.e., etc. 는 사용하지 마세요.
-
방향을 가리키는 표현은 피하세요.
- 예: above 대신 previous를, below 대신 following을 사용하세요.
-
기기에 독립적인 언어를 사용하세요.
- 예: click 대신 choose 또는 select를 사용하세요.
접근성 지침
일반 접근성 지침
- 각 컴포넌트에 대해 대체 텍스트와 ARIA(접근 가능한 리치 인터넷 애플리케이션) 영역에 대한 지침을 따르세요.
- 애플리케이션의 언어 맥락에 맞게 ARIA 레이블을 정의하세요.
- 역할(role)과 랜드마크에 불필요한 마크업을 추가하지 마세요. 각 컴포넌트의 지침을 따르세요.
- 모든 콘텐츠에 논리적이고 예측 가능한 순서로 키보드 기능을 제공하세요. 정보의 흐름이 자연스러워야 해요.