Taster

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

Plan table

Pricing

Grouped feature rows, the recommended column marked quietly, and cell formats for check, dash, limit and number in neutral ink.

내 사이트에서 가져오기

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

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

내 앱에 넣기

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

언제 쓰나요

  • Plan comparison tableGrouped feature rows, the recommended column marked quietly, and cell formats for check, dash, limit and number in neutral ink.

대신 없애 주는 AI 티

  • Colored status dot (AC-08)
  • Glyph inside a filled circle (AC-11)

정보

설치할 패키지
tailwindcss
라이선스
MIT
코드 보기
import * as React from 'react'
import { cn } from '../blocks/_cn'
import { safeHref } from '../blocks/_url'

// Plan table: plans as columns, features as grouped rows, so a buyer can check one feature across
// every plan. Follows patterns/plan-comparison-table: neutral ink only, a line check for included, a
// short drawn rule plus hidden text for not included, limits written out, the recommended plan marked by
// one word and a slightly lighter column, never a wider or taller one.
// On phones the table does not scroll sideways: a row of plan buttons picks the one plan column shown
// beside the feature names, and every cell keeps its text for screen readers either way.
// Original code, MIT.

export type PlanCell = boolean | string

export interface PlanColumn {
  id: string
  name: string
  /** Formatted price, for example "$19". */
  price: string
  period?: string
  cta?: { label: string; href: string }
  recommended?: boolean
}

export interface PlanRow {
  label: string
  /** One short line under the label, for terms that need it. */
  note?: string
  values: Record<string, PlanCell>
}

export interface PlanGroup {
  title: string
  rows: PlanRow[]
}

export interface PlanTableProps extends React.HTMLAttributes<HTMLDivElement> {
  plans: PlanColumn[]
  groups: PlanGroup[]
  caption: string
  recommendedLabel?: string
  includedLabel?: string
  notIncludedLabel?: string
}

const KEEP = 'break-keep [overflow-wrap:break-word]'

function Check() {
  return (
    <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
      <path d="M5 13l4 4 10-10" />
    </svg>
  )
}

function Cell({ value, included, notIncluded }: { value: PlanCell; included: string; notIncluded: string }) {
  if (value === true)
    return (
      <span className="inline-flex h-[1.5em] items-center text-text">
        <Check />
        <span className="sr-only">{included}</span>
      </span>
    )
  if (value === false)
    return (
      <span className="inline-flex h-[1.5em] items-center text-text-subtle">
        <span aria-hidden className="block h-px w-3 bg-current" />
        <span className="sr-only">{notIncluded}</span>
      </span>
    )
  return <span className={cn('text-body tabular-nums text-text', KEEP)}>{value}</span>
}

export function PlanTable({
  plans,
  groups,
  caption,
  recommendedLabel = 'Recommended',
  includedLabel = 'Included',
  notIncludedLabel = 'Not included',
  className,
  ...props
}: PlanTableProps) {
  const initial = plans.find((p) => p.recommended)?.id ?? plans[0]?.id
  const [shown, setShown] = React.useState(initial)
  // A column is hidden below md unless it is the one picked.
  const col = (id: string) => (id === shown ? '' : 'hidden md:table-cell')
  const rec = (p: PlanColumn) => (p.recommended ? 'bg-bg-sunken' : '')

  return (
    <div className={cn('min-w-0', className)} {...props}>
      <div role="group" aria-label="Plan to show" className="mb-4 flex flex-wrap gap-2 md:hidden">
        {plans.map((p) => (
          <button
            key={p.id}
            type="button"
            aria-pressed={p.id === shown}
            onClick={() => setShown(p.id)}
            className={cn(
              'h-11 rounded-md border px-4 text-body font-medium outline-none transition-colors duration-press ease-out focus-visible:ring-2 focus-visible:ring-ring',
              p.id === shown ? 'border-text bg-bg-sunken text-text' : 'border-border text-text-muted hover:text-text',
            )}
          >
            {p.name}
          </button>
        ))}
      </div>
      <table className="w-full border-collapse text-left md:table-fixed">
        <caption className="sr-only">{caption}</caption>
        <thead>
          <tr className="border-b border-border">
            <td className="w-[44%] p-0 md:w-[30%]" />
            {plans.map((p) => (
              <th key={p.id} scope="col" className={cn('px-4 pb-5 pt-4 align-bottom font-reg', col(p.id), rec(p))}>
                <span className="block h-5 text-label text-text-muted">{p.recommended ? recommendedLabel : ''}</span>
                <span className={cn('mt-1 block text-title font-semibold text-text', KEEP)}>{p.name}</span>
                <span className="mt-1 block text-body tabular-nums text-text-muted">
                  <span className="text-text">{p.price}</span>
                  {p.period ? ` ${p.period}` : ''}
                </span>
                {p.cta ? (
                  <a
                    href={safeHref(p.cta.href)}
                    className={cn(
                      'mt-4 inline-flex h-11 w-full items-center justify-center rounded-md px-3 text-body font-medium outline-none transition-[opacity,colors] duration-press ease-out focus-visible:ring-2 focus-visible:ring-ring desk:h-9',
                      p.recommended ? 'bg-accent text-accent-fg hover:opacity-90' : 'border border-border text-text hover:border-text-subtle',
                    )}
                  >
                    {p.cta.label}
                  </a>
                ) : null}
              </th>
            ))}
          </tr>
        </thead>
        {groups.map((g) => (
          <tbody key={g.title}>
            <tr>
              <th scope="colgroup" colSpan={plans.length + 1} className="px-0 pb-2 pt-8 text-label font-medium text-text-subtle">
                {g.title}
              </th>
            </tr>
            {g.rows.map((r) => (
              <tr key={r.label} className="border-b border-border-soft">
                <th scope="row" className="py-3 pr-4 align-top font-reg">
                  <span className={cn('block text-body text-text', KEEP)}>{r.label}</span>
                  {r.note ? <span className={cn('mt-0.5 block text-label text-text-subtle', KEEP)}>{r.note}</span> : null}
                </th>
                {plans.map((p) => (
                  <td key={p.id} className={cn('px-4 py-3 align-top', col(p.id), rec(p))}>
                    <Cell value={r.values[p.id] ?? false} included={includedLabel} notIncluded={notIncludedLabel} />
                  </td>
                ))}
              </tr>
            ))}
          </tbody>
        ))}
      </table>
    </div>
  )
}