import BoringAvatar from 'boring-avatars'; import { useCurrentUser } from '@/api/account/queries'; import { replaceable, useSkin } from '@/themes/skins'; const palette = ['var(--chart-1)', 'var(--chart-2)', 'var(--chart-3)', 'var(--chart-4)', 'var(--chart-5)']; export type AvatarVariant = 'beam' | 'marble' | 'pixel' | 'sunset' | 'ring' | 'bauhaus'; export interface AvatarProps { /** Seeds the generated pattern; the panel uses a user's UUID. */ name: string; size?: number | string; variant?: AvatarVariant; square?: boolean; title?: boolean; className?: string; /** An uploaded picture drawn in place of the pattern, such as a user's `avatar`. */ image?: string | null; } function CoreAvatar({ variant = 'beam', image, className, ...props }: AvatarProps) { const ui = useSkin('Avatar', { variant }); if (image) { // Shaped and sized like the pattern: round unless `square`, and as wide as its box without a `size`. return ( {props.title ); } return ; } const _Avatar = replaceable('Avatar', CoreAvatar); const UserAvatar = (props: Omit) => { const user = useCurrentUser(); return <_Avatar name={user.uuid} image={user.avatar} {...props} />; }; UserAvatar.displayName = 'Avatar.User'; const Avatar = Object.assign(_Avatar, { User: UserAvatar, }); export default Avatar;