RendyUI English

区块 / Customer summary

Customer summary

电商 · React / TypeScript Free

录制演示

Customer summary 实现预览

源码

customers-summary.tsx
/* Customer summary — free block published by UI Stacks (public page source).
   Kept verbatim: the author publishes this block free, in full, at https://uistacks.dev/blocks/customers-summary
   See replica/README.md for provenance. */
"use client";

import { useId } from "react";
import { StatCard } from "../components/stat-card";
import { Leaderboard, type LeaderboardPeriod } from "../components/leaderboard";
import { AvatarStack } from "../components/avatar-stack";

/* ── Sample data: replace with your own ─────────────────────── */

const STORE = "Stacks Shop";
const MONTHS = ["Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov"];

type Customer = { id: string; name: string; city: string; avatar?: string; spent: number; month: number; vip?: boolean };

/** Lifetime spend and spend this month (Nov 1 – 12), in dollars. */
const CUSTOMERS: Customer[] = [
  { id: "sofia", name: "Sofia Alvarez", city: "Seattle, WA", avatar: "/avatars/sofia-alvarez.png", spent: 1284.4, month: 412.6, vip: true },
  { id: "noah", name: "Noah Patel", city: "Atlanta, GA", spent: 1046.8, month: 210.7, vip: true },
  { id: "hannah", name: "Hannah Brooks", city: "Brooklyn, NY", spent: 902.5, month: 149.9, vip: true },
  { id: "daniel", name: "Daniel Kim", city: "San Diego, CA", spent: 618.2, month: 225.3 },
  { id: "marcus", name: "Marcus Reed", city: "Denver, CO", avatar: "/avatars/marcus-reed.png", spent: 412.3, month: 52.9 },
  { id: "lucas", name: "Lucas Martin", city: "Boston, MA", spent: 387.6, month: 123.4 },
  { id: "priya", name: "Priya Shah", city: "Chicago, IL", spent: 218.4, month: 202.8 },
];

/** Monthly figures, December to November. The last point is the headline number. */
const STATS = [
  { label: "Customers", value: 1284, delta: 8.2, data: [1012, 1030, 1041, 1066, 1080, 1102, 1121, 1139, 1160, 1188, 1214, 1284] },
  { label: "Repeat customers", value: 38.4, format: (v: number) => `${v.toFixed(1)}%`, delta: 2.1, deltaLabel: "2.1 pts", data: [31.2, 31.8, 32.5, 32.1, 33.4, 34, 34.6, 35.1, 35.9, 36.2, 36.3, 38.4] },
  { label: "Average order", value: 72.4, format: (v: number) => money(v), delta: -1.8, data: [69.2, 70.1, 71.4, 70.6, 72.2, 73.8, 74.1, 73.6, 74.4, 73.9, 73.7, 72.4] },
  { label: "Lifetime spend", value: 318.4, format: (v: number) => money(v), delta: 4.6, data: [262.1, 267.5, 271.9, 276.2, 281.4, 285, 289.7, 294.3, 299.8, 303.6, 304.4, 318.4] },
];

/* ── Helpers ────────────────────────────────────────────────── */

const money = (v: number) => v.toLocaleString("en-US", { style: "currency", currency: "USD" });
const money0 = (v: number) => v.toLocaleString("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

/** Top six by spend for each period; delta is places moved since last month. */
const top = (key: "month" | "spent") => [...CUSTOMERS].sort((a, b) => b[key] - a[key]).slice(0, 6);
const MOVES: Record<string, number> = { sofia: 0, daniel: 2, noah: -1, priya: 3, hannah: -2, lucas: 0 };
const PERIODS: LeaderboardPeriod[] = [
  { id: "month", label: "Nov", rows: top("month").map((c) => ({ id: c.id, name: c.name, avatar: c.avatar, meta: c.city, score: c.month, delta: MOVES[c.id] })) },
  { id: "year", label: "2026", rows: top("spent").map((c) => ({ id: c.id, name: c.name, avatar: c.avatar, meta: c.city, score: c.spent })) },
];
const VIPS = CUSTOMERS.filter((c) => c.vip);

/* ── The block ──────────────────────────────────────────────── */

/** How many customers you have and how they buy, over a ranked list of the top spenders. */
export default function CustomersSummaryBlock({ className = "" }: { className?: string }) {
  const titleId = useId();

  return (
    <section aria-labelledby={titleId} className={"@container w-full min-w-0 " + className}>
      <div className="flex flex-col gap-4">
        <header className="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 px-1">
          <div className="min-w-0">
            <h2 id={titleId} className="text-[15px] font-medium leading-5 text-fg">
              Customers
            </h2>
            <p className="mt-0.5 text-[13px] leading-5 text-fg-muted">{STORE} · November 2026</p>
          </div>
          <span className="flex items-center gap-2 text-[13px] leading-5 text-fg-muted">
            {VIPS.length} VIPs
            <AvatarStack size={24} people={VIPS.map((c) => ({ id: c.id, name: c.name, src: c.avatar, meta: money0(c.spent) }))} aria-label={`${VIPS.length} VIP customers`} />
          </span>
        </header>

        <div className="grid grid-cols-1 gap-4 @min-[1024px]:grid-cols-2">
          <div className="grid grid-cols-1 gap-4 @min-[480px]:grid-cols-2">
            {STATS.map((s) => (
              <StatCard key={s.label} label={s.label} value={s.value} format={s.format} delta={s.delta} deltaLabel={s.deltaLabel} comparison="vs October" data={s.data} labels={MONTHS} />
            ))}
          </div>
          <Leaderboard title="Top customers" description={`By spend · ${STORE}`} periods={PERIODS} format={money0} scoreLabel="spent" />
        </div>
      </div>
    </section>
  );
}

使用说明

把 TSX 加入 React 项目,并安装组件引用的依赖。页面样式依赖 Tailwind CSS 与 主题变量。

包依赖 · react

共享源码 · avatar-stack.tsx、leaderboard.tsx、stat-card.tsx