SunUI
创始会员$79 终身更新,1月11日截止领取名额
免费点按

结果标记

SunUI 的结果标记(导出名称 Result,Stamp 是同一个组件的旧名):放在结果发生的位置,正面结果是一颗品牌专色的小圆片,带顶边高光,勾线描出后用弹簧落定一次;已结束、已过期或已售罄等负面结果用淡色文字。

适合使用的场景

  • 展示顾客操作的结果:已领取、已付款、中奖、已售罄、已结束
  • 自己编写的 block 需要 SunUI 风格的结果标记,又不想复制代码

注意事项

  • 放在布局中原本发生操作的位置(例如按钮原来的位置),绝不叠在其他内容上
  • 「推荐」「热门」这类不是结果的标签不要用它
  • 每张卡片只放一行结果;列表本身已经说明状态时,不要在每一项重复同样的状态

交给你的 agent 安装

一次复制就包含安装命令、使用时机、props 与设计规则。粘贴到 Claude Code、Cursor 或 Codex 即可。

用 CLI 安装

使用 shadcn CLI。源码会复制到你的项目中,每一行都由你掌控。

$ npx shadcn@latest add https://sunui.synvize.com/r/stamp.json

或手动安装

  1. 1. 安装依赖。
    $ npm install clsx tailwind-merge framer-motion
  2. 2. 如果还没有,在 lib/utils.ts 添加 cn 辅助函数。没有用 shadcn/ui?再加上 sunui-theme.css 提供颜色变量(做法)。然后复制组件代码。
    stamp.tsx
    "use client";
    
    import { motion, useReducedMotion } from "framer-motion";
    import type { CSSProperties, ReactNode } from "react";
    
    import { cn } from "@/lib/utils";
    
    /**
     * SunUI's result marker, Result: place it where the action happened (where the button was, in a status bar, next to a step), not over the content.
     * Positive result: a small disc in the brand accent colour with a top-edge highlight, the check drawn as a stroke, and the disc settling once with the pop spring.
     * Expired, ended, did not win: faded text with no icon.
     * shape decides what extra information comes with it, not the look:
     * - tick, box: text only (Copied, Claimed, Sold out)
     * - date: text plus a date (Paid 2026.11.06)
     * - seal: text plus a second line (Winner, tier name)
     * - chop: text (Invited, member name)
     * Do not use it for labels that are not results (Recommended, Popular).
     *
     * Since 2026-11-19 the primary name is Result; Stamp is the old name, the same component, so existing installs keep working.
     * The file name and registry name stay stamp, so the install command is unchanged.
     */
    export type ResultShape = "tick" | "box" | "seal" | "date" | "chop";
    /** positive: positive result; muted: expired, ended, did not win. vermilion and ink are old names, equal to positive and muted respectively */
    export type ResultTone = "positive" | "muted" | "vermilion" | "ink";
    export type ResultSize = "sm" | "md" | "lg";
    
    export interface ResultProps {
      children?: ReactNode;
      shape?: ResultShape;
      /** Defaults to positive */
      tone?: ResultTone;
      size?: ResultSize;
      /** No longer affects the look; kept for compatibility with old code */
      seed?: string | number;
      /** Date shown by date; also usable as the second line of seal when there is no sub */
      date?: Date | string | number;
      /** Second line of seal, e.g. a tier name */
      sub?: ReactNode;
      /** No longer affects the look; kept for compatibility with old code */
      filled?: boolean;
      /** Adds a strikethrough to mark it void */
      void?: boolean;
      /** When false, show immediately without the settle animation (e.g. the claimed state after a refresh) */
      appear?: boolean;
      delay?: number;
      className?: string;
      style?: CSSProperties;
    }
    
    // Same as pop in sunui-motion: the rebound of a small element settling once
    const pop = { type: "spring", stiffness: 620, damping: 20, mass: 0.8 } as const;
    
    const TEXT: Record<ResultSize, string> = { sm: "text-xs", md: "text-sm", lg: "text-base" };
    const DISC: Record<ResultSize, string> = { sm: "size-4", md: "size-[18px]", lg: "size-5" };
    const ICON: Record<ResultSize, string> = { sm: "size-2.5", md: "size-3", lg: "size-3.5" };
    
    function formatDate(value: Date | string | number) {
      const d = new Date(value);
      if (Number.isNaN(d.getTime())) return "";
      const p = (n: number) => String(n).padStart(2, "0");
      return `${d.getFullYear()}.${p(d.getMonth() + 1)}.${p(d.getDate())}`;
    }
    
    export function Result({
      children,
      shape = "box",
      tone = "positive",
      size = "md",
      date,
      sub,
      void: voided = false,
      appear = true,
      delay = 0,
      className,
      style,
    }: ResultProps) {
      const reduce = useReducedMotion() ?? false;
      const positive = tone === "positive" || tone === "vermilion";
      const animate = !reduce && appear;
      const second = shape === "seal" ? (sub ?? (date !== undefined ? formatDate(date) : null)) : shape === "date" && date !== undefined ? formatDate(date) : null;
    
      return (
        <motion.span
          aria-hidden="true"
          initial={animate ? { opacity: 0 } : false}
          animate={{ opacity: 1 }}
          exit={{ opacity: 0, transition: { duration: reduce ? 0 : 0.12 } }}
          transition={animate ? { duration: 0.15, ease: "easeOut", delay } : { duration: 0 }}
          style={style}
          className={cn(
            "pointer-events-none inline-flex items-center gap-1.5 leading-tight font-medium whitespace-nowrap",
            TEXT[size],
            positive ? "text-foreground" : "text-muted-foreground",
            className,
          )}
        >
          {positive && (
            <motion.span
              initial={animate ? { scale: 0.6 } : false}
              animate={{ scale: 1 }}
              transition={animate ? { ...pop, delay } : { duration: 0 }}
              className={cn(
                "grid shrink-0 place-items-center rounded-full",
                "bg-[color:var(--sunui-spot,var(--primary))] text-[color:var(--sunui-spot-foreground,var(--primary-foreground))]",
                "shadow-[inset_0_1px_0_rgb(255_255_255/0.22),0_1px_2px_rgb(0_0_0/0.12)]",
                DISC[size],
              )}
            >
              <svg viewBox="0 0 24 24" className={ICON[size]} fill="none" stroke="currentColor" strokeWidth={3} strokeLinecap="round" strokeLinejoin="round">
                <motion.path
                  d="M5 12.5l4.5 4.5L19 7.5"
                  initial={animate ? { pathLength: 0 } : false}
                  animate={{ pathLength: 1 }}
                  transition={animate ? { duration: 0.22, ease: [0.23, 1, 0.32, 1], delay: delay + 0.06 } : { duration: 0 }}
                />
              </svg>
            </motion.span>
          )}
          <span className={cn(voided && "line-through decoration-1")}>{children}</span>
          {second && <span className="font-mono font-normal text-muted-foreground tabular-nums">{second}</span>}
        </motion.span>
      );
    }
    
    /** Old name, equal to Result */
    export const Stamp = Result;
    export type StampShape = ResultShape;
    export type StampTone = ResultTone;
    export type StampSize = ResultSize;
    export type StampProps = ResultProps;