This project is still a work in progress.

payload bricks
Fields

Link

Used for internal and external links

Installation

npx shadcn@latest add https://payload-bricks.bblank.dev/r/link-field.json

Usage

example-config.ts
import { linkField } from "@/fields/link"
import type { Block } from "payload"

export const ExampleBlock: Block = {
  slug: "example",
  interfaceName: "Example",
  fields: [
    // your other fields
    linkField,
  ],
}
example-block.tsx
import { getHrefByLink } from "@/lib/get-href-by-link"
import type { Example } from "@/payload-types"
import Link from "next/link"

export function ExampleBlock(props: Example) {
  const href = getHrefByLink(props.link)
  if (!href) return null

  return (
    <Link
      href={href}
      target={props.link?.newTab ? "_blank" : undefined}
      rel={props.link?.newTab ? "noopener noreferrer" : undefined}
    >
      {props.link?.label}
    </Link>
  )
}

Field structure

nametype
typeradioreference, custom
newTabcheckbox
referencerelationshipshown for internal links
urltextshown for custom URLs
labeltext

Customization

Internal links can point to the collections referenced in lib/collections.ts. Change collectionsWithPage to match the collections that have frontend pages in your project. The collections should use the Nested Docs Plugin. If you don't want to use that plugin, you need to update getHrefByLink.

On this page