2022-01-27 23:14:18 +00:00
|
|
|
import Router from 'next/router'
|
|
|
|
import clsx from 'clsx'
|
2022-02-04 18:30:56 +00:00
|
|
|
import { UserCircleIcon } from '@heroicons/react/solid'
|
2022-01-27 23:14:18 +00:00
|
|
|
|
|
|
|
export function Avatar(props: {
|
|
|
|
username?: string
|
|
|
|
avatarUrl?: string
|
|
|
|
noLink?: boolean
|
2022-02-04 18:30:56 +00:00
|
|
|
size?: number
|
2022-01-27 23:14:18 +00:00
|
|
|
}) {
|
2022-02-04 18:30:56 +00:00
|
|
|
const { username, avatarUrl, noLink, size } = props
|
|
|
|
const s = size || 10
|
2022-01-27 23:14:18 +00:00
|
|
|
|
|
|
|
const onClick =
|
|
|
|
noLink && username
|
|
|
|
? undefined
|
|
|
|
: (e: any) => {
|
|
|
|
e.stopPropagation()
|
|
|
|
Router.push(`/${username}`)
|
|
|
|
}
|
|
|
|
return (
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className={`flex-shrink-0 rounded-full bg-white w-${s} h-${s}`}>
|
2022-02-04 18:30:56 +00:00
|
|
|
{avatarUrl ? (
|
|
|
|
<img
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'flex items-center justify-center rounded-full object-cover',
|
2022-02-06 06:12:23 +00:00
|
|
|
`w-${s} h-${s}`,
|
2022-02-04 18:30:56 +00:00
|
|
|
!noLink && 'cursor-pointer'
|
|
|
|
)}
|
|
|
|
src={avatarUrl}
|
|
|
|
onClick={onClick}
|
|
|
|
alt={username}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
// TODO: After 2022-03-01, can just assume that all contracts have an avatarUrl
|
|
|
|
<UserCircleIcon
|
|
|
|
className={`w-${s} h-${s} text-gray-500`}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
2022-01-27 23:14:18 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|