WebberUI

商品快速預覽

商品卡點開快速預覽彈窗:圖片切換、規格選擇、加入購物車。

商品卡 hover 浮現快速預覽按鈕,點擊後卡片以 layoutId morph 展開成置中彈窗:左側圖廊縮圖切換、右側顏色色票與尺寸選擇、數量調整,加入購物車後按鈕變身成功回饋,適合電商列表頁縮短購買路徑。

載入預覽⋯

安裝

npx shadcn@latest add https://webberui.com/r/product-quick-view.json

或在 components.json 設定 registries 後,改用 @webberui/product-quick-view 安裝。

安裝依賴後,從 registry JSON(/r/product-quick-view.jsonfiles[0].content)複製 product-quick-view.tsx 原始碼到你的 components/ui/ 目錄:

npm install motion lucide-react clsx tailwind-merge

使用

import { ProductQuickView } from "@/components/ui/product-quick-view";

<ProductQuickView
  product={{
    name: "輕量針織跑鞋",
    price: 2680,
    originalPrice: 3280,
    rating: 4.5,
    badge: "新品",
    emoji: "👟",
    colors: [
      { name: "霧灰藍", hue: 210 },
      { name: "珊瑚橘", hue: 16 },
    ],
    sizes: ["US 8", "US 9", "US 10"],
  }}
  onAddToCart={({ color, size, quantity }) => {
    console.log(color, size, quantity);
  }}
/>

Props

Prop型別預設值說明
productQuickViewProduct商品資料(見下表)
onAddToCart(selection: { color: string; size: string; quantity: number }) => void加入購物車回呼,回傳所選顏色、尺寸與數量
classNamestring透傳到卡片外層容器

QuickViewProduct 欄位:

欄位型別預設值說明
namestring商品名稱
pricenumber售價(新台幣)
originalPricenumber劃線原價,提供時顯示折扣百分比
descriptionstring商品簡述,顯示於彈窗價格下方
ratingnumber星等評分(0–5)
badgestring卡片角落籤條文字,例如「新品」
emojistring"🛍️"假商品圖中央的 emoji 圖示
colors{ name: string; hue: number }[]可選顏色清單,hue 產生色票與漸層假圖
sizesstring[]可選尺寸清單

可及性

  • 彈窗使用 role="dialog"aria-modal,開啟時關閉按鈕自動聚焦,按 Esc 或點擊遮罩皆可關閉
  • 快速預覽按鈕在鍵盤 focus-visible 時同樣浮現,不依賴滑鼠 hover
  • 色票、尺寸與縮圖按鈕皆有 aria-label 或可讀文字,並以 aria-pressed 標示選中狀態
  • 數量與加入購物車狀態以 aria-live="polite" 播報變化
  • 使用者系統開啟「減少動態效果」時,停用 morph 展開動畫,改為單純淡入淡出

On this page