Skip to content

Commit

Permalink
refactor: create NextLink component and use for all links
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt committed Nov 20, 2023
1 parent cc630e3 commit 66b5cde
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
20 changes: 5 additions & 15 deletions src/app/(header-footer)/imprint/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import Link from 'next/link';
import NextLink from '@/components/NextLink';

export default function ImprintPage() {
return (
Expand Down Expand Up @@ -64,14 +64,9 @@ export default function ImprintPage() {
<p className='text-center'>
Die Europäische Kommission stellt eine Plattform zur
Online-Streitbeilegung (OS) bereit:{' '}
<Link
href='https://ec.europa.eu/consumers/odr/'
target='_blank'
rel='noopener noreferrer'
className='underline'
>
<NextLink href='https://ec.europa.eu/consumers/odr/' isExternalLink>
https://ec.europa.eu/consumers/odr/
</Link>
</NextLink>
.<br /> Unsere E-Mail-Adresse finden Sie oben im Impressum.
</p>
</div>
Expand All @@ -85,14 +80,9 @@ export default function ImprintPage() {
</p>
<p className='text-center'>
Quelle:{' '}
<Link
href='https://www.e-recht24.de'
target='_blank'
rel='noopener noreferrer'
className='underline'
>
<NextLink href='https://www.e-recht24.de' isExternalLink>
e-recht24.de
</Link>
</NextLink>
</p>
</div>
</div>
Expand Down
10 changes: 3 additions & 7 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import Link from 'next/link';

import NextImage from '@/components/NextImage';
import NextLink from '@/components/NextLink';

export default function Footer({ text, link }: { text: string; link: string }) {
return (
<div className='relative mt-20 flex w-full justify-center pb-4 lg:max-w-[1300px]'>
<Link
href={link}
className='font-primary text-xs text-neutral-700 underline'
>
<NextLink href={link} className='font-primary text-xs text-neutral-700'>
{text}
</Link>
</NextLink>
<NextImage
alt='dots'
src='/svg/grey-dots.svg'
Expand Down
8 changes: 4 additions & 4 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Link from 'next/link';
import { FiMail } from 'react-icons/fi';

import { cn } from '@/lib/utils';

import NextImage from '@/components/NextImage';
import NextLink from '@/components/NextLink';

function Logo() {
return (
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function Header({
<div
style={{ opacity: opacity }}
className={cn(
`mt-5 flex max-h-[100px] w-full items-start justify-between px-5 lg:mt-12 lg:max-w-[1300px] lg:px-16`,
'mt-5 flex max-h-[100px] w-full items-start justify-between px-5 lg:mt-12 lg:max-w-[1300px] lg:px-16',
className
)}
>
Expand All @@ -54,9 +54,9 @@ export default function Header({
</button>
)}
{clickOnLogoBehaviour === 'goHome' && (
<Link href='/'>
<NextLink href='/'>
<Logo />
</Link>
</NextLink>
)}
<div className='grow'></div>
<button
Expand Down
25 changes: 25 additions & 0 deletions src/components/NextLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Link from 'next/link';
import { ReactNode } from 'react';

import { cn } from '@/lib/utils';

export default function NextLink({
href,
children,
isExternalLink,
className,
}: {
href: string;
children: ReactNode;
isExternalLink?: boolean;
className?: string;
}) {
const linkProps = isExternalLink
? { target: '_blank', rel: 'noopener noreferrer' }
: {};
return (
<Link href={href} className={cn('underline', className)} {...linkProps}>
{children}
</Link>
);
}
10 changes: 5 additions & 5 deletions src/components/WhoWeAre.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Link from 'next/link';
import { ReactElement } from 'react';

import { cn } from '@/lib/utils';

import NextImage from '@/components/NextImage';
import NextLink from '@/components/NextLink';

function ExternalReferences({
linkedInLink,
Expand All @@ -18,24 +18,24 @@ function ExternalReferences({
}) {
return (
<div className={cn('gap-1', className)}>
<Link href={linkedInLink} target='_blank'>
<NextLink href={linkedInLink} isExternalLink>
<NextImage
src='/svg/linkedin.svg'
alt='linkedin-logo'
width={size}
height={size}
useSkeleton
/>
</Link>
<Link href={gitHubLink} target='_blank'>
</NextLink>
<NextLink href={gitHubLink} isExternalLink>
<NextImage
src='/svg/github.svg'
alt='github-logo'
width={size}
height={size}
useSkeleton
/>
</Link>
</NextLink>
</div>
);
}
Expand Down

0 comments on commit 66b5cde

Please sign in to comment.