|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { motion } from 'framer-motion'; |
| 4 | +import { memo, useState } from 'react'; |
| 5 | +import Image from 'next/image'; |
| 6 | + |
| 7 | +interface FriendModel { |
| 8 | + name: string; |
| 9 | + url: string; |
| 10 | + avatar: string; |
| 11 | + desc: string; |
| 12 | +} |
| 13 | + |
| 14 | +export default function Friends() { |
| 15 | + const friendData: FriendModel[] = [ |
| 16 | + { |
| 17 | + name: 'Alice', |
| 18 | + url: 'https://www.baidu.com', |
| 19 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 20 | + desc: 'A passionate developer and a great friend.', |
| 21 | + }, |
| 22 | + { |
| 23 | + name: 'Bob', |
| 24 | + url: 'https://bob.example.com', |
| 25 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 26 | + desc: 'Bob loves working on open-source projects.', |
| 27 | + }, |
| 28 | + { |
| 29 | + name: 'Charlie', |
| 30 | + url: 'https://charlie.example.com', |
| 31 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 32 | + desc: 'Charlie is a fantastic designer and loves to create beautiful UIs.', |
| 33 | + }, |
| 34 | + { |
| 35 | + name: 'Dave', |
| 36 | + url: 'https://dave.example.com', |
| 37 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 38 | + desc: 'A data science enthusiast and machine learning expert.', |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'Eve', |
| 42 | + url: 'https://eve.example.com', |
| 43 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 44 | + desc: 'Eve loves cybersecurity and cryptography.', |
| 45 | + }, |
| 46 | + { |
| 47 | + name: 'Frank', |
| 48 | + url: 'https://frank.example.com', |
| 49 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 50 | + desc: 'Frank is a backend engineer with years of experience.', |
| 51 | + }, |
| 52 | + { |
| 53 | + name: 'Grace', |
| 54 | + url: 'https://grace.example.com', |
| 55 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 56 | + desc: 'Grace is a machine learning researcher.', |
| 57 | + }, |
| 58 | + { |
| 59 | + name: 'Heidi', |
| 60 | + url: 'https://heidi.example.com', |
| 61 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 62 | + desc: 'Heidi enjoys working on cloud computing.', |
| 63 | + }, |
| 64 | + { |
| 65 | + name: 'Ivan', |
| 66 | + url: 'https://ivan.example.com', |
| 67 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 68 | + desc: 'Ivan specializes in database optimization.', |
| 69 | + }, |
| 70 | + { |
| 71 | + name: 'Judy', |
| 72 | + url: 'https://judy.example.com', |
| 73 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 74 | + desc: 'Judy is a frontend developer with a passion for animations.', |
| 75 | + }, |
| 76 | + { |
| 77 | + name: 'Karl', |
| 78 | + url: 'https://karl.example.com', |
| 79 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 80 | + desc: 'Karl is a mobile developer working on iOS apps.', |
| 81 | + }, |
| 82 | + { |
| 83 | + name: 'Lara', |
| 84 | + url: 'https://lara.example.com', |
| 85 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 86 | + desc: 'Lara enjoys writing clean, maintainable code.', |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'Mallory', |
| 90 | + url: 'https://mallory.example.com', |
| 91 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 92 | + desc: 'Mallory is an expert in penetration testing.', |
| 93 | + }, |
| 94 | + { |
| 95 | + name: 'Nina', |
| 96 | + url: 'https://nina.example.com', |
| 97 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 98 | + desc: 'Nina is passionate about AR/VR development.', |
| 99 | + }, |
| 100 | + { |
| 101 | + name: 'Oscar', |
| 102 | + url: 'https://oscar.example.com', |
| 103 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 104 | + desc: 'Oscar loves contributing to open-source projects.', |
| 105 | + }, |
| 106 | + { |
| 107 | + name: 'Peggy', |
| 108 | + url: 'https://peggy.example.com', |
| 109 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 110 | + desc: 'Peggy is a blockchain developer.', |
| 111 | + }, |
| 112 | + { |
| 113 | + name: 'Quinn', |
| 114 | + url: 'https://quinn.example.com', |
| 115 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 116 | + desc: 'Quinn focuses on DevOps and cloud infrastructure.', |
| 117 | + }, |
| 118 | + { |
| 119 | + name: 'Rita', |
| 120 | + url: 'https://rita.example.com', |
| 121 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 122 | + desc: 'Rita is an AI researcher and educator.', |
| 123 | + }, |
| 124 | + { |
| 125 | + name: 'Steve', |
| 126 | + url: 'https://steve.example.com', |
| 127 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 128 | + desc: 'Steve enjoys developing Android applications.', |
| 129 | + }, |
| 130 | + { |
| 131 | + name: 'Trudy', |
| 132 | + url: 'https://trudy.example.com', |
| 133 | + avatar: 'https://avatars.githubusercontent.com/u/116412388?v=4', |
| 134 | + desc: 'Trudy works on full-stack web applications.', |
| 135 | + }, |
| 136 | + ]; |
| 137 | + |
| 138 | + return ( |
| 139 | + <div> |
| 140 | + <header className="prose prose-p:my-2 font-mono"> |
| 141 | + <h1>朋友们</h1> |
| 142 | + <h3>海内存知己,天涯若比邻</h3> |
| 143 | + </header> |
| 144 | + |
| 145 | + <main className="mt-10 flex w-full flex-col"> |
| 146 | + <FriendCardList data={friendData} /> |
| 147 | + </main> |
| 148 | + </div> |
| 149 | + ); |
| 150 | +} |
| 151 | + |
| 152 | +const FriendCardList = ({ data }: { data: FriendModel[] }) => ( |
| 153 | + <div className="grid grid-cols-2 gap-6 md:grid-cols-3"> |
| 154 | + {data.map((friendModel) => { |
| 155 | + return <FriendCard friendModel={friendModel} />; |
| 156 | + })} |
| 157 | + </div> |
| 158 | +); |
| 159 | +const FriendCard = ({ friendModel }: { friendModel: FriendModel }) => { |
| 160 | + const [enter, setEnter] = useState(false); |
| 161 | + |
| 162 | + return ( |
| 163 | + <motion.div |
| 164 | + key={friendModel.name} |
| 165 | + role="link" |
| 166 | + aria-label={`Go to ${friendModel.name}'s website`} |
| 167 | + className="relative flex flex-col items-center justify-center cursor-pointer" |
| 168 | + onMouseEnter={() => setEnter(true)} |
| 169 | + onMouseLeave={() => setEnter(false)} |
| 170 | + onClick={() => window.open(friendModel.url, '_blank')} |
| 171 | + rel="noreferrer" |
| 172 | + > |
| 173 | + {enter && <LayoutBg />} |
| 174 | + <Image |
| 175 | + src={friendModel.avatar} |
| 176 | + height={64} |
| 177 | + width={64} |
| 178 | + alt={`Avatar of ${friendModel.name}`} |
| 179 | + className=" rounded-md" |
| 180 | + /> |
| 181 | + <span className="flex h-full flex-col items-center justify-center space-y-2 py-3"> |
| 182 | + <span className="text-lg font-medium">{friendModel.name}</span> |
| 183 | + <span className="line-clamp-2 text-balance break-all text-center text-sm text-base-content/80"> |
| 184 | + {friendModel.desc} |
| 185 | + </span> |
| 186 | + </span> |
| 187 | + </motion.div> |
| 188 | + ); |
| 189 | +}; |
| 190 | +const LayoutBg = memo(() => { |
| 191 | + return ( |
| 192 | + <motion.span |
| 193 | + layoutId="bg" |
| 194 | + className="absolute -inset-2 z-[-1] rounded-md bg-slate-200/80 dark:bg-neutral-600/80 pointer-events-none" |
| 195 | + initial={{ opacity: 0.8, scale: 0.8 }} |
| 196 | + animate={{ opacity: 1, scale: 1 }} |
| 197 | + exit={{ opacity: 0, scale: 0.8, transition: { delay: 0.2 } }} |
| 198 | + /> |
| 199 | + ); |
| 200 | +}); |
0 commit comments