SunUI
創始會員NT$2,490 終身更新,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;