Files
community-rule/app/components/asset/Avatar/Avatar.tsx
T
adilallo da453f6108 Replace remaining hardcoded hex colors with color tokens (CR-27)
Map leftover component hex values onto the existing color scale, and leave third-party share brands and the Avatar white-alpha border documented as intentional exceptions.
2026-08-17 14:31:28 -06:00

44 lines
1.4 KiB
TypeScript

import { memo } from "react";
export type AvatarSizeValue = "small" | "medium" | "large" | "xlarge";
interface AvatarProps extends React.ImgHTMLAttributes<HTMLImageElement> {
src: string;
alt: string;
size?: AvatarSizeValue;
className?: string;
}
const Avatar = memo<AvatarProps>(
({ src, alt, size: sizeProp = "small", className = "", ...props }) => {
const size = sizeProp;
const sizeStyles: Record<string, string> = {
small:
// White 30% border: no DS token (opacity scale is black-alpha; inverse border tokens don't cover this).
"w-[var(--spacing-scale-016)] h-[var(--spacing-scale-016)] border-[1.5px] border-[#FFFFFF4D] border-solid",
medium: "w-[var(--spacing-scale-018)] h-[var(--spacing-scale-018)]",
large: "w-[var(--spacing-scale-024)] h-[var(--spacing-scale-024)]",
xlarge: "w-[var(--spacing-scale-032)] h-[var(--spacing-scale-032)]",
};
const baseStyles = `rounded-[var(--radius-measures-radius-full)] object-cover box-border ${sizeStyles[size]} ${className}`;
return (
/* eslint-disable-next-line @next/next/no-img-element -- avatar image from URL */
<img
src={src}
alt={alt}
className={baseStyles}
loading="eager"
decoding="async"
fetchPriority="high"
{...props}
/>
);
},
);
Avatar.displayName = "Avatar";
export default Avatar;