2022-01-27 23:14:18 +00:00
|
|
|
import Router from 'next/router'
|
|
|
|
import clsx from 'clsx'
|
2022-05-26 22:22:44 +00:00
|
|
|
import { MouseEvent } from 'react'
|
2022-06-23 17:55:41 +00:00
|
|
|
import { UserCircleIcon, UserIcon, UsersIcon } from '@heroicons/react/solid'
|
2022-01-27 23:14:18 +00:00
|
|
|
|
|
|
|
export function Avatar(props: {
|
|
|
|
username?: string
|
|
|
|
avatarUrl?: string
|
|
|
|
noLink?: boolean
|
2022-03-14 21:56:53 +00:00
|
|
|
size?: number | 'xs' | 'sm'
|
2022-02-18 01:16:58 +00:00
|
|
|
className?: string
|
2022-01-27 23:14:18 +00:00
|
|
|
}) {
|
2022-05-09 21:32:59 +00:00
|
|
|
const { username, avatarUrl, noLink, size, className } = props
|
2022-03-14 21:56:53 +00:00
|
|
|
const s = size == 'xs' ? 6 : size === 'sm' ? 8 : size || 10
|
2022-01-27 23:14:18 +00:00
|
|
|
|
|
|
|
const onClick =
|
|
|
|
noLink && username
|
|
|
|
? undefined
|
2022-05-26 22:22:44 +00:00
|
|
|
: (e: MouseEvent) => {
|
2022-01-27 23:14:18 +00:00
|
|
|
e.stopPropagation()
|
|
|
|
Router.push(`/${username}`)
|
|
|
|
}
|
2022-05-09 21:32:59 +00:00
|
|
|
|
|
|
|
// 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
|
2022-04-04 21:49:14 +00:00
|
|
|
className={clsx(
|
2022-06-09 20:00:31 +00:00
|
|
|
'flex-shrink-0 rounded-full bg-white object-cover',
|
2022-05-09 21:32:59 +00:00
|
|
|
`w-${s} h-${s}`,
|
|
|
|
!noLink && 'cursor-pointer',
|
|
|
|
className
|
2022-04-04 21:49:14 +00:00
|
|
|
)}
|
2022-05-09 21:32:59 +00:00
|
|
|
src={avatarUrl}
|
|
|
|
onClick={onClick}
|
|
|
|
alt={username}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<UserCircleIcon
|
|
|
|
className={clsx(
|
|
|
|
`flex-shrink-0 rounded-full bg-white w-${s} h-${s} text-gray-500`,
|
|
|
|
className
|
2022-02-04 18:30:56 +00:00
|
|
|
)}
|
2022-05-09 21:32:59 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-01-27 23:14:18 +00:00
|
|
|
)
|
|
|
|
}
|
2022-06-23 17:55:41 +00:00
|
|
|
|
|
|
|
export function EmptyAvatar(props: { size?: number; multi?: boolean }) {
|
|
|
|
const { size = 8, multi } = props
|
|
|
|
const insize = size - 3
|
|
|
|
const Icon = multi ? UsersIcon : UserIcon
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2022-07-06 19:30:51 +00:00
|
|
|
className={`flex flex-shrink-0 h-${size} w-${size} items-center justify-center rounded-full bg-gray-200`}
|
2022-06-23 17:55:41 +00:00
|
|
|
>
|
|
|
|
<Icon className={`h-${insize} w-${insize} text-gray-500`} aria-hidden />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|