({
pattern,
activePattern,
setActivePattern,
theme,
activeMobileCard,
setActiveMobileCard,
}: PatternCardProps)
| 17 | } |
| 18 | |
| 19 | export default function PatternCard({ |
| 20 | pattern, |
| 21 | activePattern, |
| 22 | setActivePattern, |
| 23 | theme, |
| 24 | activeMobileCard, |
| 25 | setActiveMobileCard, |
| 26 | }: PatternCardProps) { |
| 27 | const { copyToClipboard, isCopied } = useCopy(); |
| 28 | const { toggleFavourite, isFavourite } = useFavorites(); |
| 29 | const isPatternDark = theme === "dark"; |
| 30 | |
| 31 | const previewPattern = (patternId: string) => { |
| 32 | setActivePattern(patternId === activePattern ? null : patternId); |
| 33 | setTimeout(() => { |
| 34 | window.scrollTo({ top: 0, behavior: "smooth" }); |
| 35 | }, 200); |
| 36 | }; |
| 37 | |
| 38 | const handleCardInteraction = (patternId: string) => { |
| 39 | setActiveMobileCard(activeMobileCard === patternId ? null : patternId); |
| 40 | }; |
| 41 | |
| 42 | return ( |
| 43 | <div className="group relative"> |
| 44 | <div |
| 45 | className={`relative aspect-square rounded-xl sm:rounded-2xl overflow-hidden bg-background shadow-sm transition-all duration-300 ${activePattern === pattern.id |
| 46 | ? "ring-2 ring-primary ring-offset-2" |
| 47 | : "" |
| 48 | } ${activeMobileCard === pattern.id |
| 49 | ? "scale-[1.02] shadow-lg sm:scale-100" |
| 50 | : "hover:shadow-lg hover:scale-[1.02]" |
| 51 | }`} |
| 52 | onClick={() => handleCardInteraction(pattern.id)} |
| 53 | > |
| 54 | {/* Favorite Button with Star Icon */} |
| 55 | <button |
| 56 | onClick={(e) => { |
| 57 | e.stopPropagation(); |
| 58 | toggleFavourite(pattern.id); |
| 59 | }} |
| 60 | className={`absolute top-2 left-2 z-10 p-2 rounded-full backdrop-blur-md shadow-lg border transition-all cursor-pointer duration-200 hover:scale-110 group/star ${isFavourite(pattern.id) |
| 61 | ? isPatternDark |
| 62 | ? "bg-yellow-500/20 border-yellow-400/30 text-yellow-400" |
| 63 | : "bg-yellow-500/20 border-yellow-500/30 text-yellow-600" |
| 64 | : isPatternDark |
| 65 | ? "bg-black/20 border-white/20 text-white hover:bg-black/30 hover:border-white/30" |
| 66 | : "bg-black/20 border-white/30 text-white hover:bg-black/30 hover:border-white/40" |
| 67 | }`} |
| 68 | title={ |
| 69 | isFavourite(pattern.id) |
| 70 | ? "Remove from favorites" |
| 71 | : "Add to favorites" |
| 72 | } |
| 73 | > |
| 74 | <Star |
| 75 | className={`h-4 w-4 transition-all duration-200 ${isFavourite(pattern.id) |
| 76 | ? "fill-current scale-110" |
nothing calls this directly
no test coverage detected