Taster

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

KPI

Chart and KPI

Label, one large number, a small delta and a caption or comparison line. No icon box or gradient tile; delta uses sign and text, not tinted pills.

내 사이트에서 가져오기

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

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

내 앱에 넣기

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

언제 쓰나요

  • KPI stat tileLabel, one large number, a small delta and a caption or comparison line. No icon box or gradient tile; delta uses sign and text, not tinted pills.
  • Sourced metric bandThree or four real figures in a row with a source line, hierarchy by ink tone, not gradient. Each figure can open its calculation and source rows.
  • Outcome-led cardsEach card opens with its own measured result in large type, then one sentence of explanation. No icon tile, no repeated three-up icon row.
  • Dashboard zonesA KPI row on top and chart panels beneath, aligned to one tone and one shared panel header, instead of mixed colorful widgets.
  • Sourced answer blockA conclusion sentence first, then a table, chart or widget with headline number, then evidence, a confidence note, source chips and an as-of date.
  • Count-up numberA figure rolls to its value once when it enters the view, reserves its final width and gives assistive tech the end value only.

대신 없애 주는 AI 티

  • Glyph inside a filled circle (AC-11)
  • Row of three big stats (CMP-06)
  • Purple gradient (COL-01)
  • Empty value traces on screen (CPY-02)
  • Fake trust signals (CMP-08)
  • Rounded square icon tile (CMP-03)
  • Three icon cards in a row (LAY-02)
  • Flat gray card with a hairline border, everywhere (AC-14)
  • Rainbow of tinted boxes (COL-06)
  • Bento grid (LAY-05)
  • Generated copy voice (CPY-01)
  • The same entrance animation on every block (MOT-01)

정보

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

// Stat / KPI tile: label, value, delta, caption.
// Only the delta uses color, and only by direction. An empty value renders a middle dot, never a fake zero.
// Say what the delta is against in `sub` ("vs previous 30 days"); a change between two percentages is in %p.

export type StatDeltaDir = 'up' | 'down' | 'flat'

export interface StatDelta {
  value: string
  dir: StatDeltaDir
  /** For metrics where up is not simply good (share, rank, cost): caret and sign stay, color goes. */
  neutral?: boolean
}

const DELTA_TONE: Record<StatDeltaDir, string> = {
  up: 'text-delta-up',
  down: 'text-delta-down',
  flat: 'text-text-muted',
}
const DELTA_WORD: Record<StatDeltaDir, string> = { up: 'up', down: 'down', flat: 'unchanged' }

export interface StatProps extends React.HTMLAttributes<HTMLDivElement> {
  label: string
  value: string | number
  delta?: StatDelta
  sub?: string
}

function CaretIcon({ dir }: { dir: StatDeltaDir }) {
  return (
    <svg
      width="14"
      height="14"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth={1.75}
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
      className="shrink-0"
    >
      {dir === 'up' ? (
        <path d="M5 14l7-7 7 7" />
      ) : dir === 'down' ? (
        <path d="M5 10l7 7 7-7" />
      ) : (
        <path d="M6 12h12" />
      )}
    </svg>
  )
}

export const Stat = React.forwardRef<HTMLDivElement, StatProps>(
  ({ label, value, delta, sub, className, ...props }, ref) => (
    <div
      ref={ref}
      className={cn('bg-bg-elev border border-border rounded-lg p-5', className)}
      {...props}
    >
      <div className="text-sm text-text-subtle">{label}</div>
      <div className="mt-2 text-h2 font-semibold tabular-nums tracking-[-0.02em]">{value}</div>
      {(delta || sub) && (
        <div className="mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs">
          {delta && (
            <span
              className={cn(
                'inline-flex items-center gap-1 whitespace-nowrap tabular-nums',
                delta.neutral ? 'text-text-muted' : DELTA_TONE[delta.dir],
              )}
            >
              <CaretIcon dir={delta.dir} />
              <span className="sr-only">{DELTA_WORD[delta.dir]} </span>
              {delta.value}
            </span>
          )}
          {sub && <span className="whitespace-nowrap text-text-muted">{sub}</span>}
        </div>
      )}
    </div>
  ),
)
Stat.displayName = 'Stat'