# Section code — ready files for the project
> Resources of the **iapl-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`):
```ts
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`):
```ts
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:
```tsx
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
? {content}
: {content}
}
```
`src/components/ui/Button.tsx` — variants as a map, not a ternary:
```ts
import type { LinkAppearance } from '@intecion/ipal-kit'
// design-token utilities only (design-tokens.md) — a brand changes src/design/tokens.ts, never this file
const BASE = 'inline-flex items-center gap-2 rounded-control px-5 py-2.5 font-medium transition-colors duration-fast ease-out'
const VARIANTS: Record = {
primary: `${BASE} bg-primary text-on-primary hover:bg-primary-hover`,
secondary: `${BASE} bg-secondary text-on-secondary hover:bg-secondary-hover`,
link: 'text-link underline-offset-4 hover:text-link-hover hover:underline',
}
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:
```tsx
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
const img = mediaImageProps(resource, { priority, sizes })
if (!img) return null // PDF / file — a link of type 'file' (CMSLink), not
return
}
```
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`:
```tsx
// src/components/ui/Section.tsx
import type { ReactNode } from 'react'
import type { SectionSettings } from '@/payload-types'
const BACKGROUNDS: Record, string> = {
default: 'bg-bg text-fg',
muted: 'bg-surface-muted text-fg',
inverted: 'bg-inverse',
}
export function Section({ settings, children }: { settings?: SectionSettings | null; children: ReactNode }) {
const background = settings?.background ?? 'default'
return (
{children}
)
}
```
```tsx
// 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.eyebrow &&
{links?.map(({ id, link }) => )}
)
}
```
**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` + `` (also the logo, brand SVG icons).
- **A fixed set of UI icons** → a `select` field + a `lucide-react` map:
```ts
// 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
```
```tsx
// 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 = { 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
}
```
The names are separate so the block config (`payload.config`) does not import React
components. **Never** SVG pasted into a section's JSX.
## Style
The design-token standard (`node_modules/@intecion/ipal-kit/docs/design-tokens.md`, AGENT.md §6.11):
- **Components use only the preset's utilities** — `bg-bg`, `bg-surface`, `bg-surface-muted`, `bg-inverse`, `text-fg`,
`text-fg-strong`, `text-fg-muted`, `text-on-primary`, `border-border`, `text-link`, `outline-focus`, `text-h1`…,
`py-section`, `px-gutter`, `gap-gap`, `rounded-control`, `rounded-card`, `shadow-sm`, `max-w-container`.
**Never** hex, `bg-[#ff6600]`, `var(--color-…)`, or `dark:` for colours (the roles switch with the theme).
- The brand is `src/design/tokens.ts` → `pnpm exec iapl-tokens` → `src/design/tokens.css`; `DESIGN.md` describes it.
- Fonts via `next/font` with `variable: '--font-family-body'` / `'--font-family-heading'` on ``.
- No CSS Modules and no `style={{…}}` — exception: a dynamic value from data.
- Visual variants → `Record` (§6.3), not ternary chains.
```css
/* src/app/(frontend)/styles.css — the same on every site */
@import "tailwindcss";
@import "@intecion/ipal-kit/fluid-wide.css";
@import "@intecion/ipal-kit/tokens.css";
@import "@intecion/ipal-kit/tailwind.css";
@import "../../design/tokens.css"; /* generated by iapl-tokens from src/design/tokens.ts */
@source "../../../node_modules/@intecion/ipal-kit/dist/**/*.js";
```