Taster

진단부품톤 고르기
부품 갤러리 / Stepper

Stepper

Timeline, stepper and calendar

Passed stages are filled dots, pending are empty rings, below target are faint dots, all in one row. A segmented bar fits signup and install flows.

내 사이트에서 가져오기

색을 고르면 아래 부품이 그 색으로 바뀝니다.

실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.

내 앱에 넣기

  1. 아직 npm 패키지가 없어서 Taster 리포를 받아 그 안의 명령을 씁니다. 내 앱 폴더가 들어 있는 폴더에서 한 번만 받습니다.

    git clone https://github.com/makim-414/taster.git && npm ci --prefix taster/packages/engine
  2. 내 앱 폴더에서 이 부품을 넣습니다. 부품 파일과 토큰 파일이 src/components/taster 에 들어갑니다.

    node ../taster/packages/engine/cli.mjs add blocks/stepper --from https://taster-six.vercel.app --dir src/components/taster
  3. 부품은 Tailwind 클래스로 그리고, Taster 프리셋이 그 클래스를 토큰에 연결합니다. Tailwind CSS 를 설치하고, tokens.css 를 앱 루트에서 한 번 불러온 뒤, 앱 루트에 이 설정을 둡니다. 프리셋이 없으면 빌드는 되어도 부품이 스타일 없이 나옵니다.

    // tailwind.config.cjs
    module.exports = {
      presets: [require('./src/components/taster/tailwind-preset.cjs')],
      content: ['./index.html', './src/**/*.{ts,tsx}'],
    };

    Tailwind v3 는 이 파일을 그대로 읽습니다. v4 는 Tailwind 를 불러오는 src/ 의 스타일시트 맨 위에 이 두 줄을 넣습니다.

    @import "tailwindcss";
    @config "../tailwind.config.cjs";

    tokens.css 는 :root 에 --bg, --text, --border, --accent 를 정의합니다. 내 앱의 스타일시트가 같은 이름을 뒤에서 다시 정의하면 그쪽 색이 이깁니다. 새 Vite 앱의 스타터 CSS 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.

언제 쓰나요

  • Stage dot progressPassed stages are filled dots, pending are empty rings, below target are faint dots, all in one row. A segmented bar fits signup and install flows.
  • Onboarding wizardA short multi-step flow with back, progress and one question per screen, optionally with a spotlight tour that lights one area at a time.

대신 없애 주는 AI 티

  • Colored status dot (AC-08)

정보

설치할 패키지
tailwindcss
라이선스
MIT
코드 보기
'use client'

import * as React from 'react'
import { cn } from './_cn'

// Stepper. Where someone is in a fixed sequence: done steps, the current step (aria-current="step") and the steps
// still ahead. Done steps show an outlined check, the current one a filled number in the accent token, upcoming
// ones a hairline ring with the number; connectors fill in ink as steps complete. Plain numbers, no "01".
// Horizontal for three to five short steps, vertical for longer flows or steps with descriptions.
// Pass onStepClick to let people go back to a finished step; upcoming steps are never clickable.

export interface StepperStep {
  id: string
  label: string
  description?: string
}

export interface StepperProps extends React.HTMLAttributes<HTMLOListElement> {
  steps: StepperStep[]
  /** Index of the current step. steps.length means every step is done. */
  current: number
  orientation?: 'horizontal' | 'vertical'
  onStepClick?: (index: number) => void
  label?: string
  stateLabels?: { done: string; current: string; upcoming: string }
}

function Marker({ index, state }: { index: number; state: 'done' | 'current' | 'upcoming' }) {
  return (
    <span
      aria-hidden="true"
      className={cn(
        'flex size-6 shrink-0 items-center justify-center rounded-full border text-label font-medium tabular-nums transition-colors duration-press',
        state === 'done' && 'border-text text-text',
        state === 'current' && 'border-transparent bg-accent text-accent-fg',
        state === 'upcoming' && 'border-border text-text-subtle',
      )}
    >
      {state === 'done' ? (
        <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2.25} strokeLinecap="round" strokeLinejoin="round">
          <path d="M5 13l4 4 10-10" />
        </svg>
      ) : (
        index + 1
      )}
    </span>
  )
}

export function Stepper({
  steps,
  current,
  orientation = 'horizontal',
  onStepClick,
  label = 'Progress',
  stateLabels = { done: 'completed', current: 'current step', upcoming: 'not started' },
  className,
  ...props
}: StepperProps) {
  const vertical = orientation === 'vertical'
  return (
    <ol aria-label={label} className={cn(vertical ? 'flex flex-col' : 'flex w-full items-start', className)} {...props}>
      {steps.map((s, i) => {
        const state = i < current ? 'done' : i === current ? 'current' : 'upcoming'
        const last = i === steps.length - 1
        const clickable = Boolean(onStepClick) && state === 'done'
        const text = (
          <span className={cn('flex min-w-0 flex-col gap-0.5', vertical ? 'pt-0.5' : 'items-center text-center')}>
            <span className={cn('text-sm', state === 'upcoming' ? 'text-text-muted' : 'font-medium text-text')}>{s.label}</span>
            {s.description && (vertical || state === 'current') && (
              <span className={cn('text-label text-text-muted', !vertical && 'hidden sm:block')}>{s.description}</span>
            )}
            <span className="sr-only">, {stateLabels[state]}</span>
          </span>
        )
        const line = (on: boolean, hide: boolean) => (
          <span aria-hidden="true" className={cn('h-px flex-1', hide ? 'invisible' : on ? 'bg-text' : 'bg-border')} />
        )
        const inner = vertical ? (
          <span className="flex items-start gap-3">
            <Marker index={i} state={state} />
            {text}
          </span>
        ) : (
          <span className="flex w-full flex-col items-center gap-2">
            <span className="flex w-full items-center gap-1.5">
              {line(i <= current, i === 0)}
              <Marker index={i} state={state} />
              {line(i < current, last)}
            </span>
            {text}
          </span>
        )
        return (
          <li
            key={s.id}
            aria-current={state === 'current' ? 'step' : undefined}
            className={cn('relative', vertical ? cn('flex flex-col', !last && 'pb-6') : 'flex min-w-0 flex-1 flex-col')}
          >
            {vertical && !last && (
              <span aria-hidden="true" className={cn('absolute bottom-1 left-3 top-7 w-px', state === 'done' ? 'bg-text' : 'bg-border')} />
            )}
            {clickable ? (
              <button
                type="button"
                onClick={() => onStepClick?.(i)}
                className="flex min-h-11 w-full rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
              >
                {inner}
              </button>
            ) : (
              inner
            )}
          </li>
        )
      })}
    </ol>
  )
}