'use client'; import { ComponentProps, ReactNode } from 'react'; import LabeledIcon, { LabeledIconType } from './LabeledIcon'; import Badge from '../Badge'; import { clsx } from 'clsx/lite'; import LinkWithStatus from '../LinkWithStatus'; import Spinner from '../Spinner'; export interface EntityLinkExternalProps { type?: LabeledIconType badged?: boolean contrast?: ComponentProps['contrast'] prefetch?: boolean className?: string } export default function EntityLink({ icon, label, labelSmall, iconWide, type, badged, contrast = 'medium', href = '', // Make link optional for debugging purposes prefetch, title, hoverEntity, truncate = true, className, debug, }: { icon: ReactNode label: ReactNode labelSmall?: ReactNode iconWide?: boolean href?: string prefetch?: boolean title?: string hoverEntity?: ReactNode truncate?: boolean className?: string debug?: boolean } & EntityLinkExternalProps) { const classForContrast = () => { switch (contrast) { case 'low': return 'text-dim'; case 'high': return 'text-main'; case 'frosted': return 'text-black'; default: return 'text-medium'; } }; const renderLabel = () => <> {labelSmall ?? label} {label} ; return ( {({ isLoading }) => <> {badged ? {renderLabel()} : {renderLabel()} } {!isLoading && hoverEntity !== undefined && {hoverEntity} } {isLoading && } } ); }