Files
ipal-kit/src/modules/block-library/ui/CMSLink.tsx
T
Radosław SmolińskiandClaude Opus 5.5 29ede3ad4b Block library: fixes from the first visual test on the reference site
- CMSLink: a link that wraps content (a logo, a card) and leads nowhere keeps the
  content — an empty link group ({ type: 'internal' }) no longer hides logos
- entryList: field `collection` → `entryCollection` (Mongoose reserves
  `collection`; unreleased, snapshot updated) + a test against reserved names
- post template starts with a page hero holding the title (the page's h1)
- legal and cookie policy templates set noindex: true (AGENT.md §0c)
- hero background: a full bg-overlay scrim under the text
- MediaValue accepts any object (generated Media types fit without a cast)
- contact: Turnstile renders dark in an inverted section

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 15:03:39 +01:00

44 lines
1.6 KiB
TypeScript

import type { ReactNode } from 'react'
import type { ResolvedLink } from '../../links/resolveNav.js'
import type { LinkData } from '../data.js'
import type { LinkComponent } from './Anchor.js'
import { Anchor } from './Anchor.js'
import { buttonClass as defaultButtonClass } from './Button.js'
import { cx } from './cx.js'
export type ResolveLink = (link: LinkData, locale: string) => null | Promise<null | ResolvedLink> | ResolvedLink
export type CMSLinkProps = {
/** For a link that wraps something (a card, an image): the content instead of the label — shown without a link when the link leads nowhere. */
children?: ReactNode
className?: string
link: LinkData
locale: string
}
/** The plugin's link: `resolve` (lib/content `resolveLink`), `buttonClass` and `Link` (next/link) are bound by createBlockRegistry. */
export async function CMSLink({
buttonClass = defaultButtonClass,
children,
className,
link,
Link,
locale,
resolve,
}: { buttonClass?: (appearance?: null | string) => string; Link?: LinkComponent; resolve: ResolveLink } & CMSLinkProps) {
const l = link ? await resolve(link, locale) : null
// A link that wraps something (a logo, a card) and leads nowhere — an empty link group, a deleted page —
// keeps its content as it is; a plain text link without a target renders nothing.
if (!l) {return children ?? null}
const content = children ?? l.label
if (!content) {return null}
const cls = cx(buttonClass(l.appearance), className) || undefined
return (
<Anchor className={cls} href={l.href} internal={l.internal} Link={Link} targetProps={l.targetProps}>
{content}
</Anchor>
)
}