import * as React from 'react'; import * as AvatarPrimitive from '@radix-ui/react-avatar'; import { tv, type VariantProps } from 'tailwind-variants'; import { useDOMRef } from '../../hooks'; import { cn } from '../../utils/cn'; import { radiusVariant } from '../../utils/variant-common'; import { Indicator, type IndicatorProps } from './indicator'; const avatarVariants = tv({ base: 'bg-background-tertiary relative z-[1] flex shrink-0 overflow-hidden', variants: { size: { xs: 'h-6 w-6', sm: 'h-8 w-8', md: 'h-10 w-10', lg: 'h-12 w-12', xl: 'h-14 w-14', '2xl': 'h-16 w-16', '3xl': 'w-18 h-18 shadow-md', '4xl': 'h-24 w-24 shadow-lg', '5xl': 'h-40 w-40 shadow-lg', }, radius: radiusVariant, }, defaultVariants: { size: 'xs', radius: 'xs', }, }); const radiusVariants = tv({ base: '', variants: { radius: radiusVariant, }, defaultVariants: { radius: 'xs', }, }); export interface AvatarProps extends React.ComponentPropsWithoutRef, VariantProps { indicator?: IndicatorProps['type'] | 'none'; rootClassName?: string; outlined?: boolean; imgRef?: React.Ref; } const Avatar = React.forwardRef, AvatarProps>( ( { className, outlined, style, children, rootClassName, indicator = 'none', size = 'md', imgRef: imgRefProp, radius, ...props }, ref ) => { const imgRef = useDOMRef(imgRefProp); const mappingSize = React.useMemo(() => { if (size === '3xl') return '2xl'; if (size === '4xl') return '3xl'; if (size === '5xl') return '4xl'; return size; }, [size]); return (
{children}
{outlined ? (
) : null}
{indicator !== 'none' && !!indicator ? ( ) : null}
); } ); Avatar.displayName = 'Avatar'; export { Avatar };