|
| 1 | +/** |
| 2 | + * 牌组卡 — 网格中的单张牌组卡片 |
| 3 | + * |
| 4 | + * @ai-context: 从 FlashcardsPage 拆出。负责牌组卡片的视觉呈现:顶部光泽/ |
| 5 | + * shimmer 扫光/到期脉冲/标题区/掌握进度条/底栏统计;点击、右键、长按等 |
| 6 | + * 交互回调由父级传入。掌握进度 = (total - due - new) / total。 |
| 7 | + * @ai-context: Extracted from FlashcardsPage. Renders a single deck card |
| 8 | + * (gloss / shimmer / due pulse / title / mastery progress / bottom stats); |
| 9 | + * click, context-menu and long-press callbacks are provided by the parent. |
| 10 | + * Mastery progress = (total - due - new) / total. |
| 11 | + */ |
| 12 | +import { motion } from 'framer-motion'; |
| 13 | +import { Tag } from '@/components/ui'; |
| 14 | +import { Layers, Clock } from 'lucide-react'; |
| 15 | +import { DeckCardDescription } from './DeckCardDescription'; |
| 16 | +import type { FlashcardDeck } from '@/types/models'; |
| 17 | + |
| 18 | +/** 牌组本地统计(由父级基于全部卡片实时计算) */ |
| 19 | +export interface DeckLocalStats { |
| 20 | + total: number; |
| 21 | + due: number; |
| 22 | + newCards: number; |
| 23 | +} |
| 24 | + |
| 25 | +/* ── 动画 variants ── */ |
| 26 | +const deckCardVariants = { |
| 27 | + hidden: { opacity: 0, y: 20, scale: 0.92 }, |
| 28 | + visible: { |
| 29 | + opacity: 1, y: 0, scale: 1, |
| 30 | + transition: { duration: 0.4, ease: [0.22, 0.61, 0.36, 1] as const }, |
| 31 | + }, |
| 32 | + exit: { opacity: 0, scale: 0.9, transition: { duration: 0.2 } }, |
| 33 | +}; |
| 34 | + |
| 35 | +export interface DeckCardProps { |
| 36 | + deck: FlashcardDeck; |
| 37 | + stats: DeckLocalStats; |
| 38 | + onClick: () => void; |
| 39 | + onContextMenu: (e: React.MouseEvent) => void; |
| 40 | + onPointerDown: () => void; |
| 41 | + onPointerUp: () => void; |
| 42 | + onPointerLeave: () => void; |
| 43 | +} |
| 44 | + |
| 45 | +export function DeckCard({ |
| 46 | + deck, stats, onClick, onContextMenu, onPointerDown, onPointerUp, onPointerLeave, |
| 47 | +}: DeckCardProps) { |
| 48 | + const progress = stats.total > 0 |
| 49 | + ? (stats.total - stats.due - stats.newCards) / stats.total : 0; |
| 50 | + const pct = Math.round(progress * 100); |
| 51 | + const hasDue = stats.due > 0; |
| 52 | + |
| 53 | + return ( |
| 54 | + <motion.div |
| 55 | + layout |
| 56 | + variants={deckCardVariants} |
| 57 | + whileHover={{ y: -4, transition: { duration: 0.2 } }} |
| 58 | + exit={deckCardVariants.exit} |
| 59 | + > |
| 60 | + <div |
| 61 | + className="group relative flex flex-col gap-3 p-kb-md rounded-[var(--kb-radius-md)] |
| 62 | + bg-bg-secondary/60 backdrop-blur-xl border border-border/30 |
| 63 | + hover:border-flashcard/30 cursor-pointer overflow-hidden |
| 64 | + transition-colors duration-300" |
| 65 | + onClick={onClick} |
| 66 | + onContextMenu={onContextMenu} |
| 67 | + onPointerDown={onPointerDown} |
| 68 | + onPointerUp={onPointerUp} |
| 69 | + onPointerLeave={onPointerLeave} |
| 70 | + > |
| 71 | + {/* ── 卡片顶部光泽 ── */} |
| 72 | + <div className="absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity duration-500 pointer-events-none" |
| 73 | + style={{ |
| 74 | + background: 'linear-gradient(135deg, rgba(123,196,184,0.06) 0%, transparent 50%, rgba(123,196,184,0.03) 100%)', |
| 75 | + }} |
| 76 | + /> |
| 77 | + {/* ── shimmer 扫光 ── */} |
| 78 | + <div className="absolute inset-0 -translate-x-full group-hover:translate-x-full transition-transform duration-[1.2s] ease-in-out pointer-events-none" |
| 79 | + style={{ |
| 80 | + background: 'linear-gradient(90deg, transparent 0%, rgba(123,196,184,0.06) 50%, transparent 100%)', |
| 81 | + }} |
| 82 | + /> |
| 83 | + |
| 84 | + {/* ── 到期脉冲指示 ── */} |
| 85 | + {hasDue && ( |
| 86 | + <motion.div |
| 87 | + className="absolute top-3 right-3 w-2 h-2 rounded-full bg-flashcard" |
| 88 | + animate={{ scale: [1, 1.4, 1], opacity: [0.8, 0.4, 0.8] }} |
| 89 | + transition={{ duration: 2, repeat: Infinity, ease: 'easeInOut' }} |
| 90 | + /> |
| 91 | + )} |
| 92 | + |
| 93 | + {/* ── 标题区 ── */} |
| 94 | + <div className="flex items-start justify-between gap-2 relative z-10"> |
| 95 | + <div className="flex-1 min-w-0"> |
| 96 | + <div className="flex items-center gap-2"> |
| 97 | + {deck.color && ( |
| 98 | + <motion.span |
| 99 | + className="w-2.5 h-2.5 rounded-kb-full flex-shrink-0 shadow-sm" |
| 100 | + style={{ backgroundColor: deck.color }} |
| 101 | + whileHover={{ scale: 1.5 }} |
| 102 | + /> |
| 103 | + )} |
| 104 | + <h3 className="text-b1 font-semibold text-text-primary truncate">{deck.name}</h3> |
| 105 | + </div> |
| 106 | + <DeckCardDescription description={deck.description} /> |
| 107 | + </div> |
| 108 | + <Tag color="flashcard">{stats.total} 卡</Tag> |
| 109 | + </div> |
| 110 | + |
| 111 | + {/* ── 进度条 ── */} |
| 112 | + <div className="relative z-10"> |
| 113 | + <div className="flex items-center justify-between mb-1.5"> |
| 114 | + <span className="text-c1 text-text-tertiary">已掌握</span> |
| 115 | + <motion.span |
| 116 | + className="text-c1 font-medium text-flashcard tabular-nums" |
| 117 | + key={pct} |
| 118 | + initial={{ opacity: 0.5, y: 4 }} |
| 119 | + animate={{ opacity: 1, y: 0 }} |
| 120 | + transition={{ duration: 0.3 }} |
| 121 | + > |
| 122 | + {pct}% |
| 123 | + </motion.span> |
| 124 | + </div> |
| 125 | + <div className="h-1.5 rounded-kb-full bg-bg-tertiary/80 overflow-hidden"> |
| 126 | + <motion.div |
| 127 | + className="h-full rounded-kb-full relative overflow-hidden" |
| 128 | + style={{ background: 'linear-gradient(90deg, #7BC4B8, #5BAFA2)' }} |
| 129 | + initial={{ width: 0 }} |
| 130 | + animate={{ width: `${pct}%` }} |
| 131 | + transition={{ duration: 0.8, ease: [0.25, 0.1, 0.25, 1] as const, delay: 0.3 }} |
| 132 | + > |
| 133 | + {/* 进度条流光 */} |
| 134 | + <div className="absolute inset-0 animate-[kb-progress-shine_2s_ease-in-out_infinite]" |
| 135 | + style={{ |
| 136 | + background: 'linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.3) 50%, transparent 100%)', |
| 137 | + }} |
| 138 | + /> |
| 139 | + </motion.div> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + |
| 143 | + {/* ── 底栏 ── */} |
| 144 | + <div className="flex items-center justify-between text-c1 text-text-tertiary pt-1 border-t border-border/20 relative z-10"> |
| 145 | + <span className="flex items-center gap-1"> |
| 146 | + <Layers className="w-3.5 h-3.5" strokeWidth={1.5} /> |
| 147 | + 共 {stats.total} 张 |
| 148 | + </span> |
| 149 | + {hasDue ? ( |
| 150 | + <span className="flex items-center gap-1 text-flashcard font-medium"> |
| 151 | + <Clock className="w-3.5 h-3.5" strokeWidth={1.5} /> |
| 152 | + {stats.due} 张到期 |
| 153 | + </span> |
| 154 | + ) : stats.total > 0 ? ( |
| 155 | + <motion.span |
| 156 | + className="text-semantic-success font-medium" |
| 157 | + initial={{ opacity: 0 }} |
| 158 | + animate={{ opacity: 1 }} |
| 159 | + transition={{ delay: 0.5 }} |
| 160 | + > |
| 161 | + ✓ 全部已学完 |
| 162 | + </motion.span> |
| 163 | + ) : ( |
| 164 | + <span className="text-text-tertiary">暂无卡片</span> |
| 165 | + )} |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + </motion.div> |
| 169 | + ); |
| 170 | +} |
0 commit comments