import { external, Icon } from '@wordpress/icons'; import { useTranslate } from 'i18n-calypso'; import React, { useEffect, useRef, useState } from 'react'; import ReaderAvatar from 'calypso/blocks/reader-avatar'; import AutoDirection from 'calypso/components/auto-direction'; import SectionNav from 'calypso/components/section-nav'; import NavItem from 'calypso/components/section-nav/item'; import NavTabs from 'calypso/components/section-nav/tabs'; import { UserData } from 'calypso/lib/user/user'; import { getUserProfileUrl } from 'calypso/reader/user-profile/user-profile.utils'; import './style.scss'; interface UserProfileHeaderProps { user: UserData; view: string; } const UserProfileHeader = ( { user, view }: UserProfileHeaderProps ): JSX.Element => { const translate = useTranslate(); const userProfileUrlWithUsername = getUserProfileUrl( user.user_login ?? '' ); const navigationItems = [ { label: translate( 'Posts' ), path: userProfileUrlWithUsername, selected: view === 'posts', }, { label: translate( 'Lists' ), path: `${ userProfileUrlWithUsername }/lists`, selected: view === 'lists', }, { label: translate( 'Recommended Blogs' ), path: `${ userProfileUrlWithUsername }/recommended-blogs`, selected: view === 'recommended-blogs', }, ]; const selectedTab = navigationItems.find( ( item ) => item.selected )?.label || ''; const avatarElement = ( ); const bioRef = useRef< HTMLSpanElement >( null ); const [ isClamped, setIsClamped ] = useState( false ); useEffect( () => { if ( bioRef.current ) { const element = bioRef.current; const originalHeight = element.offsetHeight; // Temporarily remove the clamp element.style.webkitLineClamp = 'unset'; const fullHeight = element.scrollHeight; // Restore the clamp element.style.webkitLineClamp = '3'; // Determine if the text is clamped setIsClamped( fullHeight > originalHeight ); } }, [ user.bio ] ); return (
{ avatarElement }
{ avatarElement }

{ user.display_name }

{ user.bio && (

{ user.bio } { isClamped && user.profile_URL && ( <> { translate( 'Read More' ) }{ ' ' } ) }

) }
{ navigationItems.map( ( item ) => ( { item.label } ) ) }
); }; export default UserProfileHeader;