|
| 1 | +import { Link } from '@tanstack/react-router' |
| 2 | +import { twMerge } from 'tailwind-merge' |
| 3 | +import { FaCheck, FaCopy } from 'react-icons/fa' |
| 4 | +import { Library } from '~/libraries' |
| 5 | +import { getFrameworkOptions } from '~/libraries/frameworks' |
| 6 | +import { useCopyButton } from '~/components/CopyMarkdownButton' |
| 7 | +import { useToast } from '~/components/ToastProvider' |
| 8 | + |
| 9 | +export function FrameworkCard({ |
| 10 | + framework, |
| 11 | + libraryId, |
| 12 | + packageName, |
| 13 | + index, |
| 14 | + library, |
| 15 | +}: { |
| 16 | + framework: ReturnType<typeof getFrameworkOptions>[number] |
| 17 | + libraryId: string |
| 18 | + packageName: string |
| 19 | + index: number |
| 20 | + library: Library |
| 21 | +}) { |
| 22 | + const { notify } = useToast() |
| 23 | + const [copied, onCopyClick] = useCopyButton(async () => { |
| 24 | + await navigator.clipboard.writeText(packageName) |
| 25 | + notify( |
| 26 | + <div> |
| 27 | + <div className="font-medium">Copied package name</div> |
| 28 | + <div className="text-gray-500 dark:text-gray-400 text-xs"> |
| 29 | + {packageName} copied to clipboard |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + ) |
| 33 | + }) |
| 34 | + |
| 35 | + const hasCustomInstallPath = !!library.installPath |
| 36 | + const installationPath = library.installPath |
| 37 | + ? library.installPath |
| 38 | + .replace('$framework', framework.value) |
| 39 | + .replace('$libraryId', libraryId) |
| 40 | + : 'installation' |
| 41 | + |
| 42 | + // Add framework hash fragment only for default installation pages (when installPath is not defined) |
| 43 | + // Link component adds the # automatically, so we just pass the value without # |
| 44 | + const installationHash = !hasCustomInstallPath ? framework.value : undefined |
| 45 | + |
| 46 | + return ( |
| 47 | + <div |
| 48 | + className={twMerge( |
| 49 | + 'border-2 border-gray-200 dark:border-gray-800/50 rounded-xl', |
| 50 | + 'shadow-md p-6 transition-all duration-300 ease-out', |
| 51 | + 'bg-white/90 dark:bg-black/40 backdrop-blur-sm', |
| 52 | + 'hover:shadow-xl hover:-translate-y-1', |
| 53 | + 'flex flex-col gap-4 group', |
| 54 | + 'min-h-[180px]', |
| 55 | + 'relative' |
| 56 | + )} |
| 57 | + style={{ |
| 58 | + zIndex: index, |
| 59 | + willChange: 'transform', |
| 60 | + }} |
| 61 | + > |
| 62 | + <Link |
| 63 | + from="/$libraryId/$version/docs" |
| 64 | + to="./$" |
| 65 | + params={{ |
| 66 | + _splat: installationPath, |
| 67 | + }} |
| 68 | + hash={installationHash} |
| 69 | + className="flex flex-col flex-1 gap-4" |
| 70 | + > |
| 71 | + {/* Framework Logo */} |
| 72 | + <div className="flex-shrink-0 flex justify-center"> |
| 73 | + <img |
| 74 | + src={framework.logo} |
| 75 | + alt={framework.label} |
| 76 | + className="w-16 h-16 object-contain transition-transform duration-300 group-hover:scale-110" |
| 77 | + /> |
| 78 | + </div> |
| 79 | + |
| 80 | + {/* Framework Name */} |
| 81 | + <div className="text-center flex-1 flex items-center justify-center"> |
| 82 | + <div className="text-lg font-semibold text-gray-900 dark:text-gray-100"> |
| 83 | + {framework.label} |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </Link> |
| 87 | + |
| 88 | + {/* Package Name with Copy Button - Bottom of Card */} |
| 89 | + <div className="pt-2 border-t border-gray-200 dark:border-gray-800 space-y-2"> |
| 90 | + <div className="flex items-center justify-center gap-2"> |
| 91 | + <code className="text-xs text-gray-600 dark:text-gray-400 font-mono"> |
| 92 | + {packageName} |
| 93 | + </code> |
| 94 | + <button |
| 95 | + onClick={(e) => { |
| 96 | + e.preventDefault() |
| 97 | + e.stopPropagation() |
| 98 | + onCopyClick(e) |
| 99 | + }} |
| 100 | + className="flex-shrink-0 p-1.5 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors rounded hover:bg-gray-100 dark:hover:bg-gray-800" |
| 101 | + title="Copy package name" |
| 102 | + > |
| 103 | + {copied ? ( |
| 104 | + <FaCheck className="w-3 h-3 text-green-600 dark:text-green-400" /> |
| 105 | + ) : ( |
| 106 | + <FaCopy className="w-3 h-3" /> |
| 107 | + )} |
| 108 | + </button> |
| 109 | + </div> |
| 110 | + <Link |
| 111 | + from="/$libraryId/$version/docs" |
| 112 | + to="./$" |
| 113 | + params={{ |
| 114 | + _splat: installationPath, |
| 115 | + }} |
| 116 | + hash={installationHash} |
| 117 | + className="block w-full text-center text-xs text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 underline transition-colors" |
| 118 | + > |
| 119 | + Full install instructions |
| 120 | + </Link> |
| 121 | + </div> |
| 122 | + |
| 123 | + {/* Accent indicator */} |
| 124 | + <div |
| 125 | + className={twMerge( |
| 126 | + 'absolute bottom-0 left-0 right-0 h-1 rounded-b-xl', |
| 127 | + 'transition-opacity duration-300', |
| 128 | + 'opacity-0 group-hover:opacity-100', |
| 129 | + framework.color |
| 130 | + )} |
| 131 | + /> |
| 132 | + </div> |
| 133 | + ) |
| 134 | +} |
0 commit comments