Taster

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

Step showcase

Feature and content section

Number steps only when order matters. A workflow is shown as tabs or a vertical accordion, the body in neutral tones, with one always-visible assistant dock below.

내 사이트에서 가져오기

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

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

내 앱에 넣기

  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 marketing/step-showcase --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 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.

언제 쓰나요

  • Step workflow sectionNumber steps only when order matters. A workflow is shown as tabs or a vertical accordion, the body in neutral tones, with one always-visible assistant dock below.

대신 없애 주는 AI 티

  • Tinted pill badge (AC-04)
  • Large colored glow shadow (COL-07)
  • 01 / 02 / 03 section numbers (LAY-03)

정보

설치할 패키지
tailwindcss
라이선스
MIT
출처
cult-ui Feature Carousel by Jordan Gilliam, MIT, https://github.com/nolly-studio/cult-ui
코드 보기
import * as React from 'react'
import { cn } from '../blocks/_cn'
import { useReducedMotion, useStyleOnce } from '../motion/_motion'

// Step showcase: one card with a row of numbered step buttons on top, the step's title and
// text at the top left, and the product's screens below, cut off by the card's bottom edge. The step
// advances by itself every few seconds and wraps; a step button jumps to its step and restarts the count.
// Source: "Feature Carousel" from cult-ui by Jordan Gilliam (https://github.com/nolly-studio/cult-ui,
// MIT), by way of a token rewrite first made for a template marketplace landing (written from a
// description of the original, not from its code).
// Changes: no motion/react, react-wrap-balancer or Tailwind animation plugins; enter and leave are CSS
// transitions on the motion tokens, all steps share one grid cell so the card never changes height,
// the step list is real buttons with aria-current="step" and no live region, and the count pauses
// while hovered, while keyboard focus is inside, while off screen, while the tab is hidden, and never
// runs under reduced motion. The original's frame around a panel around the card is now one card (CMP-02),
// and its click-anywhere-to-advance, mouse-follow glow and lime and purple colors are gone. The edge and
// shadow sit on the screenshot itself; a step with no screenshot draws a plain neutral fill of the same size.
// Upstream license: MIT, Copyright (c) 2023 Jordan-Gilliam. Full text in THIRD_PARTY_NOTICES.md.

const CSS = [
  '.dsg-step-card{background:linear-gradient(to bottom, var(--bg-elev), var(--bg) calc(var(--sp-16) * 3));background-color:var(--bg)}',
  '.dsg-step-slide{grid-area:1/1;visibility:hidden;transition:visibility 0s linear var(--dur-dropdown)}',
  '.dsg-step-slide[data-active="true"]{visibility:visible;transition:visibility 0s}',
  '.dsg-step-text{opacity:0;transform:translateY(var(--enter-offset));transition:opacity var(--dur-dropdown) var(--ease-out),transform var(--dur-dropdown) var(--ease-out)}',
  '.dsg-step-slide[data-active="true"] .dsg-step-text{opacity:1;transform:none;transition-delay:var(--dur-dropdown)}',
  '.dsg-step-stage{position:relative;aspect-ratio:1.25/1;min-width:0}',
  '.dsg-step-shot{position:absolute;opacity:0;transform:var(--from, scale(var(--enter-scale)));transition:opacity var(--dur-dropdown) var(--ease-out),transform calc(var(--dur-dropdown) * 1.5) var(--ease-out)}',
  '.dsg-step-shot img{display:block;width:100%;height:auto}',
  '.dsg-step-slide[data-active="true"] .dsg-step-shot{opacity:1;transform:none;transition-delay:var(--dur-dropdown)}',
  '.dsg-step-slide[data-active="true"] .dsg-step-shot:nth-child(2){transition-delay:calc(var(--dur-dropdown) + var(--stagger-step))}',
  '.dsg-step-slide[data-step="1"] .dsg-step-shot:nth-child(1){--from:translateX(calc(var(--enter-offset) * -2.5));top:8%;left:3%;width:66%}',
  '.dsg-step-slide[data-step="1"] .dsg-step-shot:nth-child(2){--from:translateX(calc(var(--enter-offset) * 2.5));top:0;right:4%;width:28%}',
  '.dsg-step-slide[data-step="2"] .dsg-step-shot:nth-child(1){top:4%;left:5%;width:28%}',
  '.dsg-step-slide[data-step="2"] .dsg-step-shot:nth-child(2){top:14%;right:3%;width:60%}',
  '.dsg-step-slide[data-step="3"] .dsg-step-shot:nth-child(1),.dsg-step-slide[data-step="4"] .dsg-step-shot:nth-child(1){top:6%;left:7%;width:86%}',
  '@media (min-width:640px){.dsg-step-stage{aspect-ratio:2/1}}',
  '@media (min-width:1024px){.dsg-step-stage{aspect-ratio:2.3/1}}',
].join('')

export interface ShowcasePicture {
  /** Screenshot URL. Leave empty to draw a neutral panel. */
  src?: string
  alt: string
  /** Width divided by height, used for the box before the image loads and for the empty panel. */
  aspect: number
}

export interface ShowcaseStep {
  id: string
  /** Short name on the step button. */
  name: string
  title: string
  body: string
  /** One or two pictures. Step 1 slides two in from the sides, step 2 fades two in, steps 3 and 4 show one wide. */
  pictures: ShowcasePicture[]
}

export interface StepShowcaseProps extends React.HTMLAttributes<HTMLDivElement> {
  steps: ShowcaseStep[]
  /** Milliseconds between automatic steps. */
  interval?: number
  /** Accessible name of the step list. */
  label?: string
}

function Check() {
  return (
    <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
      <path d="M20 6 9 17l-5-5" />
    </svg>
  )
}

export function StepShowcase({ steps, interval = 4000, label = 'Steps', className, ...props }: StepShowcaseProps) {
  useStyleOnce('dsg-step-css', CSS)
  const [index, setIndex] = React.useState(0)
  const [restart, setRestart] = React.useState(0)
  const [hover, setHover] = React.useState(false)
  const [focused, setFocused] = React.useState(false)
  const [onScreen, setOnScreen] = React.useState(false)
  const [tabHidden, setTabHidden] = React.useState(false)
  const reduced = useReducedMotion()
  const card = React.useRef<HTMLDivElement>(null)
  const paused = hover || focused || !onScreen || tabHidden || reduced

  React.useEffect(() => {
    if (paused || steps.length < 2) return
    const t = window.setTimeout(() => setIndex((n) => (n + 1) % steps.length), interval)
    return () => window.clearTimeout(t)
  }, [paused, index, restart, steps.length, interval])

  React.useEffect(() => {
    const el = card.current
    if (!el || typeof IntersectionObserver === 'undefined') {
      setOnScreen(true)
      return
    }
    const io = new IntersectionObserver(([e]) => setOnScreen(Boolean(e?.isIntersecting)), { threshold: 0.25 })
    io.observe(el)
    return () => io.disconnect()
  }, [])

  React.useEffect(() => {
    const sync = () => setTabHidden(document.hidden)
    sync()
    document.addEventListener('visibilitychange', sync)
    return () => document.removeEventListener('visibilitychange', sync)
  }, [])

  const jump = (n: number) => {
    setIndex(n)
    setRestart((r) => r + 1)
  }

  return (
    <div {...props} className={className}>
      <div
        ref={card}
        className="dsg-step-card grid gap-6 overflow-hidden rounded-3xl border border-border px-4 pt-5 sm:px-6 sm:pt-6 lg:px-8 lg:pt-8"
        onPointerEnter={() => setHover(true)}
        onPointerLeave={() => setHover(false)}
        onFocus={(e) => {
          // Only keyboard focus holds the count; a mouse press also focuses the button.
          if ((e.target as HTMLElement).matches(':focus-visible')) setFocused(true)
        }}
        onBlur={(e) => {
          if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false)
        }}
      >
        <nav aria-label={label}>
          <ol className="m-0 grid list-none grid-cols-2 gap-2 p-0 sm:flex sm:justify-center">
            {steps.map((step, n) => (
              <li key={step.id}>
                <button
                  type="button"
                  aria-current={n === index ? 'step' : undefined}
                  onClick={() => jump(n)}
                  className={cn(
                    'flex w-full items-center justify-center gap-2 whitespace-nowrap rounded-pill border px-3 text-body font-medium outline-none sm:w-auto',
                    'min-h-11 transition-[colors,transform] duration-dropdown ease-out active:scale-press focus-visible:ring-2 focus-visible:ring-ring',
                    n === index
                      ? 'border-transparent bg-accent text-accent-fg'
                      : cn('border-border-soft bg-bg-elev hover:text-text', n < index ? 'text-text-muted' : 'text-text-subtle'),
                  )}
                >
                  <span aria-hidden className="inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-pill border border-current text-label font-semibold tabular-nums">
                    {n < index ? <Check /> : n + 1}
                  </span>
                  <span>{step.name}</span>
                </button>
              </li>
            ))}
          </ol>
        </nav>

        <div className="grid min-w-0">
          {steps.map((step, n) => {
            const active = n === index
            return (
              <div
                key={step.id}
                className="dsg-step-slide grid min-w-0 grid-rows-[auto_1fr] gap-5"
                data-step={n + 1}
                data-active={active}
                aria-hidden={active ? undefined : true}
                {...(active ? {} : { inert: '' })}
              >
                <div className="dsg-step-text grid content-start gap-2" style={{ maxWidth: 'calc(var(--sp-16) * 8)' }}>
                  <h3 className="m-0 text-h2 font-semibold text-text [word-break:keep-all]">{step.title}</h3>
                  <p className="m-0 text-body text-text-muted [word-break:keep-all]">{step.body}</p>
                </div>
                <div className="dsg-step-stage">
                  {step.pictures.slice(0, 2).map((p, k) => (
                    <div key={k} className="dsg-step-shot" style={{ aspectRatio: String(p.aspect) }}>
                      {p.src ? (
                        <img src={p.src} alt={p.alt} loading="lazy" decoding="async" draggable={false} className="rounded-xl border border-border shadow-pop" />
                      ) : (
                        <div role="img" aria-label={p.alt} className="h-full w-full rounded-xl bg-bg-sunken" />
                      )}
                    </div>
                  ))}
                </div>
              </div>
            )
          })}
        </div>
      </div>
    </div>
  )
}