diff --git a/app/scripts/components/common/card/index.tsx b/app/scripts/components/common/card/index.tsx index e0fde1bb6..bcfef46c6 100644 --- a/app/scripts/components/common/card/index.tsx +++ b/app/scripts/components/common/card/index.tsx @@ -11,13 +11,15 @@ import { themeVal, listReset, } from '@devseed-ui/theme-provider'; +import SmartLink from '../smart-link'; import { CardBody, CardBlank, CardHeader, CardHeadline, CardTitle, CardOverline } from './styles'; import HorizontalInfoCard, { HorizontalCardStyles } from './horizontal-info-card'; import { variableBaseType, variableGlsp } from '$styles/variable-utils'; import { ElementInteractive } from '$components/common/element-interactive'; import { Figure } from '$components/common/figure'; -import { getLinkProps } from '$utils/url'; + + type CardType = 'classic' | 'cover' | 'featured' | 'horizontal-info'; @@ -259,16 +261,20 @@ function CardComponent(props: CardComponentProps) { } = props; const isExternalLink = /^https?:\/\//.test(linkTo); - const linkProps = getLinkProps(linkTo, Link, onLinkClick); - return ( { diff --git a/app/scripts/components/common/smart-link.tsx b/app/scripts/components/common/smart-link.tsx index f3f657b18..bab98c2e6 100644 --- a/app/scripts/components/common/smart-link.tsx +++ b/app/scripts/components/common/smart-link.tsx @@ -5,6 +5,7 @@ import { getLinkProps } from '$utils/url'; interface SmartLinkProps { to: string; + onLinkClick?: ()=> void; children?: ReactNode; } @@ -12,9 +13,10 @@ interface SmartLinkProps { * Switches between a `a` and a `Link` depending on the url. */ export default function SmartLink(props: SmartLinkProps) { - const { to, children, ...rest } = props; + const { to, onLinkClick, children, ...rest } = props; const isExternalLink = /^https?:\/\//.test(to); - const linkProps = getLinkProps(to); + const linkProps = getLinkProps(to, undefined, onLinkClick); + return isExternalLink ? ( {children} ) : (