Skip to content

Commit 2b65e91

Browse files
committed
feat(page-link): external links
1 parent d25699b commit 2b65e91

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

docs/src/components/menu/PageLink.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import classNames from 'classnames';
22
import Link from 'next/link';
33
import { useRouter } from 'next/router';
44
import React from 'react';
5+
import { ExternalLinkIcon } from '@heroicons/react/outline';
56

67
interface Props {
78
name: string | JSX.Element;
@@ -13,6 +14,13 @@ interface Props {
1314
export default function PageLink({ name, to, style }: Props) {
1415
const router = useRouter();
1516
const isActive = router.asPath === to;
17+
const isInternalLink = !to || to.startsWith('/');
18+
const aProps = isInternalLink
19+
? {}
20+
: {
21+
target: '_blank',
22+
rel: 'noopener noreferrer',
23+
};
1624

1725
return (
1826
<Link href={to || ''}>
@@ -21,11 +29,13 @@ export default function PageLink({ name, to, style }: Props) {
2129
isActive
2230
? 'bg-white text-lightPurple'
2331
: 'text-gray-600 hover:bg-white group-hover:text-gray-800',
24-
'group py-3 px-6 flex items-center md:text-sm',
32+
'group py-3 px-6 flex items-center md:text-sm justify-between',
2533
)}
2634
style={style}
35+
{...aProps}
2736
>
28-
{name}
37+
<span>{name}</span>
38+
{isInternalLink ? null : <ExternalLinkIcon className="h-4 w-4" />}
2939
</a>
3040
</Link>
3141
);

0 commit comments

Comments
 (0)