import clsx from 'clsx' import { ComponentType, useState } from 'react' import { useTranslation } from 'react-i18next' import { FollowState, LinkWrapperProps } from '@dao-dao/types' import { UNDO_PAGE_PADDING_HORIZONTAL_CLASSES, UNDO_PAGE_PADDING_TOP_CLASSES, toAccessibleImageUrl, } from '@dao-dao/utils' import { Button, FollowingToggle } from '../buttons' import { MarkdownRenderer } from '../MarkdownRenderer' import { Modal } from '../modals' import { DaoImage, DaoImageProps } from './DaoImage' export type DaoHeaderProps = { coreAddress?: string name: string description: string imageUrl?: string | null bannerImageUrl?: string | null parentDao: DaoImageProps['parentDao'] LinkWrapper: ComponentType follow?: FollowState className?: string } export const DaoHeader = ({ coreAddress, name, description, imageUrl, bannerImageUrl, parentDao, LinkWrapper, follow, className, }: DaoHeaderProps) => { const { t } = useTranslation() const [descriptionCollapsed, setDescriptionCollapsed] = useState(false) const [descriptionVisible, setDescriptionVisible] = useState(false) const image = ( ) return ( <>
{bannerImageUrl ? (
{image}
) : ( image )}

{name}

{follow && ( // Following toggle next to name on desktop. )}
{!!description && (
setDescriptionVisible(true)} > { if (!ref || descriptionCollapsed) { return } setDescriptionCollapsed(ref.scrollHeight > ref.clientHeight) } } /> {descriptionCollapsed && ( )}
)} {follow && ( // Following toggle below description on mobile. )}
{descriptionCollapsed && ( setDescriptionVisible(false)} visible={descriptionVisible} > )} ) }