Files
ipal-kit/docs/agent/skills/ipal-block/resources/section-code.md
T
Radosław SmolińskiandClaude Opus 5.5 2d9f3e15d4 Docs in English (part 1), seeding guide, Coolify deployment
- Translate to English every doc the code branches did not touch: AGENT.md,
  developer guide, vibe, CHANGELOG, docs index, module pages, all skills
  except ipal-seo-check (14 pages follow after the security/SEO merge).
  Placeholder marker is now [TO FILL: …]; skill resources renamed to
  section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer
  block say the docs are in English.
- docs/seeding.md: create-only, natural keys, never delete, no users or
  secrets, empty-field globals, fallbackLocale: false, dry run, backup and
  restore, production update guard, seeds vs migrations, Coolify Terminal.
  Seed templates gain --dry-run, the SEED_UPDATE production guard
  (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary.
  "Seeding on production" rule block in AGENT.md.
- Coolify is the single deployment path (deployment, env, developer guide,
  ipal-setup): build vs runtime env, migrations on container start
  (prodMigrations), health check and rolling updates, rollback, backups and
  restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone;
  default is media served by the app (R2_PUBLIC_URL empty).
- docsConsistency: no Polish prose outside code/quoted data (pending pages
  listed); IPAL_* names may also be read by shipped skill templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:39:03 +02:00

13 KiB
Raw Blame History

Section code — ready files for the project

Resources of the ipal-block skill. The rules (why, and what not to do) are in node_modules/@intecion/ipal-kit/docs/agent/AGENT.md §6 — this file is only the code to create in the project 1:1. Links (buildLinkField, buildLinksField, resolveLink), section fields (buildSectionHeaderField, buildSectionSettingsField) and the menu (resolveNav) come from the plugin — do not copy them.

Layer 1 — shared fields

Link / CTA — from the plugin, do not copy the code (docs/links.md):

import { buildLinkField, buildLinksField } from '@intecion/ipal-kit'

buildLinksField()                                            // 0–2 section buttons → `links` field
buildLinksField({ maxRows: 3, appearances: ['primary', 'secondary'] })
buildLinkField()                                             // single link → `link` field
buildLinkField({ disableLabel: true, appearances: false })   // whole card clickable

One link shape: type (internal page / external URL, mailto, tel, #anchor / file upload), label (localized), newTab, appearance. payload-types.ts gets a CmsLink type (without style: CmsLinkPlain, without label: CmsLinkNoLabel; all fit CmsLink; custom name: interfaceName). Options: relationTo (default 'pages'), uploadTo (default 'media'), required.

Files and images: { name: 'media', type: 'upload', relationTo: 'media' }. The media collection accepts PDF (upload.mimeTypes: ['image/*', 'application/pdf', 'video/mp4']), has alt (required, localized) and normalizeFilenameHook. "Download price list (PDF)" is a link of type file, not a separate pdf/pdfUrl field.

Section header and settings — from the plugin, do not copy the code (docs/blocks.md):

import { buildSectionHeaderField, buildSectionSettingsField } from '@intecion/ipal-kit'

buildSectionHeaderField()      // `header` group: eyebrow, heading, intro (localized) — type SectionHeaderData
buildSectionSettingsField()    // sidebar `settings`: anchor, background (default/muted/inverted) — type SectionSettings
buildSectionSettingsField({ backgrounds: [{ label: 'Default', value: 'default' }, { label: 'Brand', value: 'brand' }] })

Every section has buildSectionSettingsField() — no bgColor, darkMode, sectionId in individual blocks. Field labels in English (the panel is EN).

Layer 2 — UI primitives

src/components/ui/CMSLink.tsx — every link/button from the panel:

import Link from 'next/link'
import type { ReactNode } from 'react'
import type { CmsLink } from '@/payload-types'
import { resolveLink } from '@/lib/content'
import { buttonClass } from './Button'
import type { LinkAppearance } from '@intecion/ipal-kit'

type Props = {
  link: CmsLink | null | undefined
  locale: string
  className?: string
  /** For wrapping links (cards): content instead of link.label. */
  children?: ReactNode
}

// href, new tab, rel, internal/external — from the plugin. Here: the element and the classes.
export async function CMSLink({ link, locale, className, children }: Props) {
  const l = await resolveLink(link, locale)
  const content = children ?? l?.label
  if (!l || !content) return null
  const cls = [l.appearance ? buttonClass(l.appearance as LinkAppearance) : '', className].filter(Boolean).join(' ') || undefined
  return l.internal
    ? <Link href={l.href} className={cls} {...l.targetProps}>{content}</Link>
    : <a href={l.href} className={cls} {...l.targetProps}>{content}</a>
}

src/components/ui/Button.tsx — variants as a map, not a ternary:

import type { LinkAppearance } from '@intecion/ipal-kit'

const VARIANTS: Record<LinkAppearance, string> = {
  primary: 'btn btn-primary',
  secondary: 'btn btn-secondary',
  link: 'link-arrow',
}

export function buttonClass(appearance: LinkAppearance): string {
  return VARIANTS[appearance]
}

src/components/ui/Media.tsx — every image/video from the panel. The plugin handles speed (mediaImageProps, videoProps), the look stays here:

import Image from 'next/image'
import { mediaImageProps, MEDIA_SIZES, videoProps, type VideoMode } from '@intecion/ipal-kit'
import type { Media as MediaDoc } from '@/payload-types'

type Props = {
  resource: MediaDoc | string | number | null | undefined
  /** Width ON SCREEN — MEDIA_SIZES.half / .third / a custom string. Without it the full width downloads. */
  sizes?: string
  /** Only the first visible image of the page (hero, LCP). The rest load lazily. */
  priority?: boolean
  className?: string
  /** Video: 'background' (muted loop) or 'player' (controls, loads on click). */
  videoMode?: VideoMode
  /** Video poster — upload from the panel. */
  poster?: MediaDoc | string | number | null
}

export function Media({ resource, sizes = MEDIA_SIZES.full, priority = false, className, videoMode = 'player', poster }: Props) {
  const video = videoProps(resource, { mode: videoMode, poster })
  if (video) return <video {...video} className={className} />
  const img = mediaImageProps(resource, { priority, sizes })
  if (!img) return null // PDF / file — a link of type 'file' (CMSLink), not <Media>
  return <Image {...img} className={className} />
}

Media in the collection: upload: { focalPoint: true, … } (focal point → object-position) and hooks from the plugin: hooks.beforeOperation: [normalizeFilenameHook, buildOptimizeUploadHook(), buildMediaPlaceholderHook()], fields buildOptimizeUploadField() (consent to optimize an oversized file) and buildMediaPlaceholderField() (blurred preview + color while loading).

Section.tsx and SectionHeader.tsx:

// src/components/ui/Section.tsx
import type { ReactNode } from 'react'
import type { SectionSettings } from '@/payload-types'

const BACKGROUNDS: Record<NonNullable<SectionSettings['background']>, string> = {
  default: 'bg-background',
  muted: 'bg-muted',
  inverted: 'bg-foreground text-background',
}

export function Section({ settings, children }: { settings?: SectionSettings | null; children: ReactNode }) {
  return (
    <section
      id={settings?.anchor || undefined}
      className={`py-16 md:py-24 ${BACKGROUNDS[settings?.background ?? 'default']}`}
    >
      <div className="container">{children}</div>
    </section>
  )
}
// src/components/ui/SectionHeader.tsx
import type { SectionHeaderData } from '@/payload-types'

export function SectionHeader({ header, as: H = 'h2' }: { header?: SectionHeaderData | null; as?: 'h1' | 'h2' }) {
  if (!header?.heading && !header?.eyebrow && !header?.intro) return null
  return (
    <header className="mb-10 max-w-2xl">
      {header.eyebrow && <p className="eyebrow">{header.eyebrow}</p>}
      {header.heading && <H className="heading">{header.heading}</H>}
      {header.intro && <p className="lead">{header.intro}</p>}
    </header>
  )
}

locale for every block — once, in the page route:

const enhanceProps = () => ({ locale })   // Turnstile: <TurnstileProvider> in the layout, not props
<RenderBlocks blocks={doc.layout as never} components={blockRegistry} enhanceProps={enhanceProps} />

Layer 3 — section = composition

// src/blocks/Hero/config.ts
import type { Block } from 'payload'
import { buildLinksField } from '@intecion/ipal-kit'
import { buildSectionHeaderField, buildSectionSettingsField } from '@intecion/ipal-kit'

export const HeroBlock: Block = {
  slug: 'hero',
  interfaceName: 'HeroBlock',
  labels: { singular: 'Hero', plural: 'Heroes' },
  fields: [
    buildSectionHeaderField(),
    { name: 'media', type: 'upload', relationTo: 'media' },
    buildLinksField(),
    buildSectionSettingsField(),
  ],
}
// src/blocks/Hero/Component.tsx — the whole component
import type { HeroBlock } from '@/payload-types'
import { Section } from '@/components/ui/Section'
import { SectionHeader } from '@/components/ui/SectionHeader'
import { Media } from '@/components/ui/Media'
import { CMSLink } from '@/components/ui/CMSLink'

export function Hero({ header, media, links, settings, locale }: HeroBlock & { locale: string }) {
  return (
    <Section settings={settings}>
      <div className="grid items-center gap-10 md:grid-cols-2">
        <div>
          <SectionHeader header={header} as="h1" />
          {links?.length ? (
            <div className="flex flex-wrap gap-3">
              {links.map(({ id, link }) => <CMSLink key={id} link={link} locale={locale} />)}
            </div>
          ) : null}
        </div>
        <Media resource={media} priority sizes="(min-width: 768px) 50vw, 100vw" />
      </div>
    </Section>
  )
}

A section with repeatable items — an array item is a subcomponent:

// src/blocks/FeatureGrid/config.ts (fields) — import { buildLinkField, buildLinksField, rowLabel } from '@intecion/ipal-kit'
buildSectionHeaderField(),
{
  name: 'items',
  type: 'array',
  interfaceName: 'FeatureItem',
  labels: { singular: 'Feature', plural: 'Features' },   // panel: "+ Add Feature"
  minRows: 1,
  maxRows: 6,                                             // as many as the design fits
  admin: { initCollapsed: true, components: rowLabel('heading', 'Feature') },   // row = heading
  fields: [
    { name: 'media', type: 'upload', relationTo: 'media' },
    { name: 'heading', type: 'text', localized: true, required: true },
    { name: 'text', type: 'textarea', localized: true },
    buildLinkField({ appearances: ['link'] }),
  ],
},
buildLinksField({ maxRows: 1 }),
buildSectionSettingsField(),
// src/blocks/FeatureGrid/FeatureCard.tsx
export function FeatureCard({ item, locale }: { item: FeatureItem; locale: string }) {
  return (
    <article className="card">
      <Media resource={item.media} sizes="(min-width: 1024px) 33vw, 100vw" />
      <h3>{item.heading}</h3>
      {item.text && <p>{item.text}</p>}
      <CMSLink link={item.link} locale={locale} />
    </article>
  )
}

// src/blocks/FeatureGrid/Component.tsx
export function FeatureGrid({ header, items, links, settings, locale }: FeatureGridBlock & { locale: string }) {
  return (
    <Section settings={settings}>
      <SectionHeader header={header} />
      <div className="grid gap-6 md:grid-cols-3">
        {items?.map((item) => <FeatureCard key={item.id} item={item} locale={locale} />)}
      </div>
      {links?.map(({ id, link }) => <CMSLink key={id} link={link} locale={locale} className="mt-10" />)}
    </Section>
  )
}

Extract a subcomponent when any of these is true: the same JSX 2+ times; an items[] element has >5 lines of markup; Component.tsx >80 lines of JSX; there is state/ interaction (accordion, slider, tabs → a separate 'use client'). A subcomponent of one section → in its folder; used in 2+ sections → src/components/ui/. Icons: upload or a select with a map in src/components/icons — never SVG pasted into a section.

Icons

Two sources, nothing in between:

  • Any graphic from the client → upload to media + <Media> (also the logo, brand SVG icons).
  • A fixed set of UI icons → a select field + a lucide-react map:
// src/components/icons/names.ts — names only, imported by the block config
export const ICON_NAMES = ['phone', 'mail', 'mapPin', 'clock', 'check'] as const
export type IconName = (typeof ICON_NAMES)[number]
export const iconField = {
  name: 'icon',
  type: 'select',
  options: ICON_NAMES.map((value) => ({ label: value, value })),
} as const
// src/components/icons/Icon.tsx — the map, imported only by components
import { Check, Clock, Mail, MapPin, Phone, type LucideIcon } from 'lucide-react'
import type { IconName } from './names'

const ICONS: Record<IconName, LucideIcon> = { phone: Phone, mail: Mail, mapPin: MapPin, clock: Clock, check: Check }

export function Icon({ name, className }: { name?: IconName | null; className?: string }) {
  if (!name) return null
  const Component = ICONS[name]
  return <Component className={className} aria-hidden />
}

The names are separate so the block config (payload.config) does not import React components. Never SVG pasted into a section's JSX.

Style

  • Tailwind in components, colors and fonts as tokens in styles.css (@theme) — the source is DESIGN.md (Impeccable). Components use only token names (bg-primary, text-foreground), never bg-[#ff6600] or hex.
  • Map the plugin tokens to the project tokens — one brand color in one place.
  • Fonts via next/font in the layout, wired to @theme with a CSS variable.
  • No CSS Modules and no style={{…}} — exception: a dynamic value from data.
  • Visual variants → Record<Variant, string> (§6.3), not ternary chains.
/* src/app/(frontend)/styles.css */
@import "tailwindcss";
@source "../../../node_modules/@intecion/ipal-kit/dist/**/*.js";

@theme {
  --color-primary: oklch(0.62 0.19 45);
  --color-background: oklch(0.99 0 0);
  --color-foreground: oklch(0.2 0 0);
  --color-muted: oklch(0.96 0 0);
  --font-sans: var(--font-body);      /* next/font: variable '--font-body' */
}

:root {
  --ipal-primary: var(--color-primary);   /* cookie banner, Turnstile = brand color */
  --ipal-radius: 0.75rem;
}