Block library: 15 blocks, registry, primitives, templates, manifest, eject

- @intecion/ipal-kit/blocks: libraryBlocks() opt-in, one builder per block, field
  builders, option merging, blockLibraryManifest, faqItemsFromLayout
- @intecion/ipal-kit/blocks/rsc: createBlockRegistry, the block components and UI
  primitives (token utilities only; next/image and next/link passed in)
- @intecion/ipal-kit/templates: 10 page templates as createSeeder data
- createSeeder: { $form: title } references
- ipal-blocks eject <block>
- tests: options, rendering and a11y per block, Payload + seeding, GraphQL, admin
  wording, schema snapshot (versioning), eject imports
- shorter admin labels: link "New tab", table of contents "Show contents"

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 14:05:47 +01:00
co-authored by Claude Opus 5.5
parent 7918eaf6d4
commit 2d1cc0e77d
73 changed files with 5091 additions and 9 deletions
@@ -0,0 +1,70 @@
import type { BuilderFormTexts } from '../../../forms/builderTypes.js'
import type { ContactDetail, LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, RichTextData } from '../../data.js'
import { RenderForm } from '../../../forms/RenderForm.js'
import { RenderRichText } from '../../../richtext/RenderRichText.js'
import { headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type ContactBlockData = { content?: RichTextData; form?: unknown } & BaseBlockData
export const CONTACT_PARTS = {
aside: 'space-y-6',
content: 'space-y-4 text-fg',
detailLabel: 'text-sm text-fg-muted',
details: 'grid gap-4',
detailValue: 'font-medium text-fg-strong',
form: 'rounded-card border border-border bg-surface p-6 md:p-8',
grid: 'grid gap-gap md:grid-cols-2',
}
/** A form from the form builder (RenderForm) with text and contact details beside it. Needs `sendForm` in createBlockRegistry. */
export async function ContactBlock(props: LibraryBlockProps<ContactBlockData>) {
const { classNames, content, ctx, form, header, isFirst, locale, settings, ui, variant } = props
if (!ctx.sendForm || !ctx.content.getFormTexts) {
console.warn('[ipal] contact block: pass sendForm and content with getFormTexts to createBlockRegistry')
return null
}
const c = parts(CONTACT_PARTS, classNames)
const id = headingId(props)
const withDetails = variant !== 'formOnly'
const [texts, linkOptions, details] = await Promise.all([
ctx.content.getFormTexts(locale),
ctx.content.getLinkOptions?.(locale),
withDetails && ctx.contactDetails ? ctx.contactDetails(locale) : ([] as ContactDetail[]),
])
const formEl = (
<div className={c.form}>
<RenderForm action={ctx.sendForm} classNames={ctx.formClassNames} form={form as never} linkOptions={linkOptions} locale={locale} texts={texts as BuilderFormTexts} />
</div>
)
const aside = withDetails && (content || details.length) ? (
<div className={c.aside}>
{content ? <RenderRichText className={cx(c.content, ctx.richText?.className)} data={content as never} /> : null}
{details.length ? (
<dl className={c.details}>
{details.map((d) => (
<div key={d.label}>
<dt className={c.detailLabel}>{d.label}</dt>
<dd className={c.detailValue}>{d.href ? <a className="text-link hover:text-link-hover" href={d.href}>{d.value}</a> : d.value}</dd>
</div>
))}
</dl>
) : null}
</div>
) : null
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings} width={aside ? 'default' : 'narrow'}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
{aside ? (
<div className={c.grid}>
{aside}
{formEl}
</div>
) : (
formEl
)}
</ui.Section>
)
}
@@ -0,0 +1,30 @@
import type { BlockOptions } from '../../types.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildContentField } from '../../fields.js'
export const CONTACT_VARIANTS = [
variantOption('formWithDetails', 'Form and contact details', 'Formularz i dane kontaktowe'),
variantOption('formOnly', 'Form only', 'Tylko formularz'),
] as const
export type ContactOptions = {
/** The form builder collection. Default 'forms'. */
formsCollection?: string
} & BlockOptions
/** Contact — a form from the form builder, with text and contact details beside it. */
export const buildContactBlock = defineLibraryBlock<ContactOptions>({
slug: 'contact',
fields: ({ formsCollection = 'forms' }) => [
{ name: 'form', type: 'relationship', label: adminText('Form', 'Formularz'), relationTo: formsCollection, required: true },
buildContentField({
description: adminText('Shown beside the form, e.g. office hours.', 'Wyświetlany obok formularza, np. godziny pracy.'),
label: adminText('Side text', 'Tekst obok'),
}),
],
interfaceName: 'ContactBlock',
labels: { plural: adminText('Contact sections', 'Sekcje kontaktu'), singular: adminText('Contact', 'Kontakt') },
links: false,
variants: CONTACT_VARIANTS,
})
@@ -0,0 +1,50 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, MediaValue } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { parts } from '../../ui/cx.js'
export type CtaBlockData = { media?: MediaValue } & BaseBlockData
export const CTA_PARTS = {
band: 'flex flex-col items-start justify-between gap-6 md:flex-row md:items-center',
card: 'rounded-card bg-surface-raised p-8 text-center shadow-md md:p-12',
media: 'h-auto w-full rounded-media object-cover',
split: 'grid items-center gap-gap md:grid-cols-2',
}
/** A short heading with buttons: a band, a card, or beside an image. */
export function CtaBlock(props: LibraryBlockProps<CtaBlockData>) {
const { classNames, header, isFirst, links, locale, media, settings, ui, variant } = props
const c = parts(CTA_PARTS, classNames)
const id = headingId(props)
const as = isFirst ? 'h1' : 'h2'
const v = variant ?? 'band'
if (!header?.heading && !links?.length) {return null}
if (v === 'card') {
return (
<ui.Section block={props.blockType} compact labelledBy={id} settings={settings}>
<div className={c.card}>
<ui.SectionHeader align="center" as={as} className="mb-0" header={header} id={id} />
<Buttons className="justify-center" CMSLink={ui.CMSLink} links={links} locale={locale} />
</div>
</ui.Section>
)
}
return (
<ui.Section block={props.blockType} compact={v === 'band'} labelledBy={id} settings={settings}>
<div className={v === 'split' && media ? c.split : c.band}>
<div>
<ui.SectionHeader as={as} className="mb-0" header={header} id={id} />
{v === 'split' ? <Buttons CMSLink={ui.CMSLink} links={links} locale={locale} /> : null}
</div>
{v === 'split' ? (
<ui.Media className={c.media} resource={media} sizes={MEDIA_SIZES.half} />
) : (
<Buttons className="mt-0 shrink-0" CMSLink={ui.CMSLink} links={links} locale={locale} />
)}
</div>
</ui.Section>
)
}
@@ -0,0 +1,17 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildMediaField } from '../../fields.js'
export const CTA_VARIANTS = [
variantOption('band', 'Full-width band', 'Pas na całą szerokość'),
variantOption('card', 'Card', 'Karta'),
variantOption('split', 'Image beside text', 'Obraz obok tekstu'),
] as const
/** Call to action — a short heading with one or two buttons. */
export const buildCtaBlock = defineLibraryBlock({
slug: 'cta',
fields: () => [buildMediaField()],
interfaceName: 'CtaBlock',
labels: { plural: adminText('Calls to action', 'Wezwania do działania'), singular: adminText('Call to action', 'Wezwanie do działania') },
variants: CTA_VARIANTS,
})
@@ -0,0 +1,80 @@
import type { EntryCard, LibraryBlockProps } from '../../context.js'
import type { BaseBlockData } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
import { TitleLink } from '../../ui/TitleLink.js'
export type EntryListBlockData = {
collection?: null | string
entries?: { relationTo: string; value: unknown }[] | null
limit?: null | number
mode?: null | string
} & BaseBlockData
export const ENTRY_LIST_PARTS = {
card: 'gap-3 overflow-hidden',
cards: 'grid gap-gap sm:grid-cols-2 lg:grid-cols-3',
date: 'text-sm text-fg-muted',
list: 'grid gap-6',
media: 'aspect-[3/2] h-auto w-full object-cover',
text: 'text-fg-muted',
title: 'font-heading text-h4 leading-heading text-fg-strong',
}
const str = (v: unknown) => (typeof v === 'string' && v.trim() ? v : undefined)
/** Default entry card: title, excerpt / description, media / image / cover, publishedAt. */
export function defaultEntryCard(doc: Record<string, unknown>): EntryCard | null {
const title = str(doc.title) ?? str(doc.name)
if (!title) {return null}
return { date: str(doc.publishedAt) ?? null, media: doc.media ?? doc.image ?? doc.cover, text: str(doc.excerpt) ?? str(doc.description) ?? null, title }
}
type Row = { card: EntryCard; collection: string; doc: Record<string, unknown> }
/** The latest entries of a collection, or entries chosen by hand; each card links to its entry. */
export async function EntryListBlock(props: LibraryBlockProps<EntryListBlockData>) {
const { classNames, collection, ctx, entries, header, isFirst, limit, links, locale, mode, settings, ui, variant } = props
const toCard = ctx.entryCard ?? defaultEntryCard
let docs: { collection: string; doc: Record<string, unknown> }[] = []
if (mode === 'selected') {
docs = (entries ?? []).flatMap((e) => (e?.value && typeof e.value === 'object' ? [{ collection: e.relationTo, doc: e.value as Record<string, unknown> }] : []))
} else if (collection && ctx.content.getEntries) {
const result = await ctx.content.getEntries(collection, locale, 1, limit ?? 3)
docs = result.docs.map((doc) => ({ collection, doc }))
}
const rows = docs.flatMap((d): Row[] => {
const card = toCard(d.doc, d.collection)
return card ? [{ ...d, card }] : []
})
if (!rows.length) {return null}
const c = parts(ENTRY_LIST_PARTS, classNames)
const id = headingId(props)
const dates = new Intl.DateTimeFormat(locale, { dateStyle: 'long' })
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={variant === 'list' ? c.list : c.cards}>
{rows.map(({ card, collection: from, doc }, i) => (
<li className="flex" key={typeof doc.id === 'string' || typeof doc.id === 'number' ? doc.id : i}>
<ui.Card className={cx('w-full', c.card)} interactive>
{variant === 'list' ? null : <ui.Media className={c.media} resource={card.media as never} sizes={MEDIA_SIZES.third} />}
<div className="flex flex-col gap-2 p-6 pt-0 first:pt-6">
{card.date ? <time className={c.date} dateTime={card.date}>{dates.format(new Date(card.date))}</time> : null}
<h3 className={c.title}>
<TitleLink link={{ type: 'internal', page: { relationTo: from, value: doc } }} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink}>
{card.title}
</TitleLink>
</h3>
{card.text ? <p className={c.text}>{card.text}</p> : null}
</div>
</ui.Card>
</li>
))}
</ul>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,63 @@
import type { AdminText } from '../../../admin-i18n/define.js'
import type { BlockOptions } from '../../types.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
export const ENTRY_LIST_VARIANTS = [variantOption('cards', 'Cards', 'Karty'), variantOption('list', 'List', 'Lista')] as const
export type EntryListOptions = {
/** Content collections the editor picks from (they need URLs: ipalKit `content`). Default posts. */
collections?: readonly { label: AdminText; value: string }[]
} & BlockOptions
const DEFAULT_COLLECTIONS = [{ label: adminText('Posts', 'Wpisy'), value: 'posts' }]
/** Entry list — the latest or chosen entries of a collection (posts, projects, products). */
export const buildEntryListBlock = defineLibraryBlock<EntryListOptions>({
slug: 'entryList',
fields: ({ collections = DEFAULT_COLLECTIONS, maxItems = 12 }) => {
const latest = (_: unknown, s: { mode?: string } | undefined) => s?.mode !== 'selected'
return [
{
name: 'collection',
type: 'select',
defaultValue: collections[0]?.value,
label: adminText('Show', 'Pokaż'),
options: collections.map((c) => ({ label: c.label, value: c.value })),
required: true,
},
{
name: 'mode',
type: 'radio',
defaultValue: 'latest',
label: adminText('Entries', 'Wpisy'),
options: [
{ label: adminText('The latest', 'Najnowsze'), value: 'latest' },
{ label: adminText('Chosen by hand', 'Wybrane ręcznie'), value: 'selected' },
],
},
{
name: 'limit',
type: 'number',
admin: { condition: latest },
defaultValue: 3,
label: adminText('How many', 'Liczba wpisów'),
max: maxItems,
min: 1,
},
{
name: 'entries',
type: 'relationship',
admin: { condition: (d: unknown, s: { mode?: string } | undefined) => !latest(d, s) },
hasMany: true,
label: adminText('Chosen entries', 'Wybrane wpisy'),
maxRows: maxItems,
relationTo: collections.map((c) => c.value),
},
]
},
interfaceName: 'EntryListBlock',
labels: { plural: adminText('Entry lists', 'Listy wpisów'), singular: adminText('Entry list', 'Lista wpisów') },
links: { maxRows: 1 },
variants: ENTRY_LIST_VARIANTS,
})
@@ -0,0 +1,44 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData } from '../../data.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type FaqItem = { answer: string; id?: null | string; question: string }
export type FaqBlockData = { items?: FaqItem[] | null } & BaseBlockData
export const FAQ_PARTS = {
answer: 'whitespace-pre-line px-5 pb-5 text-fg-muted',
item: 'group rounded-card border border-border bg-surface',
list: 'grid gap-3',
marker: 'shrink-0 text-fg-muted transition-transform duration-fast ease-out group-open:rotate-45',
question:
'flex cursor-pointer list-none items-center justify-between gap-4 p-5 font-medium text-fg-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus [&::-webkit-details-marker]:hidden',
twoColumn: 'md:grid-cols-2 md:items-start',
}
/** Questions as native <details>: keyboard and screen readers work with no script. */
export function FaqBlock(props: LibraryBlockProps<FaqBlockData>) {
const { classNames, header, isFirst, items, links, locale, settings, ui, variant } = props
const shown = (items ?? []).filter((i) => i.question && i.answer)
if (!shown.length) {return null}
const c = parts(FAQ_PARTS, classNames)
const id = headingId(props)
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<div className={cx(c.list, variant === 'twoColumn' && c.twoColumn)}>
{shown.map((item, i) => (
<details className={c.item} key={item.id ?? i}>
<summary className={c.question}>
<span>{item.question}</span>
<span aria-hidden className={c.marker}>+</span>
</summary>
<p className={c.answer}>{item.answer}</p>
</details>
))}
</div>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,24 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField } from '../../fields.js'
export const FAQ_VARIANTS = [variantOption('single', 'One column', 'Jedna kolumna'), variantOption('twoColumn', 'Two columns', 'Dwie kolumny')] as const
/** FAQ — questions that open to show the answer; feeds FAQ rich results (faqItemsFromLayout). */
export const buildFaqBlock = defineLibraryBlock({
slug: 'faq',
fields: ({ maxItems = 30 }) => [
buildItemsField({
fields: [
{ name: 'question', type: 'text', label: adminText('Question', 'Pytanie'), localized: true, required: true },
{ name: 'answer', type: 'textarea', admin: { rows: 4 }, label: adminText('Answer', 'Odpowiedź'), localized: true, required: true },
],
labels: { plural: adminText('Questions', 'Pytania'), singular: adminText('Question', 'Pytanie') },
maxRows: maxItems,
rowLabelField: 'question',
}),
],
interfaceName: 'FaqBlock',
labels: { plural: adminText('FAQs', 'Pytania i odpowiedzi'), singular: adminText('FAQ', 'Pytania i odpowiedzi') },
links: { maxRows: 1 },
variants: FAQ_VARIANTS,
})
@@ -0,0 +1,70 @@
import type { BlockContext, BlockUi, LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, LinkData, MediaValue } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, GRID_COLUMNS, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
import { TitleLink } from '../../ui/TitleLink.js'
export type FeatureItem = { heading: string; icon?: null | string; id?: null | string; link?: LinkData; media?: MediaValue; text?: null | string }
export type FeatureGridBlockData = { columns?: null | string; items?: FeatureItem[] | null } & BaseBlockData
export const FEATURE_GRID_PARTS = {
card: 'gap-3 p-6',
grid: 'grid gap-gap',
heading: 'font-heading text-h4 leading-heading text-fg-strong',
icon: 'h-8 w-8 text-primary',
list: 'grid gap-gap',
media: 'mb-2 h-auto w-full rounded-media object-cover',
number: 'font-heading text-h3 text-primary',
text: 'text-fg-muted',
}
/** Cards, a plain list or numbered items; a feature with a link makes its whole card clickable. */
export function FeatureGridBlock(props: LibraryBlockProps<FeatureGridBlockData>) {
const { classNames, columns, ctx, header, isFirst, items, links, locale, settings, ui, variant } = props
if (!items?.length) {return null}
const c = parts(FEATURE_GRID_PARTS, classNames)
const id = headingId(props)
const v = variant ?? 'cards'
const List = v === 'numbered' ? 'ol' : 'ul'
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<List className={cx(v === 'list' ? c.list : c.grid, GRID_COLUMNS[columns ?? 'three'])}>
{items.map((item, i) => (
<li className="flex" key={item.id ?? i}>
<FeatureCard c={c} ctx={ctx} index={v === 'numbered' ? i + 1 : undefined} item={item} locale={locale} plain={v === 'list'} ui={ui} />
</li>
))}
</List>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
function FeatureCard({ c, ctx, index, item, locale, plain, ui }: { c: typeof FEATURE_GRID_PARTS; ctx: BlockContext; index?: number; item: FeatureItem; locale: string; plain: boolean; ui: BlockUi }) {
const Icon = item.icon ? ctx.icons?.[item.icon] : undefined
const heading = item.link ? (
<TitleLink link={item.link} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink}>
{item.heading}
</TitleLink>
) : (
item.heading
)
const body = (
<>
{index ? <span aria-hidden className={c.number}>{String(index).padStart(2, '0')}</span> : null}
{Icon ? <Icon aria-hidden className={c.icon} /> : null}
<ui.Media className={c.media} resource={item.media} sizes={MEDIA_SIZES.third} />
<h3 className={c.heading}>{heading}</h3>
{item.text ? <p className={c.text}>{item.text}</p> : null}
</>
)
if (plain) {return <div className={cx('relative flex flex-col', c.card)}>{body}</div>}
return (
<ui.Card className={cx('w-full', c.card)} interactive={Boolean(item.link)}>
{body}
</ui.Card>
)
}
@@ -0,0 +1,42 @@
import type { Field } from 'payload'
import type { BlockOptions } from '../../types.js'
import { buildLinkField } from '../../../links/buildLinkField.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildIconField, buildItemsField, buildMediaField } from '../../fields.js'
import { columnsField } from '../../shared.js'
export const FEATURE_GRID_VARIANTS = [
variantOption('cards', 'Cards', 'Karty'),
variantOption('list', 'List', 'Lista'),
variantOption('numbered', 'Numbered', 'Numerowane'),
] as const
export type FeatureGridOptions = {
/** The project's icon names — adds an icon select to each feature. Default none (images only). */
icons?: readonly string[]
} & BlockOptions
/** Feature grid — cards with an image or icon, heading, text and a link (services, advantages, categories). */
export const buildFeatureGridBlock = defineLibraryBlock<FeatureGridOptions>({
slug: 'featureGrid',
fields: ({ icons, maxItems = 12 }) => [
buildItemsField({
fields: [
...(icons?.length ? [buildIconField({ names: icons })] : []),
buildMediaField(),
{ name: 'heading', type: 'text', label: adminText('Heading', 'Nagłówek'), localized: true, required: true },
{ name: 'text', type: 'textarea', admin: { rows: 3 }, label: adminText('Text', 'Tekst'), localized: true },
buildLinkField({ appearances: false }),
] as Field[],
labels: { plural: adminText('Features', 'Elementy'), singular: adminText('Feature', 'Element') },
maxRows: maxItems,
}),
columnsField(),
],
interfaceName: 'FeatureGridBlock',
labels: { plural: adminText('Feature grids', 'Siatki elementów'), singular: adminText('Feature grid', 'Siatka elementów') },
links: { maxRows: 1 },
variants: FEATURE_GRID_VARIANTS,
})
@@ -0,0 +1,58 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, MediaValue } from '../../data.js'
import { lightboxImage } from '../../../lightbox/lightboxImage.js'
import { LightboxTrigger } from '../../../lightbox/LightboxProvider.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, GRID_COLUMNS, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type GalleryItem = { caption?: null | string; id?: null | string; media?: MediaValue }
export type GalleryBlockData = { columns?: null | string; items?: GalleryItem[] | null } & BaseBlockData
export const GALLERY_PARTS = {
caption: 'mt-2 text-sm text-fg-muted',
grid: 'grid gap-4',
image: 'h-full w-full rounded-media object-cover',
item: 'm-0',
masonry: 'columns-1 gap-4 sm:columns-2 lg:columns-3 [&>*]:mb-4 [&>*]:break-inside-avoid',
trigger: 'block w-full overflow-hidden rounded-media focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus',
}
/** Images in a grid or a mosaic; each opens in the site's image viewer (one group per gallery). */
export function GalleryBlock(props: LibraryBlockProps<GalleryBlockData>) {
const { classNames, columns, ctx, header, isFirst, items, links, locale, settings, ui, variant } = props
const shown = (items ?? []).filter((item) => item.media)
if (!shown.length) {return null}
const c = parts(GALLERY_PARTS, classNames)
const id = headingId(props)
const group = `gallery-${props.id ?? 'block'}`
const masonry = variant === 'masonry'
const sizes = columns === 'two' ? MEDIA_SIZES.half : columns === 'four' ? MEDIA_SIZES.quarter : MEDIA_SIZES.third
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings} width="wide">
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={masonry ? c.masonry : cx(c.grid, GRID_COLUMNS[columns ?? 'three'])}>
{shown.map((item, i) => {
const image = <ui.Media className={c.image} resource={item.media} sizes={sizes} />
const large = ctx.lightbox ? lightboxImage(item.media, item.caption ? { caption: item.caption } : {}) : null
return (
<li key={item.id ?? i}>
<figure className={c.item}>
{large ? (
<LightboxTrigger className={c.trigger} group={group} image={large}>
{image}
</LightboxTrigger>
) : (
image
)}
{item.caption ? <figcaption className={c.caption}>{item.caption}</figcaption> : null}
</figure>
</li>
)
})}
</ul>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,26 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField, buildMediaField } from '../../fields.js'
import { columnsField } from '../../shared.js'
export const GALLERY_VARIANTS = [variantOption('grid', 'Even grid', 'Równa siatka'), variantOption('masonry', 'Mosaic', 'Mozaika')] as const
/** Gallery — images that open enlarged in the site's image viewer. */
export const buildGalleryBlock = defineLibraryBlock({
slug: 'gallery',
fields: ({ maxItems = 48 }) => [
buildItemsField({
fields: [
buildMediaField({ required: true }),
{ name: 'caption', type: 'text', label: adminText('Caption', 'Podpis'), localized: true },
],
labels: { plural: adminText('Images', 'Obrazy'), singular: adminText('Image', 'Obraz') },
maxRows: maxItems,
rowLabelField: ['caption', 'media.alt', 'media.filename'],
}),
columnsField(),
],
interfaceName: 'GalleryBlock',
labels: { plural: adminText('Galleries', 'Galerie'), singular: adminText('Gallery', 'Galeria') },
links: { maxRows: 1 },
variants: GALLERY_VARIANTS,
})
@@ -0,0 +1,54 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, MediaValue } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type HeroBlockData = { media?: MediaValue; poster?: MediaValue } & BaseBlockData
export const HERO_PARTS = {
background: 'relative isolate flex min-h-[var(--ipal-hero-min-h)] items-center overflow-hidden',
backgroundMedia: 'absolute inset-0 -z-10 h-full w-full object-cover',
backgroundOverlay: 'absolute inset-0 -z-10 bg-linear-to-t from-overlay to-transparent',
centered: 'mx-auto max-w-narrow text-center',
media: 'h-auto w-full rounded-media object-cover',
page: 'max-w-measure',
split: 'grid items-center gap-gap md:grid-cols-2',
}
/** Hero: split (image beside), background (image behind with a scrim), centered, page (small header). */
export function HeroBlock(props: LibraryBlockProps<HeroBlockData>) {
const { classNames, header, isFirst = true, links, locale, media, poster, settings, ui, variant } = props
const c = parts(HERO_PARTS, classNames)
const v = variant ?? 'split'
const id = headingId(props)
const as = isFirst ? 'h1' : 'h2'
const title = <ui.SectionHeader align={v === 'centered' ? 'center' : 'start'} as={as} className="mb-0" display={v !== 'page'} header={header} id={id} />
const buttons = <Buttons className={v === 'centered' ? 'justify-center' : undefined} CMSLink={ui.CMSLink} links={links} locale={locale} />
if (v === 'background') {
return (
<ui.Section block={props.blockType} className={c.background} labelledBy={id} settings={{ ...settings, background: 'inverted' }}>
<ui.Media alt="" className={c.backgroundMedia} poster={poster} priority={isFirst} resource={media} sizes={MEDIA_SIZES.full} videoMode="background" />
<span aria-hidden className={c.backgroundOverlay} />
<div className={c.page}>
{title}
{buttons}
</div>
</ui.Section>
)
}
const withMedia = v === 'split' && media
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<div className={cx(withMedia ? c.split : v === 'centered' ? c.centered : c.page)}>
<div>
{title}
{buttons}
</div>
{withMedia ? <ui.Media className={c.media} poster={poster} priority={isFirst} resource={media} sizes={MEDIA_SIZES.half} /> : null}
</div>
</ui.Section>
)
}
@@ -0,0 +1,27 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildMediaField } from '../../fields.js'
export const HERO_VARIANTS = [
variantOption('split', 'Image beside text', 'Obraz obok tekstu'),
variantOption('background', 'Image behind text', 'Obraz pod tekstem'),
variantOption('centered', 'Centred text', 'Tekst na środku'),
variantOption('page', 'Small page header', 'Mały nagłówek strony'),
] as const
/** Hero — the first section of a page: heading, image or video, buttons. */
export const buildHeroBlock = defineLibraryBlock({
slug: 'hero',
fields: () => [
buildMediaField({ label: adminText('Image or video', 'Obraz lub wideo') }),
{
name: 'poster',
type: 'upload',
admin: { description: adminText('Shown before a video starts; not needed for an image.', 'Wyświetlana przed startem wideo; zbędna przy obrazie.') },
label: adminText('Video poster', 'Okładka wideo'),
relationTo: 'media',
},
],
interfaceName: 'HeroBlock',
labels: { plural: adminText('Heroes', 'Sekcje główne'), singular: adminText('Hero', 'Sekcja główna') },
variants: HERO_VARIANTS,
})
@@ -0,0 +1,50 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, LinkData, MediaValue } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { headingId } from '../../ui/Buttons.js'
import { parts } from '../../ui/cx.js'
export type LogoItem = { heading: string; id?: null | string; link?: LinkData; media?: MediaValue }
export type LogosBlockData = { items?: LogoItem[] | null } & BaseBlockData
export const LOGOS_PARTS = {
grid: 'grid grid-cols-2 items-center gap-8 sm:grid-cols-3 lg:grid-cols-6',
image: 'mx-auto h-12 w-auto object-contain',
row: 'flex flex-wrap items-center justify-center gap-x-12 gap-y-8',
}
const altOf = (item: LogoItem) => {
const alt = item.media && typeof item.media === 'object' ? (item.media as { alt?: unknown }).alt : undefined
return typeof alt === 'string' && alt.trim() ? alt : item.heading
}
/** Logos in a row or a grid; the name is the alt text when the image has none, and a link's name. */
export function LogosBlock(props: LibraryBlockProps<LogosBlockData>) {
const { classNames, header, isFirst, items, locale, settings, ui, variant } = props
const shown = (items ?? []).filter((i) => i.media)
if (!shown.length) {return null}
const c = parts(LOGOS_PARTS, classNames)
const id = headingId(props)
return (
<ui.Section block={props.blockType} compact labelledBy={id} settings={settings}>
<ui.SectionHeader align="center" as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={variant === 'grid' ? c.grid : c.row}>
{shown.map((item, i) => {
const logo = <ui.Media alt={altOf(item)} className={c.image} resource={item.media} sizes={MEDIA_SIZES.thumb} />
return (
<li key={item.id ?? i}>
{item.link ? (
<ui.CMSLink className="block" link={item.link} locale={locale}>
{logo}
</ui.CMSLink>
) : (
logo
)}
</li>
)
})}
</ul>
</ui.Section>
)
}
@@ -0,0 +1,27 @@
import type { Field } from 'payload'
import { buildLinkField } from '../../../links/buildLinkField.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField, buildMediaField } from '../../fields.js'
export const LOGOS_VARIANTS = [variantOption('row', 'One row', 'Jeden rząd'), variantOption('grid', 'Grid', 'Siatka')] as const
/** Logos — clients, partners or certificates; the name is the alt text when the image has none. */
export const buildLogosBlock = defineLibraryBlock({
slug: 'logos',
fields: ({ maxItems = 24 }) => [
buildItemsField({
fields: [
buildMediaField({ label: adminText('Logo', 'Logo'), required: true }),
{ name: 'heading', type: 'text', label: adminText('Name', 'Nazwa'), localized: true, required: true },
buildLinkField({ appearances: false, disableLabel: true }),
] as Field[],
labels: { plural: adminText('Logos', 'Logotypy'), singular: adminText('Logo', 'Logo') },
maxRows: maxItems,
}),
],
interfaceName: 'LogosBlock',
labels: { plural: adminText('Logos', 'Logotypy'), singular: adminText('Logos', 'Logotypy') },
links: false,
variants: LOGOS_VARIANTS,
})
@@ -0,0 +1,72 @@
import type { BlockUi, LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, LinkData } from '../../data.js'
import { headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type PricingPlan = {
features?: { id?: null | string; text: string }[] | null
heading: string
highlighted?: boolean | null
id?: null | string
link?: LinkData
period?: null | string
price: string
text?: null | string
}
export type PricingBlockData = { highlightLabel?: null | string; items?: null | PricingPlan[]; note?: null | string } & BaseBlockData
export const PRICING_PARTS = {
name: 'font-heading text-h4 text-fg-strong',
badge: 'self-start rounded-full bg-accent px-3 py-1 text-xs font-medium text-on-accent',
feature: "flex gap-2 before:text-primary before:content-['✓']",
features: 'grid gap-2 text-sm',
grid: 'grid gap-gap md:grid-cols-2 lg:grid-cols-3',
highlighted: 'border-2 border-primary shadow-md',
note: 'mt-8 text-sm text-fg-muted',
period: 'text-fg-muted',
plan: 'gap-4 p-6',
price: 'font-heading text-h2 text-fg-strong',
}
/** Plans side by side; the highlighted plan carries a text label (not only a colour). */
export function PricingBlock(props: LibraryBlockProps<PricingBlockData>) {
const { classNames, header, highlightLabel, isFirst, items, locale, note, settings, ui } = props
if (!items?.length) {return null}
const c = parts(PRICING_PARTS, classNames)
const id = headingId(props)
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={c.grid}>
{items.map((plan, i) => (
<li className="flex" key={plan.id ?? i}>
<Plan c={c} highlightLabel={highlightLabel} locale={locale} plan={plan} ui={ui} />
</li>
))}
</ul>
{note ? <p className={c.note}>{note}</p> : null}
</ui.Section>
)
}
function Plan({ c, highlightLabel, locale, plan, ui }: { c: typeof PRICING_PARTS; highlightLabel?: null | string; locale: string; plan: PricingPlan; ui: BlockUi }) {
return (
<ui.Card className={cx('w-full', c.plan, plan.highlighted && c.highlighted)}>
{plan.highlighted && highlightLabel ? <p className={c.badge}>{highlightLabel}</p> : null}
<h3 className={c.name}>{plan.heading}</h3>
<p>
<span className={c.price}>{plan.price}</span> {plan.period ? <span className={c.period}>{plan.period}</span> : null}
</p>
{plan.text ? <p className="text-fg-muted">{plan.text}</p> : null}
{plan.features?.length ? (
<ul className={c.features}>
{plan.features.map((f, i) => (
<li className={c.feature} key={f.id ?? i}>{f.text}</li>
))}
</ul>
) : null}
{plan.link ? <div className="mt-auto pt-4"><ui.CMSLink link={plan.link} locale={locale} /></div> : null}
</ui.Card>
)
}
@@ -0,0 +1,58 @@
import type { Field } from 'payload'
import { buildLinkField } from '../../../links/buildLinkField.js'
import { adminText, defineLibraryBlock } from '../../define.js'
import { buildItemsField } from '../../fields.js'
/** Pricing — plans with a price, what is included and a button; one plan can be highlighted. */
export const buildPricingBlock = defineLibraryBlock({
slug: 'pricing',
fields: ({ maxItems = 6 }) => [
buildItemsField({
fields: [
{ name: 'heading', type: 'text', label: adminText('Plan name', 'Nazwa pakietu'), localized: true, required: true },
{
type: 'row',
fields: [
{ name: 'price', type: 'text', admin: { placeholder: adminText('$49', '199 zł'), width: '50%' }, label: adminText('Price', 'Cena'), localized: true, required: true },
{ name: 'period', type: 'text', admin: { placeholder: adminText('/ month', '/ miesiąc'), width: '50%' }, label: adminText('Period', 'Okres'), localized: true },
],
},
{ name: 'text', type: 'textarea', admin: { rows: 2 }, label: adminText('Short description', 'Krótki opis'), localized: true },
buildItemsField({
name: 'features',
fields: [{ name: 'text', type: 'text', label: adminText('Included', 'W pakiecie'), localized: true, required: true }],
labels: { plural: adminText('Included items', 'Elementy pakietu'), singular: adminText('Included item', 'Element pakietu') },
rowLabelField: 'text',
}),
{
name: 'highlighted',
type: 'checkbox',
admin: { description: adminText('Marks this plan with the highlight label.', 'Oznacza ten pakiet etykietą wyróżnienia.') },
defaultValue: false,
label: adminText('Highlight this plan', 'Wyróżnij ten pakiet'),
},
buildLinkField(),
] as Field[],
labels: { plural: adminText('Plans', 'Pakiety'), singular: adminText('Plan', 'Pakiet') },
maxRows: maxItems,
}),
{
name: 'highlightLabel',
type: 'text',
admin: { placeholder: adminText('Most popular', 'Najczęściej wybierany') },
label: adminText('Highlight label', 'Etykieta wyróżnienia'),
localized: true,
},
{
name: 'note',
type: 'textarea',
admin: { description: adminText('Shown under the plans, e.g. prices without VAT.', 'Wyświetlana pod pakietami, np. ceny netto.'), rows: 2 },
label: adminText('Note', 'Uwaga'),
localized: true,
},
],
interfaceName: 'PricingBlock',
labels: { plural: adminText('Pricing', 'Cenniki'), singular: adminText('Pricing', 'Cennik') },
links: false,
})
@@ -0,0 +1,41 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, RichTextData } from '../../data.js'
import { extractHeadings } from '../../../richtext/headings.js'
import { RenderRichText } from '../../../richtext/RenderRichText.js'
import { TableOfContents } from '../../../richtext/TableOfContents.js'
import { headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type RichTextBlockData = { content?: RichTextData; tableOfContents?: { label?: null | string; show?: boolean | null } | null } & BaseBlockData
export const RICH_TEXT_PARTS = {
content: 'space-y-4 text-fg [&_a]:text-link [&_a:hover]:text-link-hover [&_h2]:mt-10 [&_h2]:font-heading [&_h2]:text-h3 [&_h2]:text-fg-strong [&_h3]:mt-8 [&_h3]:font-heading [&_h3]:text-h4 [&_h3]:text-fg-strong [&_ol]:list-decimal [&_ol]:pl-6 [&_ul]:list-disc [&_ul]:pl-6',
layout: 'grid gap-gap lg:grid-cols-[16rem_1fr]',
toc: 'self-start text-sm lg:sticky lg:top-24',
}
/** A text section; with a table of contents its headings get anchor ids and a list beside the text. */
export function RichTextBlock(props: LibraryBlockProps<RichTextBlockData>) {
const { classNames, content, ctx, header, isFirst, settings, tableOfContents, ui, variant } = props
if (!content) {return null}
const c = parts(RICH_TEXT_PARTS, classNames)
const id = headingId(props)
const toc = tableOfContents?.show ? extractHeadings(content) : []
const text = <RenderRichText className={cx(c.content, ctx.richText?.className)} data={content as never} headingIds={toc.length > 0} />
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings} width={variant === 'wide' || toc.length ? 'default' : 'narrow'}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
{toc.length ? (
<div className={c.layout}>
<div className={c.toc}>
<TableOfContents items={toc} label={tableOfContents?.label ?? undefined} />
</div>
<div className="max-w-measure">{text}</div>
</div>
) : (
text
)}
</ui.Section>
)
}
@@ -0,0 +1,15 @@
import { buildTableOfContentsField } from '../../../richtext/headings.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildContentField } from '../../fields.js'
export const RICH_TEXT_VARIANTS = [variantOption('narrow', 'Narrow column', 'Wąska kolumna'), variantOption('wide', 'Full width', 'Pełna szerokość')] as const
/** Text — a formatted text section (legal pages, articles), with an optional table of contents. */
export const buildRichTextBlock = defineLibraryBlock({
slug: 'richText',
fields: () => [buildContentField({ required: true }), buildTableOfContentsField()],
interfaceName: 'RichTextBlock',
labels: { plural: adminText('Text sections', 'Sekcje tekstu'), singular: adminText('Text', 'Tekst') },
links: false,
variants: RICH_TEXT_VARIANTS,
})
@@ -0,0 +1,42 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData } from '../../data.js'
import { headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type StatItem = { heading: string; id?: null | string; text?: null | string; value: string }
export type StatsBlockData = { items?: null | StatItem[] } & BaseBlockData
export const STATS_PARTS = {
card: 'rounded-card border border-border bg-surface p-6 shadow-sm',
item: 'flex flex-col-reverse gap-1',
label: 'font-medium text-fg-strong',
list: 'grid gap-gap sm:grid-cols-2 lg:grid-cols-4',
text: 'text-sm text-fg-muted',
value: 'm-0 font-heading text-display leading-none text-primary',
}
/** Key figures as a description list (number + label). Static: no count-up animation. */
export function StatsBlock(props: LibraryBlockProps<StatsBlockData>) {
const { classNames, header, isFirst, items, settings, ui, variant } = props
const shown = (items ?? []).filter((i) => i.value && i.heading)
if (!shown.length) {return null}
const c = parts(STATS_PARTS, classNames)
const id = headingId(props)
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<dl className={c.list}>
{shown.map((s, i) => (
<div className={cx(c.item, variant === 'cards' && c.card)} key={s.id ?? i}>
<dt className={c.label}>
{s.heading}
{s.text ? <span className={cx('block font-normal', c.text)}>{s.text}</span> : null}
</dt>
<dd className={c.value}>{s.value}</dd>
</div>
))}
</dl>
</ui.Section>
)
}
@@ -0,0 +1,29 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField } from '../../fields.js'
export const STATS_VARIANTS = [variantOption('row', 'One row', 'Jeden rząd'), variantOption('cards', 'Cards', 'Karty')] as const
/** Key figures — a few numbers with a label ("120 projects"). Not the site's visit statistics. */
export const buildStatsBlock = defineLibraryBlock({
slug: 'stats',
fields: ({ maxItems = 6 }) => [
buildItemsField({
fields: [
{
type: 'row',
fields: [
{ name: 'value', type: 'text', admin: { placeholder: adminText('120+', '120+'), width: '40%' }, label: adminText('Number', 'Liczba'), localized: true, required: true },
{ name: 'heading', type: 'text', admin: { width: '60%' }, label: adminText('Label', 'Opis liczby'), localized: true, required: true },
],
},
{ name: 'text', type: 'textarea', admin: { rows: 2 }, label: adminText('Extra text', 'Dodatkowy tekst'), localized: true },
],
labels: { plural: adminText('Figures', 'Liczby'), singular: adminText('Figure', 'Liczba') },
maxRows: maxItems,
}),
],
interfaceName: 'StatsBlock',
labels: { plural: adminText('Key figures', 'Liczby'), singular: adminText('Key figures', 'Liczby') },
links: false,
variants: STATS_VARIANTS,
})
@@ -0,0 +1,50 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, MediaValue } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { blockTexts, fillText } from '../../texts.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type StepItem = { heading: string; id?: null | string; media?: MediaValue; text?: null | string }
export type StepsBlockData = { items?: null | StepItem[] } & BaseBlockData
export const STEPS_PARTS = {
heading: 'font-heading text-h4 leading-heading text-fg-strong',
item: 'grid grid-cols-[3rem_1fr] gap-4',
list: 'grid gap-8',
media: 'mt-3 h-auto w-full max-w-md rounded-media object-cover',
number: 'flex h-12 w-12 items-center justify-center rounded-full bg-primary font-heading text-lg text-on-primary',
text: 'mt-1 text-fg-muted',
timeline: 'relative before:absolute before:top-0 before:bottom-0 before:left-6 before:w-px before:bg-border',
}
/** Steps in an ordered list, numbered or along a line. */
export function StepsBlock(props: LibraryBlockProps<StepsBlockData>) {
const { classNames, ctx, header, isFirst, items, links, locale, settings, ui, variant } = props
if (!items?.length) {return null}
const c = parts(STEPS_PARTS, classNames)
const texts = blockTexts(locale, ctx.texts)
const id = headingId(props)
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ol className={cx(c.list, variant === 'timeline' && c.timeline)}>
{items.map((s, i) => (
<li className={c.item} key={s.id ?? i}>
<span aria-hidden className={cx(c.number, 'relative')}>{i + 1}</span>
<div>
<h3 className={c.heading}>
<span className="sr-only">{fillText(texts.step, i + 1)}: </span>
{s.heading}
</h3>
{s.text ? <p className={c.text}>{s.text}</p> : null}
<ui.Media className={c.media} resource={s.media} sizes={MEDIA_SIZES.half} />
</div>
</li>
))}
</ol>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,23 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField, buildMediaField } from '../../fields.js'
export const STEPS_VARIANTS = [variantOption('numbered', 'Numbered', 'Numerowane'), variantOption('timeline', 'Timeline', 'Oś czasu')] as const
/** Steps — a process or timeline in order. */
export const buildStepsBlock = defineLibraryBlock({
slug: 'steps',
fields: ({ maxItems = 10 }) => [
buildItemsField({
fields: [
{ name: 'heading', type: 'text', label: adminText('Heading', 'Nagłówek'), localized: true, required: true },
{ name: 'text', type: 'textarea', admin: { rows: 3 }, label: adminText('Text', 'Tekst'), localized: true },
buildMediaField(),
],
labels: { plural: adminText('Steps', 'Kroki'), singular: adminText('Step', 'Krok') },
maxRows: maxItems,
}),
],
interfaceName: 'StepsBlock',
labels: { plural: adminText('Steps', 'Kroki'), singular: adminText('Steps', 'Kroki') },
variants: STEPS_VARIANTS,
})
@@ -0,0 +1,49 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, LinkData, MediaValue } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
import { TitleLink } from '../../ui/TitleLink.js'
export type TeamMember = { bio?: null | string; heading: string; id?: null | string; link?: LinkData; media?: MediaValue; text?: null | string }
export type TeamBlockData = { items?: null | TeamMember[] } & BaseBlockData
export const TEAM_PARTS = {
name: 'font-heading text-h4 leading-heading text-fg-strong',
bio: 'text-sm text-fg-muted',
grid: 'grid gap-gap sm:grid-cols-2 lg:grid-cols-3',
list: 'grid gap-6',
listItem: 'grid gap-6 sm:grid-cols-[10rem_1fr] sm:items-start',
photo: 'aspect-square h-auto w-full rounded-media object-cover',
role: 'text-sm text-fg-muted',
}
/** People with a photo, name, role, a short bio and a profile link (the name links to it). */
export function TeamBlock(props: LibraryBlockProps<TeamBlockData>) {
const { classNames, ctx, header, isFirst, items, links, locale, settings, ui, variant } = props
if (!items?.length) {return null}
const c = parts(TEAM_PARTS, classNames)
const id = headingId(props)
const list = variant === 'list'
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={list ? c.list : c.grid}>
{items.map((m, i) => (
<li className={cx('flex flex-col gap-3', list && c.listItem)} key={m.id ?? i}>
<ui.Media className={c.photo} resource={m.media} sizes={list ? '10rem' : MEDIA_SIZES.third} />
<div className="flex flex-col gap-1">
<h3 className={c.name}><TitleLink link={m.link} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink} stretch={false}>
{m.heading}
</TitleLink></h3>
{m.text ? <p className={c.role}>{m.text}</p> : null}
{m.bio ? <p className={c.bio}>{m.bio}</p> : null}
</div>
</li>
))}
</ul>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,34 @@
import type { Field } from 'payload'
import { buildLinkField } from '../../../links/buildLinkField.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField, buildMediaField } from '../../fields.js'
export const TEAM_VARIANTS = [variantOption('grid', 'Grid', 'Siatka'), variantOption('list', 'List', 'Lista')] as const
/** Team — people with a photo, name, role and a profile link. */
export const buildTeamBlock = defineLibraryBlock({
slug: 'team',
fields: ({ maxItems = 24 }) => [
buildItemsField({
fields: [
buildMediaField({ label: adminText('Photo', 'Zdjęcie') }),
{
type: 'row',
fields: [
{ name: 'heading', type: 'text', admin: { width: '50%' }, label: adminText('Name', 'Imię i nazwisko'), localized: true, required: true },
{ name: 'text', type: 'text', admin: { placeholder: adminText('Co-founder', 'Współzałożycielka'), width: '50%' }, label: adminText('Role', 'Stanowisko'), localized: true },
],
},
{ name: 'bio', type: 'textarea', admin: { rows: 3 }, label: adminText('Short bio', 'Krótki opis'), localized: true },
buildLinkField({ name: 'link', appearances: false }),
] as Field[],
labels: { plural: adminText('People', 'Osoby'), singular: adminText('Person', 'Osoba') },
maxRows: maxItems,
}),
],
interfaceName: 'TeamBlock',
labels: { plural: adminText('Teams', 'Zespoły'), singular: adminText('Team', 'Zespół') },
links: { maxRows: 1 },
variants: TEAM_VARIANTS,
})
@@ -0,0 +1,72 @@
import type { LibraryBlockProps, TestimonialItem } from '../../context.js'
import type { BaseBlockData } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { blockTexts, fillText } from '../../texts.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type TestimonialsBlockData = { entries?: null | unknown[]; items?: null | TestimonialItem[]; source?: null | string } & BaseBlockData
export const TESTIMONIALS_PARTS = {
author: 'font-medium text-fg-strong',
figure: 'm-0 flex h-full flex-col gap-4 p-6',
grid: 'grid gap-gap md:grid-cols-2 lg:grid-cols-3',
photo: 'h-12 w-12 rounded-full object-cover',
quote: 'text-lead text-fg',
rating: 'text-accent',
role: 'text-sm text-fg-muted',
single: 'mx-auto grid max-w-narrow gap-gap',
}
const str = (v: unknown) => (typeof v === 'string' && v.trim() ? v : undefined)
/** Default mapping of a testimonials-collection document. */
export function defaultTestimonial(doc: Record<string, unknown>): null | TestimonialItem {
const quote = str(doc.quote) ?? str(doc.text)
const heading = str(doc.heading) ?? str(doc.author) ?? str(doc.name)
if (!quote || !heading) {return null}
return { id: str(doc.id), heading, media: doc.media ?? doc.photo, quote, rating: typeof doc.rating === 'number' ? doc.rating : null, text: str(doc.role) ?? str(doc.company) ?? null }
}
/** Quotes as <figure>/<blockquote>/<figcaption>; a rating has a text equivalent for screen readers. */
export function TestimonialsBlock(props: LibraryBlockProps<TestimonialsBlockData>) {
const { classNames, ctx, entries, header, isFirst, items, links, locale, settings, source, ui, variant } = props
const map = ctx.mapTestimonial ?? defaultTestimonial
const list =
source === 'collection'
? (entries ?? []).flatMap((e) => (e && typeof e === 'object' ? [map(e as Record<string, unknown>)] : [])).filter((x): x is TestimonialItem => !!x)
: (items ?? []).filter((i) => i.quote && i.heading)
if (!list.length) {return null}
const c = parts(TESTIMONIALS_PARTS, classNames)
const texts = blockTexts(locale, ctx.texts)
const id = headingId(props)
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<ui.SectionHeader align={variant === 'single' ? 'center' : 'start'} as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={variant === 'single' ? c.single : c.grid}>
{list.map((t, i) => (
<li key={t.id ?? i}>
<ui.Card as="figure" className={c.figure}>
{t.rating ? (
<p className={c.rating}>
<span aria-hidden>{'★'.repeat(Math.round(t.rating))}</span>
<span className="sr-only">{fillText(texts.rating, t.rating)}</span>
</p>
) : null}
<blockquote className={cx(c.quote, 'whitespace-pre-line')}>{t.quote}</blockquote>
<figcaption className="mt-auto flex items-center gap-3">
<ui.Media alt="" className={c.photo} resource={t.media as never} sizes={MEDIA_SIZES.thumb} />
<span className="flex flex-col">
<span className={c.author}>{t.heading}</span>
{t.text ? <span className={c.role}>{t.text}</span> : null}
</span>
</figcaption>
</ui.Card>
</li>
))}
</ul>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,70 @@
import type { Field } from 'payload'
import type { BlockOptions } from '../../types.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField, buildMediaField } from '../../fields.js'
export const TESTIMONIALS_VARIANTS = [variantOption('grid', 'Grid', 'Siatka'), variantOption('single', 'One at a time', 'Pojedyncza opinia')] as const
export type TestimonialsOptions = {
/**
* A collection of testimonials to pick from, e.g. 'testimonials' — adds "From the list" as a source.
* Its documents need `quote` and `heading` (author); `text`, `media`, `rating` are optional
* (or map them with `mapTestimonial` in createBlockRegistry). Default none: inline only.
*/
collection?: string
} & BlockOptions
const ITEM_FIELDS: Field[] = [
{ name: 'quote', type: 'textarea', admin: { rows: 4 }, label: adminText('Quote', 'Cytat'), localized: true, required: true },
{
type: 'row',
fields: [
{ name: 'heading', type: 'text', admin: { width: '50%' }, label: adminText('Author', 'Autor'), localized: true, required: true },
{ name: 'text', type: 'text', admin: { width: '50%' }, label: adminText('Role or company', 'Stanowisko lub firma'), localized: true },
],
},
buildMediaField({ label: adminText('Photo', 'Zdjęcie') }),
{ name: 'rating', type: 'number', admin: { step: 1 }, label: adminText('Rating (1–5)', 'Ocena (1–5)'), max: 5, min: 1 },
]
/** Testimonials — quotes typed into the block, or picked from a testimonials collection. */
export const buildTestimonialsBlock = defineLibraryBlock<TestimonialsOptions>({
slug: 'testimonials',
fields: ({ collection, maxItems = 12 }) => {
const items = buildItemsField({
fields: ITEM_FIELDS,
labels: { plural: adminText('Testimonials', 'Opinie'), singular: adminText('Testimonial', 'Opinia') },
maxRows: maxItems,
})
if (!collection) {return [items]}
const fromList = (_: unknown, s: { source?: string } | undefined) => s?.source === 'collection'
return [
{
name: 'source',
type: 'radio',
defaultValue: 'inline',
label: adminText('Source', 'Źródło'),
options: [
{ label: adminText('Typed here', 'Wpisane tutaj'), value: 'inline' },
{ label: adminText('From the list', 'Z listy opinii'), value: 'collection' },
],
},
{ ...items, admin: { ...items.admin, condition: (d: unknown, s: { source?: string } | undefined) => !fromList(d, s) } },
{
name: 'entries',
type: 'relationship',
admin: { condition: fromList },
hasMany: true,
label: adminText('Testimonials', 'Opinie'),
maxRows: maxItems,
relationTo: collection,
},
]
},
interfaceName: 'TestimonialsBlock',
labels: { plural: adminText('Testimonials', 'Opinie'), singular: adminText('Testimonials', 'Opinie') },
links: { maxRows: 1 },
variants: TESTIMONIALS_VARIANTS,
})
@@ -0,0 +1,39 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, MediaValue, RichTextData } from '../../data.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { RenderRichText } from '../../../richtext/RenderRichText.js'
import { Buttons, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type TextMediaBlockData = { content?: RichTextData; media?: MediaValue } & BaseBlockData
export const TEXT_MEDIA_PARTS = {
content: 'max-w-measure space-y-4 text-fg',
grid: 'grid items-center gap-gap md:grid-cols-2',
media: 'h-auto w-full rounded-media object-cover',
mediaLeft: 'md:order-first',
}
/** Text and image side by side; the image goes left or right with `variant`. */
export function TextMediaBlock(props: LibraryBlockProps<TextMediaBlockData>) {
const { classNames, content, ctx, header, isFirst, links, locale, media, settings, ui, variant } = props
const c = parts(TEXT_MEDIA_PARTS, classNames)
const id = headingId(props)
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
<div className={media ? c.grid : undefined}>
<div>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} className="mb-6" header={header} id={id} />
{content ? <RenderRichText className={cx(c.content, ctx.richText?.className)} data={content as never} /> : null}
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</div>
{media ? (
<div className={variant === 'mediaLeft' ? c.mediaLeft : undefined}>
<ui.Media className={c.media} priority={isFirst} resource={media} sizes={MEDIA_SIZES.half} />
</div>
) : null}
</div>
</ui.Section>
)
}
@@ -0,0 +1,16 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildContentField, buildMediaField } from '../../fields.js'
export const TEXT_MEDIA_VARIANTS = [
variantOption('mediaRight', 'Image on the right', 'Obraz po prawej'),
variantOption('mediaLeft', 'Image on the left', 'Obraz po lewej'),
] as const
/** Text and image — formatted text beside an image or a video. */
export const buildTextMediaBlock = defineLibraryBlock({
slug: 'textMedia',
fields: () => [buildContentField(), buildMediaField({ label: adminText('Image or video', 'Obraz lub wideo') })],
interfaceName: 'TextMediaBlock',
labels: { plural: adminText('Text and image', 'Tekst i obraz'), singular: adminText('Text and image', 'Tekst i obraz') },
variants: TEXT_MEDIA_VARIANTS,
})