import { QuestionMark } from '@mui/icons-material' import clsx from 'clsx' import { ComponentType, ReactNode } from 'react' import { useTranslation } from 'react-i18next' import { LinkWrapperProps } from '@dao-dao/types' import { DaoParentInfo } from '@dao-dao/types/dao' import { getFallbackImage, toAccessibleImageUrl } from '@dao-dao/utils' import { useDaoNavHelpers } from '../../hooks' import { Tooltip } from '../tooltip' export interface DaoImageProps { daoName: string size: 'sm' | 'md' | 'lg' | 'xl' imageUrl: string | undefined | null // Used to get placeholder image if no `imageUrl` present. coreAddress?: string parentDao?: Pick< DaoParentInfo, 'name' | 'coreAddress' | 'coreVersion' | 'imageUrl' | 'registeredSubDao' > | null className?: string imageClassName?: string children?: ReactNode blur?: boolean hideRing?: boolean LinkWrapper: ComponentType } export const DaoImage = ({ daoName, size, imageUrl, coreAddress, parentDao, className, imageClassName, children, blur, hideRing = false, LinkWrapper, }: DaoImageProps) => { const { t } = useTranslation() const { getDaoPath } = useDaoNavHelpers() const sizeClassNames = clsx('overflow-hidden rounded-full', { // DaoCard 'h-[4.5rem] w-[4.5rem]': size === 'sm', // SDA header 'h-7 w-7': size === 'md', // DAO home page 'h-20 w-20 xs:h-24 xs:w-24': size === 'lg', // DAO home page with banner 'h-20 w-20 xs:h-24 xs:w-24 sm:h-28 sm:w-28': size === 'xl', }) return (
{children && (
{children}
)} {/* Link to parent DAO in a circle in the bottom right. */} {parentDao && ( e.stopPropagation()} style={{ backgroundImage: `url(${ parentDao.imageUrl ? toAccessibleImageUrl(parentDao.imageUrl) : getFallbackImage(parentDao.coreAddress) })`, }} > {/* Show gray overlay with question mark if parent has not registered this SubDAO. */} {!parentDao.registeredSubDao && (
)}
)}
) }