import { HTMLAttributes } from "react"; import { Icon } from "../icon"; import Typography from "../typography/typography"; /** * @params alt - Provide an alt text for the image tag * @params className - Custom CSS classes * @params currentStatus - Provide user current status * @params onClick - Provides onClick function * @params shape - Shape of the Avatar * @params size - Size of the Avatar component * @params src - Source for image tag */ export interface AvatarProps extends HTMLAttributes { className?: string; status?: "online" | "offline" | "busy" | "away"; onClick?: () => void; shape?: "circle" | "square"; size?: "xs" | "sm" | "md" | "lg" | "xl" | "2xl"; type?: "image" | "name" | "placeholder"; name?: string; src: string; } const sizes = { xs: "w-6 h-6", sm: "w-8 h-8", md: "w-10 h-10", lg: "w-12 h-12", xl: "w-14 h-14", "2xl": "w-16 h-16", }; const shapes = { circle: "rounded-full", square: "rounded", }; const activeClass = { xs: "w-1.5 h-1.5", sm: "w-2 h-2", md: "w-2.5 h-2.5", lg: "w-3 h-3", xl: "w-3.5 h-4.5", "2xl": "w-4 h-4", }; const statusColors = { online: "bg-success-500", offline: "bg-gray-500", busy: "bg-error-500", away: "bg-warning-500", }; const iconSize = { xs: 16, sm: 20, md: 24, lg: 28, xl: 32, "2xl": 32, }; export function Avatar({ src, size = "md", shape = "circle", onClick, status = "away", type = "image", name = "", className, ...restProps }: AvatarProps) { const shortName = name .split(/\s+/) .map(i => i.slice(0, 1).toUpperCase()) .slice(0, 2) .join(""); return (
{type === "image" && ( {name} )} {type === "placeholder" && ( )} {type === "name" && ( {shortName} )}
{status !== "away" && ( {shape === "square" && ( )} )}
); } export default Avatar;