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

스텝

원문 보기 위키 갱신

스텝 (Steps)

프로세스의 일련의 단계를 사용자에게 안내할 때 사용하는 컴포넌트입니다. 단계의 진행 상태를 시각적으로 표시하고, 이전/다음 이동을 지원합니다.

출처: 문서

본문

해부 구조 (Anatomy)

<Steps.Root>
  <Steps.List>
    <Steps.Item>
      <Steps.Trigger>
        <Steps.Indicator />
      </Steps.Trigger>
      <Steps.Separator />
    </Steps.Item>
  </Steps.List>
  <Steps.Content />
  <Steps.CompletedContent />
  <Steps.PrevTrigger />
  <Steps.NextTrigger />
</Steps.Root>

예시 (Examples)

기본 (Basic)

다음은 Steps 컴포넌트의 기본 예시입니다.

import { Steps } from '@ark-ui/react/steps'
import button from 'styles/button.module.css'
import styles from 'styles/steps.module.css'

const items = [
  { value: 'first', title: 'First', description: 'Contact Info' },
  { value: 'second', title: 'Second', description: 'Date & Time' },
  { value: 'third', title: 'Third', description: 'Select Rooms' },
]

export const Basic = () => {
  return (
    <Steps.Root className={styles.Root} count={items.length}>
      <Steps.List className={styles.List}>
        {items.map((item, index) => (
          <Steps.Item className={styles.Item} key={index} index={index}>
            <Steps.Trigger className={styles.Trigger}>
              <Steps.Indicator className={styles.Indicator}>{index + 1}</Steps.Indicator>
              <span>{item.title}</span>
            </Steps.Trigger>
            <Steps.Separator className={styles.Separator} />
          </Steps.Item>
        ))}
      </Steps.List>

      {items.map((item, index) => (
        <Steps.Content className={styles.Content} key={index} index={index}>
          {item.title} - {item.description}
        </Steps.Content>
      ))}

      <Steps.CompletedContent className={styles.CompletedContent}>
        Steps Complete - Thank you for filling out the form!
      </Steps.CompletedContent>

      <div className={styles.Actions}>
        <Steps.PrevTrigger className={button.Root}>Back</Steps.PrevTrigger>
        <Steps.NextTrigger className={button.Root} data-variant="solid">
          Next
        </Steps.NextTrigger>
      </div>
    </Steps.Root>
  )
}

제어 (Controlled)

RootProvider 컴포넌트를 사용하면 step prop과 onStepChange 이벤트를 이용해 활성화된 단계를 제어할 수 있습니다.

import { Steps } from '@ark-ui/react/steps'
import { useState } from 'react'
import button from 'styles/button.module.css'
import styles from 'styles/steps.module.css'

const items = [
  { value: 'first', title: 'First', description: 'Contact Info' },
  { value: 'second', title: 'Second', description: 'Date & Time' },
  { value: 'third', title: 'Third', description: 'Select Rooms' },
]

export const Controlled = () => {
  const [step, setStep] = useState(0)

  return (
    <div className="stack">
      <output>current step: {step + 1}</output>

      <Steps.Root
        className={styles.Root}
        count={items.length}
        step={step}
        onStepChange={(details) => setStep(details.step)}
      >
        <Steps.List className={styles.List}>
          {items.map((item, index) => (
            <Steps.Item className={styles.Item} key={index} index={index}>
              <Steps.Trigger className={styles.Trigger}>
                <Steps.Indicator className={styles.Indicator}>{index + 1}</Steps.Indicator>
                <span>{item.title}</span>
              </Steps.Trigger>
              <Steps.Separator className={styles.Separator} />
            </Steps.Item>
          ))}
        </Steps.List>

        {items.map((item, index) => (
          <Steps.Content className={styles.Content} key={index} index={index}>
            {item.title} - {item.description}
          </Steps.Content>
        ))}

        <Steps.CompletedContent className={styles.CompletedContent}>
          Steps Complete - Thank you for filling out the form!
        </Steps.CompletedContent>

        <div className={styles.Actions}>
          <Steps.PrevTrigger className={button.Root}>Back</Steps.PrevTrigger>
          <Steps.NextTrigger className={button.Root} data-variant="solid">
            Next
          </Steps.NextTrigger>
        </div>
      </Steps.Root>
    </div>
  )
}

루트 프로바이더 (Root Provider)

스텝을 제어하는 또 다른 방법은 RootProvider 컴포넌트와 useSteps 훅을 사용하는 것입니다. 이렇게 하면 컴포넌트 외부에서 상태와 메서드에 접근할 수 있습니다.

import { Steps, useSteps } from '@ark-ui/react/steps'
import button from 'styles/button.module.css'
import styles from 'styles/steps.module.css'

const items = [
  { value: 'first', title: 'First', description: 'Contact Info' },
  { value: 'second', title: 'Second', description: 'Date & Time' },
  { value: 'third', title: 'Third', description: 'Select Rooms' },
]

export const RootProvider = () => {
  const steps = useSteps({ count: items.length })

  return (
    <div className="stack">
      <output>current step: {steps.value + 1}</output>

      <Steps.RootProvider className={styles.Root} value={steps}>
        <Steps.List className={styles.List}>
          {items.map((item, index) => (
            <Steps.Item className={styles.Item} key={index} index={index}>
              <Steps.Trigger className={styles.Trigger}>
                <Steps.Indicator className={styles.Indicator}>{index + 1}</Steps.Indicator>
                <span>{item.title}</span>
              </Steps.Trigger>
              <Steps.Separator className={styles.Separator} />
            </Steps.Item>
          ))}
        </Steps.List>

        {items.map((item, index) => (
          <Steps.Content className={styles.Content} key={index} index={index}>
            {item.title} - {item.description}
          </Steps.Content>
        ))}

        <Steps.CompletedContent className={styles.CompletedContent}>
          Steps Complete - Thank you for filling out the form!
        </Steps.CompletedContent>

        <div className={styles.Actions}>
          <Steps.PrevTrigger className={button.Root}>Back</Steps.PrevTrigger>
          <Steps.NextTrigger className={button.Root} data-variant="solid">
            Next
          </Steps.NextTrigger>
        </div>
      </Steps.RootProvider>
    </div>
  )
}

세로형 (Vertical)

orientation prop을 사용하면 스텝을 세로로 표시할 수 있습니다.

import { Steps } from '@ark-ui/react/steps'
import button from 'styles/button.module.css'
import styles from 'styles/steps.module.css'

const items = [
  { value: 'first', title: 'First', description: 'Contact Info' },
  { value: 'second', title: 'Second', description: 'Date & Time' },
  { value: 'third', title: 'Third', description: 'Select Rooms' },
]

export const Vertical = () => {
  return (
    <Steps.Root className={styles.Root} count={items.length} orientation="vertical">
      <Steps.List className={styles.List}>
        {items.map((item, index) => (
          <Steps.Item className={styles.Item} key={index} index={index}>
            <Steps.Trigger className={styles.Trigger}>
              <Steps.Indicator className={styles.Indicator}>{index + 1}</Steps.Indicator>
              <span>{item.title}</span>
            </Steps.Trigger>
            <Steps.Separator className={styles.Separator} />
          </Steps.Item>
        ))}
      </Steps.List>

      {items.map((item, index) => (
        <Steps.Content className={styles.Content} key={index} index={index}>
          <div className="vstack">
            <span>
              {item.title} - {item.description}
            </span>
            <div className={styles.Actions}>
              <Steps.PrevTrigger className={button.Root}>Back</Steps.PrevTrigger>
              <Steps.NextTrigger className={button.Root} data-variant="solid">
                Next
              </Steps.NextTrigger>
            </div>
          </div>
        </Steps.Content>
      ))}

      <Steps.CompletedContent className={styles.CompletedContent}>
        <div className="vstack">
          <span>Steps Complete - Thank you for filling out the form!</span>
          <Steps.PrevTrigger className={button.Root}>Back</Steps.PrevTrigger>
        </div>
      </Steps.CompletedContent>
    </Steps.Root>
  )
}

API 참조 (API Reference)

Props

Root

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

count Type: number Required: false Default Value: undefined Description: 전체 단계 수입니다.

defaultStep Type: number Required: false Default Value: undefined Description: 렌더링 시 스테퍼(stepper)의 초기 값입니다. 스테퍼의 값을 직접 제어할 필요가 없을 때 사용합니다.

ids Type: ElementIds Required: false Default Value: undefined Description: 스테퍼 요소의 사용자 지정 id입니다.

isStepSkippable Type: (index: number) => boolean Required: false Default Value: () => false Description: 탐색 중 건너뛸 수 있는 단계인지 여부입니다. 건너뛸 수 있는 단계는 next/prev를 사용할 때 건너뜁니다.

isStepValid Type: (index: number) => boolean Required: false Default Value: () => true Description: 단계가 유효한지 여부입니다. 유효하지 않은 단계는 선형(linear) 모드에서 앞으로 이동을 차단합니다.

linear Type: boolean Required: false Default Value: undefined Description: true인 경우, 스테퍼는 사용자가 단계를 순서대로 완료해야 합니다.

onStepChange Type: (details: StepChangeDetails) => void Required: false Default Value: undefined Description: 값이 변경될 때 호출되는 콜백입니다.

onStepComplete Type: VoidFunction Required: false Default Value: undefined Description: 단계가 완료될 때 호출되는 콜백입니다.

onStepInvalid Type: (details: StepInvalidDetails) => void Required: false Default Value: undefined Description: 유효하지 않은 단계로 인해 탐색이 차단될 때 호출됩니다.

orientation Type: 'horizontal' | 'vertical' Required: false Default Value: "horizontal" Description: 스테퍼의 방향입니다.

step Type: number Required: false Default Value: undefined Description: 스테퍼의 제어(controlled) 값입니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: root data-orientation: 스텝의 방향입니다.

CompletedContent

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

Content

Props

index Type: number Required: true Default Value: undefined Description: undefined

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: content data-state: "open" | "closed" data-orientation: 콘텐츠의 방향입니다.

Indicator

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: indicator data-complete: 표시자(indicator) 값이 완료되었을 때 표시됩니다. data-current: 현재 상태일 때 표시됩니다. data-incomplete:

Item

Props

index Type: number Required: true Default Value: undefined Description: undefined

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: item data-orientation: 항목의 방향입니다. data-skippable:

List

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: list data-orientation: 리스트의 방향입니다.

NextTrigger

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

PrevTrigger

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

Progress

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: progress data-complete: 진행(progress) 값이 완료되었을 때 표시됩니다.

RootProvider

Props

value Type: UseStepsReturn Required: true Default Value: undefined Description: undefined

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

Separator

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: separator data-orientation: 구분선(separator)의 방향입니다. data-complete: 구분선 값이 완료되었을 때 표시됩니다. data-current: 현재 상태일 때 표시됩니다. data-incomplete:

Trigger

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합합니다.

데이터 속성 (Data Attributes)

data-scope: steps data-part: trigger data-state: "open" | "closed" data-orientation: 트리거의 방향입니다. data-complete: 트리거 값이 완료되었을 때 표시됩니다. data-current: 현재 상태일 때 표시됩니다. data-incomplete:

Context

API:

Property Type Description
value number 스테퍼의 값입니다.
percent number 스테퍼의 백분율입니다.
count number 전체 단계 수입니다.
hasNextStep boolean 스테퍼에 다음 단계가 있는지 여부입니다.
hasPrevStep boolean 스테퍼에 이전 단계가 있는지 여부입니다.
isCompleted boolean 스테퍼가 완료되었는지 여부입니다.
isStepValid (index: number) => boolean 특정 단계가 유효한지 확인합니다 (lazy evaluation).
isStepSkippable (index: number) => boolean 특정 단계를 건너뛸 수 있는지 확인합니다.
setStep (step: number) => void 스테퍼의 값을 설정하는 함수입니다.
goToNextStep VoidFunction 다음 단계로 이동하는 함수입니다.
goToPrevStep VoidFunction 이전 단계로 이동하는 함수입니다.
resetStep VoidFunction 스테퍼를 초기화하는 함수입니다.
getItemState (props: ItemProps) => ItemState 주어진 인덱스의 항목 상태를 반환합니다.

더 알아보기 (Learn more)