import type { CSSProperties, HTMLAttributes, Ref } from 'react'; import React from 'react'; import { useVisuallyHidden } from 'react-aria'; import classNames from 'classnames'; import { Avatar as CoreAvatar, Image as CoreImage } from '@shoptet/ui-core-web'; import { Icon } from '../Icon/Icon'; interface HTMLElementProps extends HTMLAttributes {} export interface AvatarOwnProps extends HTMLElementProps { /** * Ref for the root avatar element. */ ref?: Ref; /** * The class name of the root element. */ className?: string; /** * The description of the person. */ description?: string; /** * Controls the lazy loading of the image. */ lazy?: boolean; /** * The name of the person. */ name: string; /** * The URL of the image. */ src?: string; /** * The URL source set of the image. */ srcSet?: string; /** * Controls the visibility of the image and text. * @default 'image+text' */ variant?: 'image' | 'text' | 'image+text'; } export interface AvatarProps extends Omit {} const hiddenImgStyle: CSSProperties = { opacity: 0, transition: 'none' }; export const Avatar = ({ ref, name, description, src, srcSet, lazy, variant = 'image+text', ...rest }: AvatarProps) => { const { visuallyHiddenProps } = useVisuallyHidden(); const textVisuallyHidden = variant === 'image'; return ( {variant !== 'text' && ( {() => ( {({ state }) => state.initials || } )} state.loadingState === 'initial' || state.loadingState === 'success' ? {} : hiddenImgStyle } /> )} {({ state }) => ( <> {state.name} {state.description} )} ); };