Stepper는 다단계 워크플로우를 위한 compound composition 방식의, styled가 없는 접근성 높은 스테퍼 컴포넌트예요. 레이아웃과 스타일을 완전히 제어해 단계별 워크플로우를 만들 수 있어요.
출처: 문서
본문
기능 (Features)
- 11개의 하위 컴포넌트(
Root, List, Step, Item, Header, Number, Title, Separator, Panels, Panel, Content)로 구성된 compound 컴포넌트 API
List + Step + Panels + Panel을 통한 가로 레이아웃
Item + Step + Panel + Content를 통한 세로 레이아웃
Panels/Panel을 생략하는 단계(steps) 전용 모드
사용법 (Usage)
import { Stepper } from 'primereact/stepper';
<Stepper.Root>
<Stepper.List>
<Stepper.Step>
<Stepper.Header>
<Stepper.Number></Stepper.Number>
<Stepper.Title></Stepper.Title>
</Stepper.Header>
<Stepper.Separator />
</Stepper.Step>
</Stepper.List>
<Stepper.Panels>
<Stepper.Panel></Stepper.Panel>
</Stepper.Panels>
</Stepper.Root>
세로 레이아웃 (Vertical Layout)
세로 방향을 위해 각 단계 헤더와 패널을 Stepper.Item 안에 감싸세요. 올바른 세로 구조를 위해 Stepper.Panel 안에서 Stepper.Separator와 Stepper.Content를 사용해요.
<Stepper.Root>
<Stepper.Item>
<Stepper.Step>
<Stepper.Header>
<Stepper.Number></Stepper.Number>
<Stepper.Title></Stepper.Title>
</Stepper.Header>
</Stepper.Step>
<Stepper.Panel>
<Stepper.Separator />
<Stepper.Content></Stepper.Content>
</Stepper.Panel>
</Stepper.Item>
</Stepper.Root>
동작 (Behavior)
모션 애니메이션 (Motion Animation)
세로 레이아웃에서 패널 열림/닫힘 애니메이션을 설정하려면 Root에 motionProps를 사용해요.
<Stepper.Root motionProps={{ name: 'p-collapsible', cssVarPrefix: 'stepper-panel', hideStrategy: 'remove' }}></Stepper.Root>
애니메이션 단계(phases), CSS 변수, hide 전략에 대해서는 Motion 문서를 참고하세요.
다형적 렌더링 (Polymorphic Rendering)
아무 하위 컴포넌트에 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.
<Stepper.Root as="nav">
<Stepper.List as="ol">
<Stepper.Step as="li"></Stepper.Step>
</Stepper.List>
</Stepper.Root>
기본 요소: Root=div, List=div, Step=div, Item=div, Header=button, Number=span, Title=span, Separator=span, Panels=div, Panel=div, Content=div.
렌더 함수 자식 (Render Function Children)
Panel은 렌더 함수를 자식으로 받아 컴포넌트 인스턴스에 접근할 수 있게 해 줘요. 인스턴스는 stepper(루트 인스턴스), stepperitem(부모 아이템 인스턴스), active, activeValue를 노출해요.
<Stepper.Panel>{(instance) => <div>Step is {instance.active ? 'active' : 'inactive'}</div>}</Stepper.Panel>
패스 스루 (Pass Through)
<DocPTViewer name="stepper-pt" components={['StepperRoot']} />
API
StepperRoot
| Attribute |
Value |
data-scope |
"stepper" |
data-part |
"root" |
| Label |
Type |
Description |
| root |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| list |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the list's DOM element. |
| step |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the step's DOM element. |
| header |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the header's DOM element. |
| number |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the number's DOM element. |
| title |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the title's DOM element. |
| separator |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the separator's DOM element. |
| panels |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the panels's DOM element. |
| panel |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the panel's DOM element. |
| item |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the item's DOM element. |
| content |
StepperRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the content's DOM element. |
StepperList
| Label |
Type |
Description |
| root |
StepperListPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperItem
| Attribute |
Value |
data-scope |
"stepper" |
data-part |
"item" |
data-active |
Present when item is active |
| Label |
Type |
Description |
| root |
StepperItemPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperStep
| Attribute |
Value |
data-scope |
"stepper" |
data-part |
"step" |
data-active |
Present when step is active |
data-disabled |
Present when step is disabled |
| Label |
Type |
Description |
| root |
StepperStepPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"stepper" |
data-part |
"header" |
| Label |
Type |
Description |
| root |
StepperHeaderPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperNumber
| Label |
Type |
Description |
| root |
StepperNumberPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperTitle
| Label |
Type |
Description |
| root |
StepperTitlePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperSeparator
| Label |
Type |
Description |
| root |
StepperSeparatorPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperPanels
| Label |
Type |
Description |
| root |
StepperPanelsPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperPanel
| Attribute |
Value |
data-scope |
"stepper" |
data-part |
"panel" |
data-active |
Present when panel is active |
| Label |
Type |
Description |
| root |
StepperPanelPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
StepperContent
| Label |
Type |
Description |
| root |
StepperContentPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
접근성 (Accessibility)
스크린 리더 (Screen Reader)
Stepper 컨테이너는 tablist 역할로 정의돼요. 각 스테퍼 헤더는 tab 역할을 가지며 해당 스테퍼 콘텐츠 요소를 가리키는 aria-controls를 가져요. 각 스테퍼의 콘텐츠 요소는 tabpanel 역할, 헤더의 aria-controls와 일치하는 id, 그리고 접근 가능한 이름으로 헤더를 가리키는 aria-labelledby 참조를 가져요. 루트 요소에 aria-labelledby를 사용해 Stepper를 설명하는 요소를 지정할 수 있어요.
| Key |
Function |
tab |
Moves focus through the header. |
enter |
Activates the focused stepper header. |
space |
Activates the focused stepper header. |
더 알아보기 (Learn more)