-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from NishantChandla/34-few-fixes
add component for link buttons
- Loading branch information
Showing
9 changed files
with
96 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
href={link.url ? link.url : ''} | ||
className={`mr-2 mt-2 inline-block rounded border border-indigo-600 ${ | ||
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 hover:text-white focus:outline-none focus:ring focus:ring-yellow-400`} | ||
target={link.newTab ? '_blank' : '_self'} | ||
> | ||
{link.label} | ||
</Link> | ||
) | ||
); | ||
|
||
return ( | ||
link && ( | ||
<Link | ||
href={link.url ? link.url : ''} | ||
className={`${className} text-sm font-semibold leading-6 text-indigo-600`} | ||
> | ||
{JSON.stringify(link)} | ||
{link.label} | ||
</Link> | ||
) | ||
); | ||
} | ||
|
||
if (link.type === 'reference') { | ||
const doc = link.reference?.value; | ||
if (typeof doc !== 'string' && doc?.slug) { | ||
if (link.appearance) { | ||
return ( | ||
link && ( | ||
<Link | ||
className={`mr-2 mt-2 inline-block rounded border border-indigo-600 ${ | ||
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 hover:text-white focus:outline-none focus:ring focus:ring-yellow-400`} | ||
target={link.newTab ? '_blank' : '_self'} | ||
href={doc.slug} | ||
> | ||
{doc.title} | ||
</Link> | ||
) | ||
); | ||
} | ||
|
||
return ( | ||
<Link | ||
className={`${className} text-gray-500 transition hover:text-gray-500/75`} | ||
href={doc.slug} | ||
> | ||
{doc.title} | ||
</Link> | ||
); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters