import React, { memo } from 'react'; import Link from 'next/link'; import urljoin from 'url-join'; import LinkedPagePath from '../models/linked-page-path'; type PagePathHierarchicalLinkProps = { linkedPagePath: LinkedPagePath, linkedPagePathByHtml?: LinkedPagePath, basePath?: string, isInTrash?: boolean, // !!INTERNAL USE ONLY!! isInnerElem?: boolean, }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types const PagePathHierarchicalLink = memo((props: PagePathHierarchicalLinkProps): JSX.Element => { const { linkedPagePath, linkedPagePathByHtml, basePath, isInTrash, } = props; // render root element if (linkedPagePath.isRoot) { if (basePath != null) { return <>; } return isInTrash ? ( <> / ) : ( <> / ); } const isParentExists = linkedPagePath.parent != null; const isParentRoot = linkedPagePath.parent?.isRoot; const isSeparatorRequired = isParentExists && !isParentRoot; const shouldDangerouslySetInnerHTML = linkedPagePathByHtml != null; const href = encodeURI(urljoin(basePath || '/', linkedPagePath.href)); // eslint-disable-next-line react/prop-types const RootElm = ({ children }) => { return props.isInnerElem ? <>{children} : {children}; }; return ( { isParentExists && ( ) } { isSeparatorRequired && ( / ) } { shouldDangerouslySetInnerHTML // eslint-disable-next-line react/no-danger ? : {linkedPagePath.pathName} } ); }); PagePathHierarchicalLink.displayName = 'PagePathHierarchicalLink'; export default PagePathHierarchicalLink;