Download tasks/linkedin/solution/site/implementation/clone/components/Avatar.tsx from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 612 Bytes
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/linkedin/solution/site/implementation/clone/components/Avatar.tsx
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/linkedin/solution/site/implementation/clone/components/Avatar.tsx
-
curl -L -o Avatar.tsx https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/linkedin/solution/site/implementation/clone/components/Avatar.tsx
612 Bytes
| "use client"; | |
| import { useState } from "react"; | |
| type AvatarProps = { | |
| name: string; | |
| src?: string; | |
| size?: "sm" | "md" | "lg" | "xl"; | |
| }; | |
| export function Avatar({ name, src, size = "md" }: AvatarProps) { | |
| const [imageFailed, setImageFailed] = useState(false); | |
| if (src && !imageFailed) { | |
| return <img className={`avatar avatar-${size}`} src={src} alt="" onError={() => setImageFailed(true)} />; | |
| } | |
| const initials = name.split(/\s+/).slice(0, 2).map((part) => part[0]).join("").toUpperCase(); | |
| return <span className={`avatar avatar-${size} avatar-fallback`} aria-hidden="true">{initials}</span>; | |
| } | |