diff --git a/src/common/Blocks/CTACenteredBlock/index.tsx b/src/common/Blocks/CTACenteredBlock/index.tsx index ca630b2..9049047 100644 --- a/src/common/Blocks/CTACenteredBlock/index.tsx +++ b/src/common/Blocks/CTACenteredBlock/index.tsx @@ -1,5 +1,5 @@ -import Link from 'next/link'; import type { CTACenteredBlock as CTACenteredBlockType } from '@/payload-types'; +import { LinkButton } from '../../Components/LinkButtons'; export const CTACenteredBlock = ({ data }: { data: CTACenteredBlockType | null | undefined }) => { if (!data) return null; @@ -22,20 +22,7 @@ export const CTACenteredBlock = ({ data }: { data: CTACenteredBlockType | null |
- {data.links?.map(({ link }, index) => ( - - {link.label} - - ))} + {data.links?.map(({ link }, index) => )}
diff --git a/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx b/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx index 1d731b9..e2f614b 100644 --- a/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx +++ b/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx @@ -1,4 +1,4 @@ -import Link from 'next/link'; +import { LinkButton } from '../../Components/LinkButtons'; import type { CTAWithSplitContentAndButtonBlock as CTAWithSplitContentAndButtonBlockType } from '@/payload-types'; export const CTAWithSplitContentAndButtonBlock = ({ @@ -27,20 +27,7 @@ export const CTAWithSplitContentAndButtonBlock = ({
- {data.links?.map(({ link }, index) => ( - - {link.label} - - ))} + {data.links?.map(({ link }, index) => )}
diff --git a/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx b/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx index f2eefb0..6a2a0f1 100644 --- a/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx +++ b/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx @@ -1,7 +1,6 @@ -import Link from 'next/link'; import type { CTAWithSplitContentAndImageBlock as CTAWithSplitContentAndImageBlockType } from '@/payload-types'; - import Image from 'next/image'; +import { LinkButton } from '../../Components/LinkButtons'; export const CTAWithSplitContentAndImageBlock = ({ data, @@ -48,20 +47,7 @@ export const CTAWithSplitContentAndImageBlock = ({
- {data.links?.map(({ link }, index) => ( - - {link.label} - - ))} + {data.links?.map(({ link }, index) => )}
diff --git a/src/common/Blocks/ContentBlock/index.tsx b/src/common/Blocks/ContentBlock/index.tsx index 7b3911c..cecdc9d 100644 --- a/src/common/Blocks/ContentBlock/index.tsx +++ b/src/common/Blocks/ContentBlock/index.tsx @@ -1,5 +1,5 @@ +import { LinkButton } from '../../Components/LinkButtons'; import { ContentBlock as ContentBlockType } from '@/payload-types'; -import Link from 'next/link'; export const ContentBlock = ({ data }: { data: ContentBlockType | null | undefined }) => { if (!data) return null; @@ -27,20 +27,7 @@ export const ContentBlock = ({ data }: { data: ContentBlockType | null | undefin {richText_html &&
} {enableLink && links && - links.map(({ link }, index) => ( - - {link.label} - - ))} + links.map(({ link }, index) => )}
))}
diff --git a/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx b/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx index e52b943..cb73c76 100644 --- a/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx +++ b/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx @@ -1,6 +1,6 @@ -import Link from 'next/link'; import { CustomIcon } from '../../Components/CustomIcon'; import type { FeatureWithThreeColumnBlock as FeatureWithThreeColumnBlockType } from '@/payload-types'; +import { LinkButton } from '../../Components/LinkButtons'; export const FeatureWithThreeColumnBlock = ({ data, @@ -27,12 +27,10 @@ export const FeatureWithThreeColumnBlock = ({ )}

{link && ( - - {link.label} - + /> )}

diff --git a/src/common/Blocks/HeroWithBackgroundBlock/index.tsx b/src/common/Blocks/HeroWithBackgroundBlock/index.tsx index ebbaff3..12f4f1b 100644 --- a/src/common/Blocks/HeroWithBackgroundBlock/index.tsx +++ b/src/common/Blocks/HeroWithBackgroundBlock/index.tsx @@ -1,6 +1,6 @@ -import Link from 'next/link'; import type { HeroWithBackgroundBlock as HeroWithBackgroundBlockType } from '@/payload-types'; import { MediaImage } from '../../Mediaimage'; +import { LinkButton } from '../../Components/LinkButtons'; export const HeroWithBackgroundBlock = ({ data, @@ -41,19 +41,7 @@ export const HeroWithBackgroundBlock = ({
- {data.links?.map(({ link }, index) => ( - - {link.label} - - ))} + {data.links?.map(({ link }, index) => )}
{data.backgroundType === 'backgroundImage' && data.backgroundImage && ( diff --git a/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx b/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx index c10a19b..83d4317 100644 --- a/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx +++ b/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx @@ -1,6 +1,6 @@ -import Link from 'next/link'; import type { HeroWithSplitContentAndImageBlock as HeroWithSplitContentAndImageBlockType } from '@/payload-types'; import { MediaImage } from '../../Mediaimage'; +import { LinkButton } from '../../Components/LinkButtons'; export const HeroWithSplitContentAndImageBlock = ({ data, @@ -42,20 +42,7 @@ export const HeroWithSplitContentAndImageBlock = ({
- {data.links?.map(({ link }, index) => ( - - {link.label} - - ))} + {data.links?.map(({ link }, index) => )}
diff --git a/src/common/Components/LinkButtons/index.tsx b/src/common/Components/LinkButtons/index.tsx new file mode 100644 index 0000000..8154615 --- /dev/null +++ b/src/common/Components/LinkButtons/index.tsx @@ -0,0 +1,79 @@ +import { Page } from '@/payload-types'; +import Link from 'next/link'; + +interface Link { + type?: ('reference' | 'custom') | null; + newTab?: boolean | null; + reference?: { + relationTo: 'pages'; + value: string | Page; + } | null; + url?: string | null; + label?: string; + appearance?: ('primary' | 'secondary') | null; +} + +export const LinkButton = ({ link, className }: { link: Link; className?: string }) => { + if (link.type === 'custom') { + if (link.appearance) + return ( + link && ( + + {link.label} + + ) + ); + + return ( + link && ( + + {JSON.stringify(link)} + {link.label} + + ) + ); + } + + if (link.type === 'reference') { + const doc = link.reference?.value; + if (typeof doc !== 'string' && doc?.slug) { + if (link.appearance) { + return ( + link && ( + + {doc.title} + + ) + ); + } + + return ( + + {doc.title} + + ); + } + } +}; diff --git a/tailwind.config.js b/tailwind.config.js index 5239a72..5564c28 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -2,7 +2,7 @@ export default { content: [ './src/pages/**/*.{js,ts,jsx,tsx,mdx}', - './src/components/**/*.{js,ts,jsx,tsx,mdx}', + './src/Components/**/*.{js,ts,jsx,tsx,mdx}', './src/common/**/*.{js,ts,jsx,tsx,mdx}', './src/app/**/*.{js,ts,jsx,tsx,mdx}', ],