manifold/web/components/avatar.tsx
Marshall Polaris 8a99f3772a
Cleanup avatar again (#161)
* Reinstate avatar component cleanup

This was reverted due to a bug, fixed in the subsequent commit.

* Kill additional wrapper divs around avatars

This also fixes a bug where the `w-8` answer row wrapper div was
constraining the width of the `w-10` avatar, leading it to be `w-8`
and `h-10` and appear as an oval.
2022-05-09 14:32:59 -07:00

47 lines
1.2 KiB
TypeScript

import Router from 'next/router'
import clsx from 'clsx'
import { UserCircleIcon } from '@heroicons/react/solid'
export function Avatar(props: {
username?: string
avatarUrl?: string
noLink?: boolean
size?: number | 'xs' | 'sm'
className?: string
}) {
const { username, avatarUrl, noLink, size, className } = props
const s = size == 'xs' ? 6 : size === 'sm' ? 8 : size || 10
const onClick =
noLink && username
? undefined
: (e: any) => {
e.stopPropagation()
Router.push(`/${username}`)
}
// there can be no avatar URL or username in the feed, we show a "submit comment"
// item with a fake grey user circle guy even if you aren't signed in
return avatarUrl ? (
<img
className={clsx(
'flex-shrink-0 rounded-full rounded-full bg-white object-cover',
`w-${s} h-${s}`,
!noLink && 'cursor-pointer',
className
)}
src={avatarUrl}
onClick={onClick}
alt={username}
/>
) : (
<UserCircleIcon
className={clsx(
`flex-shrink-0 rounded-full bg-white w-${s} h-${s} text-gray-500`,
className
)}
aria-hidden="true"
/>
)
}