From 738f77e571c3d872d16a03a5e1ff399075067771 Mon Sep 17 00:00:00 2001 From: guri Date: Fri, 7 Jun 2024 19:12:15 +0530 Subject: [PATCH 1/2] add component for link buttons --- src/common/Blocks/CTACenteredBlock/index.tsx | 17 +--- .../index.tsx | 17 +--- .../index.tsx | 18 +---- src/common/Blocks/ContentBlock/index.tsx | 17 +--- .../FeatureWithThreeColumnBlock/index.tsx | 10 +-- .../Blocks/HeroWithBackgroundBlock/index.tsx | 16 +--- .../index.tsx | 17 +--- src/common/Components/LinkButtons/index.tsx | 79 +++++++++++++++++++ 8 files changed, 95 insertions(+), 96 deletions(-) create mode 100644 src/common/Components/LinkButtons/index.tsx diff --git a/src/common/Blocks/CTACenteredBlock/index.tsx b/src/common/Blocks/CTACenteredBlock/index.tsx index ca630b2..f764879 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..785dfb6 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..ad74464 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..0a36e1d 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 0be7c6f..158887f 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 '@/common/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..ec00e26 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..73b3aef 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..63cf968 --- /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} + + ); + } + } +}; From 17033f75a8b8529bccdf9612e9a3d10cf8fb32e0 Mon Sep 17 00:00:00 2001 From: guri Date: Tue, 11 Jun 2024 17:44:57 +0530 Subject: [PATCH 2/2] update --- src/common/Blocks/CTACenteredBlock/index.tsx | 2 +- src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx | 2 +- src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx | 2 +- src/common/Blocks/ContentBlock/index.tsx | 2 +- src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx | 3 +-- src/common/Blocks/HeroWithBackgroundBlock/index.tsx | 2 +- src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx | 2 +- src/common/Components/LinkButtons/index.tsx | 4 ++-- tailwind.config.js | 2 +- 9 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/common/Blocks/CTACenteredBlock/index.tsx b/src/common/Blocks/CTACenteredBlock/index.tsx index f764879..9049047 100644 --- a/src/common/Blocks/CTACenteredBlock/index.tsx +++ b/src/common/Blocks/CTACenteredBlock/index.tsx @@ -1,5 +1,5 @@ import type { CTACenteredBlock as CTACenteredBlockType } from '@/payload-types'; -import { LinkButton } from '../../components/LinkButtons'; +import { LinkButton } from '../../Components/LinkButtons'; export const CTACenteredBlock = ({ data }: { data: CTACenteredBlockType | null | undefined }) => { if (!data) return null; diff --git a/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx b/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx index 785dfb6..e2f614b 100644 --- a/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx +++ b/src/common/Blocks/CTAWithSplitContentAndButtonBlock/index.tsx @@ -1,4 +1,4 @@ -import { LinkButton } from '../../components/LinkButtons'; +import { LinkButton } from '../../Components/LinkButtons'; import type { CTAWithSplitContentAndButtonBlock as CTAWithSplitContentAndButtonBlockType } from '@/payload-types'; export const CTAWithSplitContentAndButtonBlock = ({ diff --git a/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx b/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx index ad74464..6a2a0f1 100644 --- a/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx +++ b/src/common/Blocks/CTAWithSplitContentAndImageBlock/index.tsx @@ -1,6 +1,6 @@ import type { CTAWithSplitContentAndImageBlock as CTAWithSplitContentAndImageBlockType } from '@/payload-types'; import Image from 'next/image'; -import { LinkButton } from '../../components/LinkButtons'; +import { LinkButton } from '../../Components/LinkButtons'; export const CTAWithSplitContentAndImageBlock = ({ data, diff --git a/src/common/Blocks/ContentBlock/index.tsx b/src/common/Blocks/ContentBlock/index.tsx index 0a36e1d..cecdc9d 100644 --- a/src/common/Blocks/ContentBlock/index.tsx +++ b/src/common/Blocks/ContentBlock/index.tsx @@ -1,4 +1,4 @@ -import { LinkButton } from '../../components/LinkButtons'; +import { LinkButton } from '../../Components/LinkButtons'; import { ContentBlock as ContentBlockType } from '@/payload-types'; export const ContentBlock = ({ data }: { data: ContentBlockType | null | undefined }) => { diff --git a/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx b/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx index 57005ef..cb73c76 100644 --- a/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx +++ b/src/common/Blocks/FeatureWithThreeColumnBlock/index.tsx @@ -1,7 +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'; +import { LinkButton } from '../../Components/LinkButtons'; export const FeatureWithThreeColumnBlock = ({ data, diff --git a/src/common/Blocks/HeroWithBackgroundBlock/index.tsx b/src/common/Blocks/HeroWithBackgroundBlock/index.tsx index ec00e26..12f4f1b 100644 --- a/src/common/Blocks/HeroWithBackgroundBlock/index.tsx +++ b/src/common/Blocks/HeroWithBackgroundBlock/index.tsx @@ -1,6 +1,6 @@ import type { HeroWithBackgroundBlock as HeroWithBackgroundBlockType } from '@/payload-types'; import { MediaImage } from '../../Mediaimage'; -import { LinkButton } from '../../components/LinkButtons'; +import { LinkButton } from '../../Components/LinkButtons'; export const HeroWithBackgroundBlock = ({ data, diff --git a/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx b/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx index 73b3aef..83d4317 100644 --- a/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx +++ b/src/common/Blocks/HeroWithSplitContentAndImageBlock/index.tsx @@ -1,6 +1,6 @@ import type { HeroWithSplitContentAndImageBlock as HeroWithSplitContentAndImageBlockType } from '@/payload-types'; import { MediaImage } from '../../Mediaimage'; -import { LinkButton } from '../../components/LinkButtons'; +import { LinkButton } from '../../Components/LinkButtons'; export const HeroWithSplitContentAndImageBlock = ({ data, diff --git a/src/common/Components/LinkButtons/index.tsx b/src/common/Components/LinkButtons/index.tsx index 63cf968..8154615 100644 --- a/src/common/Components/LinkButtons/index.tsx +++ b/src/common/Components/LinkButtons/index.tsx @@ -24,7 +24,7 @@ export const LinkButton = ({ link, className }: { link: Link; className?: string link.appearance === 'primary' && 'bg-indigo-600' } px-12 py-3 text-sm font-medium ${ link.appearance === 'primary' ? 'text-white' : 'text-indigo-600' - } transition hover:bg-indigo-700 focus:outline-none focus:ring focus:ring-yellow-400`} + } transition hover:bg-indigo-700 hover:text-white focus:outline-none focus:ring focus:ring-yellow-400`} target={link.newTab ? '_blank' : '_self'} > {link.label} @@ -56,7 +56,7 @@ export const LinkButton = ({ link, className }: { link: Link; className?: string link.appearance === 'primary' && 'bg-indigo-600' } px-12 py-3 text-sm font-medium ${ link.appearance === 'primary' ? 'text-white' : 'text-indigo-600' - } transition hover:bg-indigo-700 focus:outline-none focus:ring focus:ring-yellow-400`} + } transition hover:bg-indigo-700 hover:text-white focus:outline-none focus:ring focus:ring-yellow-400`} target={link.newTab ? '_blank' : '_self'} href={doc.slug} > 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}', ],