# 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`):
```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'
const VARIANTS: Record = {
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:
```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-background',
muted: 'bg-muted',
inverted: 'bg-foreground text-background',
}
export function Section({ settings, children }: { settings?: SectionSettings | null; children: ReactNode }) {
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
- **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` (§6.3), not ternary chains.
```css
/* 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;
}
```