Adds the Contact section to the homepage
Adds the contact form with the live fields, validation and browser-side anti-spam, behind a coming-soon notice with a mail button until the API exists. A "Boek" link on a price card selects its package, tidies the URL and moves focus to the form. The form loads only when it comes near the screen, so the hero does not wait for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# Code Summary — Unit 5: Contact
|
||||
|
||||
Plan: [contact-code-generation-plan.md](../../plans/contact-code-generation-plan.md). Functional design: [../functional-design/](../functional-design/). Branch: `feature/homepage-sections`.
|
||||
|
||||
## Files
|
||||
|
||||
### Created
|
||||
| File | Purpose |
|
||||
|---|---|
|
||||
| `web/src/contact/types.ts` | Values, errors, payload, shoot option, limits, empty values |
|
||||
| `web/src/contact/submitContactForm.ts` + test | The single submission adapter; fails until the API exists (comment shows the future `POST /api/contact`) |
|
||||
| `web/src/lib/shootOptions.ts` + test | Shown packages + Overig |
|
||||
| `web/src/lib/validateContact.ts` + test | `validateField` / `validateContact` with the agreed messages |
|
||||
| `web/src/lib/toContactPayload.ts` + test | Trimmed payload |
|
||||
| `web/src/lib/isLikelySpam.ts` + test | Honeypot or under 3000 ms |
|
||||
| `web/src/lib/mailLink.ts` + test | `mailSubject`, `mailtoLink` |
|
||||
| `web/src/lib/contactFormReducer.ts` + test | The form as a pure state machine (editing → sending → sent / failed) |
|
||||
| `web/src/recipes/formControl.ts` | The design's square fields for Input, Textarea and NativeSelect |
|
||||
| `web/src/components/ContactForm/ContactForm.tsx` + test | The form (lazy chunk) |
|
||||
| `web/src/components/ContactForm/ContactFormGate.tsx` + test | Dimmed, inert form under the coming-soon notice |
|
||||
| `web/src/components/home/ContactSection/ContactSection.tsx` + test | The section: heading, gate, lazy form, `?pakket=` handling, focus |
|
||||
|
||||
### Modified
|
||||
| File | Change |
|
||||
|---|---|
|
||||
| `web/src/content/types.ts`, `homeContent.ts`, `siteContent.ts` | `HomeContent.contact`; `SiteContent.contactForm = { enabled: false }` |
|
||||
| `web/src/theme.ts` | `error` colour (#a4443a: 5.7:1 on paper, 6.1:1 on white), `panel` shadow, `formControl` recipe |
|
||||
| `web/src/components/SectionHeading/SectionHeading.tsx` | `focusable` (tabIndex −1 for the programmatic focus) |
|
||||
| `web/src/components/home/Pricing/PriceCard.tsx` | Feature list as plain `ul`/`li` instead of Chakra `List` (see performance) |
|
||||
| `web/src/components/home/Testimonials/TestimonialSlide.tsx` | Plain `figure`/`blockquote`/`figcaption` instead of Chakra `Blockquote` (see performance) |
|
||||
| `web/src/routes/index.tsx` | Renders `ContactSection` with `pakket` from `Route.useSearch()` |
|
||||
| `web/src/test/arbitraries.ts` | `contactValues`, `anyContactValues`, `contactEvent` |
|
||||
| `web/src/test/setup.ts` | No-op `Element.scrollIntoView` (the router's hash scroll; jsdom lacks it) |
|
||||
| `web/src/app.test.tsx` | "Contact" in the page order; full "Boek Newborn" path through the real route |
|
||||
|
||||
## Findings and fixes during generation
|
||||
- **Labels not linked** (found by a test): Chakra's `Field.Root` links the label to the control through its own id; overriding the control's `id` broke that. In Ark, `Field.Root`'s `id` is the control's id (and `ids.control` is, confusingly, the root group's id), so the id now goes on `Field.Root`. Ark links the error text with `aria-errormessage` (not `aria-describedby` as written in the functional design); `aria-invalid` is set.
|
||||
- **Field refs vs the React compiler lint**: refs set from a helper called during render were rejected; focus now finds the first invalid field by its id.
|
||||
- **Form disappearing after a "Boek" arrival**: with the form loaded because of `?pakket=`, removing the parameter made it unload until the observer fired, losing typed input. Once loaded the form now stays (asserted in the app test).
|
||||
- **Coverage**: two reducer branches were only reached randomly by the stateful property test; fixed with deterministic example tests (100% on `src/lib/**`).
|
||||
- **Performance** (5-run Lighthouse medians, unit 4 rebuilt alongside for the same conditions):
|
||||
|
||||
| Build | Median | LCP | TBT |
|
||||
|---|---|---|---|
|
||||
| Unit 4 | 0.83 | 3.84 s | 177 ms |
|
||||
| Unit 5, form in the route chunk | 0.80 | 3.99 s | 232 ms |
|
||||
| Unit 5, form lazy | 0.81 | 3.99 s | 207 ms |
|
||||
| Unit 5, form lazy, no slot recipes in the route chunk | **0.83** | 3.84 s | 175 ms |
|
||||
|
||||
First the form was moved into its own chunk, loaded when the section comes within 200 px of the screen, or at once when arriving via "Boek …". The remaining gap came from a new shared chunk (Chakra's slot-recipe factory, now used by three chunks) that the route had to fetch on page load: the price cards' `List` and the review slide's `Blockquote` were the only slot-recipe components on the route, so they became plain elements with the same styling, and the route no longer needs that chunk.
|
||||
- **Placeholder** while the form loads: measured 604 px on phones, 502 px from `sm`.
|
||||
|
||||
## Verification (`pnpm check`)
|
||||
- Lint ✅, Prettier ✅, build ✅ (`ContactForm` in its own chunk, ±5.7 KB gzipped)
|
||||
- Tests: 52 files, **237 passed**; 100% coverage on `src/lib/**`
|
||||
- Lighthouse home: mobile **0.83**, desktop **1.0**; accessibility, best practices, SEO **1.0**
|
||||
- Visual check: 1440 and 390 with the overlay; 1440 with the form switched on locally (reverted before the build that was checked)
|
||||
|
||||
## Extension compliance
|
||||
- **Security Baseline**: client-side limits and format (SECURITY-05, server side in the API feature); misuse: gate + honeypot + time check (SECURITY-11); generic failure text (SECURITY-15); the e-mail address is assembled in the browser; no new dependencies or external resources; CSP unchanged.
|
||||
- **PBT**: PBT-02 (mailto round-trip), PBT-03 (validation invariants), PBT-04 (payload idempotency), PBT-05 (spam and e-mail oracles), PBT-06 (stateful reducer test over random event sequences), PBT-07 (generators), PBT-08/09 (existing seed setup), PBT-10 (example tests).
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
# Business Logic Model — Unit 5: Contact
|
||||
|
||||
## Submit sequence
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
box rgba(246,224,94,0.4) Visitor
|
||||
participant V as Visitor
|
||||
end
|
||||
box rgba(99,179,237,0.4) Homepage
|
||||
participant F as ContactForm
|
||||
participant L as PureHelpers
|
||||
participant A as SubmitAdapter
|
||||
end
|
||||
V->>F: Clicks the send button
|
||||
F->>L: validateContact with the values and options
|
||||
L-->>F: Errors per field, or none
|
||||
F->>L: isLikelySpam with honeypot and elapsed time
|
||||
L-->>F: Spam or not
|
||||
F->>A: submitContactForm with the trimmed payload
|
||||
A-->>F: Resolved or rejected
|
||||
F-->>V: Thank-you message, or failure message with mail link
|
||||
```
|
||||
|
||||
Text alternative: on submit the form validates, checks for spam, sends the trimmed payload through the single adapter, and shows the thank-you or the failure message.
|
||||
|
||||
## Form state (a pure reducer)
|
||||
|
||||
The form's behaviour is a pure reducer `contactFormReducer(state, event)`, so it can be tested as a state machine (PBT-06) independently of React.
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
Editing["editing"] -->|"submit, invalid"| Editing
|
||||
Editing -->|"submit, spam"| Sent["sent"]
|
||||
Editing -->|"submit, valid"| Sending["sending"]
|
||||
Sending -->|"resolved"| Sent
|
||||
Sending -->|"rejected"| Failed["failed"]
|
||||
Failed -->|"edit or blur"| Failed
|
||||
Failed -->|"submit, valid"| Sending
|
||||
|
||||
classDef state fill:#63b3ed,stroke:#2b6cb0,stroke-width:1px,color:#000;
|
||||
classDef final fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000;
|
||||
class Editing,Sending,Failed state;
|
||||
class Sent final;
|
||||
```
|
||||
|
||||
Text alternative: the form is editing until a submit; an invalid submit stays in editing (with errors), spam goes straight to sent, a valid submit goes to sending, which ends in sent or failed; from failed, a valid submit sends again.
|
||||
|
||||
**State**: `{ status: 'editing' | 'sending' | 'sent' | 'failed'; values; touched: Set of fields; errors }`
|
||||
**Events**: `edit(field, value)`, `blur(field)`, `preselect(shoot)`, `submit({ now, shownAt, honeypot })`, `resolved`, `rejected`.
|
||||
|
||||
## Pure functions (`web/src/lib/`)
|
||||
|
||||
| Function | Purpose | Rules |
|
||||
|---|---|---|
|
||||
| `shootOptions(packages)` | shown packages + Overig | domain-entities.md |
|
||||
| `validateField(field, values, options)` | first failing message for one field, or undefined | BR-FORM-01…07 |
|
||||
| `validateContact(values, options)` | errors for all fields | BR-FORM-01…07 |
|
||||
| `toContactPayload(values)` | trimmed payload | BR-SEND-01 |
|
||||
| `isLikelySpam({ honeypot, shownAt, now })` | honeypot or under 3000 ms | BR-SPAM-01 |
|
||||
| `mailSubject(packageName?)` | "Aanvraag fotoshoot: X" or "Vraag via andreaslop.nl" | BR-MAIL-01 |
|
||||
| `mailtoLink(address, subject)` | `mailto:` with encoded subject | BR-MAIL-01 |
|
||||
| `contactFormReducer(state, event)` | the state machine above | BR-FORM-10…12, BR-SEND-01…04, BR-SPAM-02 |
|
||||
|
||||
## Testable properties (PBT-01)
|
||||
|
||||
| Function | Category | Property |
|
||||
|---|---|---|
|
||||
| `shootOptions` | Invariant | Last option is Overig; the others are the packages' ids and names in order |
|
||||
| `validateContact` | Oracle | For generated valid values there are no errors |
|
||||
| `validateContact` | Invariant | Emptying any one required field gives exactly that field's "required" message |
|
||||
| `validateContact` | Invariant | Exceeding a limit gives that field's "te lang" message |
|
||||
| `validateContact` | Oracle | E-mail error ⇔ the trimmed value fails the format regex (for non-empty, short values) |
|
||||
| `toContactPayload` | Idempotency | Making a payload of a payload changes nothing; no field has outer whitespace |
|
||||
| `isLikelySpam` | Oracle | Equals `honeypot !== '' \|\| now - shownAt < 3000` |
|
||||
| `mailtoLink` | Round-trip | Decoding the `subject` parameter gives back the subject; the link starts with `mailto:<address>?` |
|
||||
| `mailSubject` | Invariant | Contains the package name when given, otherwise the general subject |
|
||||
| `contactFormReducer` | Stateful (PBT-06) | For random event sequences: status only moves along the allowed transitions; `sending` only after a valid, non-spam submit; values never change while `sending`; errors never show for an untouched field unless a submit happened; after `sent` nothing changes |
|
||||
|
||||
Generators (PBT-07): valid `contactValues` (realistic names, e-mails from the existing `validEmail`, a shoot from the options, messages up to the limit), `anyContactValues` (empty, whitespace, overlong, bad e-mails), and event sequences for the reducer (`fc.commands` or a list of events).
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
# Business Rules — Unit 5: Contact
|
||||
|
||||
Sources: FR-HP-06…09, unit 3's BR-PARAM-02…04, [contact-fd-questions.md](../../plans/contact-fd-questions.md) and [contact-fd-clarification-questions.md](../../plans/contact-fd-clarification-questions.md).
|
||||
|
||||
## Validation
|
||||
|
||||
| ID | Rule | Message |
|
||||
|---|---|---|
|
||||
| BR-FORM-01 | `naam` is required (after trimming) | "Vul je naam in." |
|
||||
| BR-FORM-02 | `email` is required | "Vul je e-mailadres in." |
|
||||
| BR-FORM-03 | `email` must look like an address: `^[^\s@]+@[^\s@]+\.[^\s@]{2,}$` after trimming | "Dit e-mailadres is ongeldig." |
|
||||
| BR-FORM-04 | `shoot` must be one of the shoot options | "Kies een soort shoot." |
|
||||
| BR-FORM-05 | `bericht` is required | "Schrijf hier je vraag." |
|
||||
| BR-FORM-06 | Maximum lengths: `naam` 100, `email` 254, `bericht` 2000 (also `maxLength` on the fields) | "De naam is te lang." / "Het e-mailadres is te lang." / "Het bericht is te lang." |
|
||||
| BR-FORM-07 | Per field the first failing rule wins, in the order required → length → format | — |
|
||||
|
||||
## When errors show (Q1 = B)
|
||||
|
||||
| ID | Rule |
|
||||
|---|---|
|
||||
| BR-FORM-10 | A field is checked when the visitor **leaves** it, but only once they have typed in it; tabbing through an untouched empty field shows nothing. |
|
||||
| BR-FORM-11 | On **submit** every field is checked; if any is invalid, nothing is sent and focus moves to the first invalid field. |
|
||||
| BR-FORM-12 | A shown error is re-checked while typing and **disappears** as soon as the field is valid (it is not re-shown while typing; a new error only appears on leaving or submitting). |
|
||||
| BR-FORM-13 | Errors are linked to their field (`aria-describedby`, `aria-invalid`) and announced. |
|
||||
|
||||
## Sending
|
||||
|
||||
| ID | Rule |
|
||||
|---|---|
|
||||
| BR-SEND-01 | Valid and not spam → state **sending**: button disabled, label "Versturen…"; the payload (trimmed values) goes to `submitContactForm`. |
|
||||
| BR-SEND-02 | Success → state **sent**: the form is replaced by "Bedankt voor je bericht! Ik reageer binnen 1-2 werkdagen." and focus moves to that message (Q3 = A). |
|
||||
| BR-SEND-03 | Failure → state **failed**: above the button "Versturen lukte niet. Probeer het later nog eens of mail naar info@andreaslop.nl" with the address as a mail link (BR-MAIL-01); what the visitor typed stays; the next submit tries again (Q6 = A). |
|
||||
| BR-SEND-04 | A second submit while sending is ignored. |
|
||||
|
||||
## Anti-spam (FR-HP-08)
|
||||
|
||||
| ID | Rule |
|
||||
|---|---|
|
||||
| BR-SPAM-01 | Spam when the honeypot `website` is not empty, or less than 3000 ms passed since the form became usable. |
|
||||
| BR-SPAM-02 | Spam gets the normal success (state **sent**), but nothing is sent. Validation still runs first, like for a person. |
|
||||
| BR-SPAM-03 | No robot-check script is loaded in this feature; the form keeps a slot for Friendly Captcha (FR-HP-09). |
|
||||
|
||||
## Gate (FR-HP-07)
|
||||
|
||||
| ID | Rule |
|
||||
|---|---|
|
||||
| BR-GATE-01 | `contactForm.enabled = false` → the form is visible but dimmed and `inert`; over it the notice "Binnenkort", "Het contactformulier komt binnenkort. Mail me voor nu op info@andreaslop.nl" and the button "Stuur een e-mail". |
|
||||
| BR-GATE-02 | The address is assembled from `siteContent.email` in the browser (existing `emailAddress`); if it is invalid the notice shows only "Het contactformulier komt binnenkort." without address or button. |
|
||||
| BR-GATE-03 | `enabled = true` → the form works normally and the notice is not rendered. |
|
||||
|
||||
## Mail link (Q4 = A)
|
||||
|
||||
| ID | Rule |
|
||||
|---|---|
|
||||
| BR-MAIL-01 | Every mail link (notice button, address in the notice, address in the failure message) opens a mail with a subject: "Aanvraag fotoshoot: <package name>" when the visitor arrived via a "Boek …" link (a package is selected from `?pakket=`), otherwise "Vraag via andreaslop.nl". Subject is URL-encoded. |
|
||||
|
||||
## Preselection from "Boek …" (unit 3, BR-PARAM-02…04)
|
||||
|
||||
| ID | Rule |
|
||||
|---|---|
|
||||
| BR-PARAM-02 | When the page has a `pakket` value: if it names a shown package (`packageFromSearch`), the shoot field takes that package — replacing an earlier choice (last click wins, BR-PARAM-03). Then `pakket` is removed from the URL with a history *replace*, keeping `#contact`, without scrolling. Unknown values are removed the same way and change nothing. |
|
||||
| BR-PARAM-04 | This happens the same way with the gate on or off (with the gate on, the package still feeds the mail subject). |
|
||||
| BR-FOCUS-01 | After arriving via a "Boek …" link (any `pakket` value present), focus moves to the "Contact" heading (programmatic focus, no visible ring), so keyboard and screen reader users continue in the right place (Q5 = A). A normal page load does not move focus. |
|
||||
|
||||
## Decision flow: submit
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Submit["Visitor submits"] --> Busy{"Already sending?"}
|
||||
Busy -->|"yes"| Ignore["Ignore"]
|
||||
Busy -->|"no"| Valid{"All fields valid?"}
|
||||
Valid -->|"no"| ShowErrors["Show errors, focus first invalid field"]
|
||||
Valid -->|"yes"| Spam{"Honeypot filled or under 3 s?"}
|
||||
Spam -->|"yes"| FakeSent["Show thank-you, send nothing"]
|
||||
Spam -->|"no"| Sending["Sending: button disabled"]
|
||||
Sending --> Result{"Adapter result"}
|
||||
Result -->|"ok"| Sent["Replace form by thank-you, focus it"]
|
||||
Result -->|"error"| Failed["Failure message with mail link, keep input"]
|
||||
|
||||
classDef input fill:#f6e05e,stroke:#c05621,stroke-width:1px,color:#000;
|
||||
classDef decision fill:#63b3ed,stroke:#2b6cb0,stroke-width:1px,color:#000;
|
||||
classDef outcome fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000;
|
||||
class Submit input;
|
||||
class Busy,Valid,Spam,Result decision;
|
||||
class Ignore,ShowErrors,FakeSent,Sending,Sent,Failed outcome;
|
||||
```
|
||||
|
||||
Text alternative: a submit is ignored while sending; otherwise invalid input shows errors and focuses the first invalid field; valid spam gets the thank-you without sending; valid input is sent, and the result either replaces the form by the thank-you or shows the failure message with a mail link while keeping the input.
|
||||
|
||||
## Decision flow: arriving with `?pakket=`
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Arrive["Homepage with pakket in the URL"] --> Known{"Names a shown package?"}
|
||||
Known -->|"yes"| Select["Shoot field takes the package, replacing an earlier choice"]
|
||||
Known -->|"no"| Keep["Shoot field unchanged"]
|
||||
Select --> Clean["Remove pakket with history replace, keep hash contact"]
|
||||
Keep --> Clean
|
||||
Clean --> Focus["Focus the Contact heading"]
|
||||
|
||||
classDef input fill:#f6e05e,stroke:#c05621,stroke-width:1px,color:#000;
|
||||
classDef decision fill:#63b3ed,stroke:#2b6cb0,stroke-width:1px,color:#000;
|
||||
classDef outcome fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000;
|
||||
class Arrive input;
|
||||
class Known decision;
|
||||
class Select,Keep,Clean,Focus outcome;
|
||||
```
|
||||
|
||||
Text alternative: a known package is selected (replacing an earlier choice), an unknown one changes nothing; either way the parameter is removed from the URL with a history replace and focus moves to the Contact heading.
|
||||
|
||||
## Misuse considerations (SECURITY-11)
|
||||
- Form spam: gate today; honeypot and time check in the browser; Friendly Captcha, server-side validation and rate limiting in the API feature (the browser checks are never the only defence).
|
||||
- Input is only ever rendered as text by React and sent as JSON later; `pakket` is never reflected.
|
||||
- Failure messages are generic (no technical details, SECURITY-15).
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
# Domain Entities — Unit 5: Contact
|
||||
|
||||
## Relationships
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Values["ContactValues"]
|
||||
Errors["ContactErrors"]
|
||||
Payload["ContactPayload"]
|
||||
Option["ShootOption"]
|
||||
Package["PricingPackage"]
|
||||
Config["Contact form setting"]
|
||||
Address["EmailAddress"]
|
||||
|
||||
Package -->|"becomes, plus Overig"| Option
|
||||
Option -->|"allowed values of shoot"| Values
|
||||
Values -->|"checked into"| Errors
|
||||
Values -->|"trimmed into"| Payload
|
||||
Config -->|"switches form or notice"| Values
|
||||
Address -->|"mail link in notice and failure message"| Config
|
||||
|
||||
classDef entity fill:#2196F3,stroke:#0d47a1,stroke-width:1px,color:#000;
|
||||
classDef value fill:#FF9800,stroke:#e65100,stroke-width:1px,color:#000;
|
||||
classDef config fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000;
|
||||
class Values,Payload entity;
|
||||
class Errors,Option,Package,Address value;
|
||||
class Config config;
|
||||
```
|
||||
|
||||
Text alternative: packages (plus Overig) become the shoot options that limit the shoot value; what the visitor typed is checked into errors and trimmed into the payload; the contact form setting switches between the form and the coming-soon notice, which, like the failure message, uses the site's e-mail address.
|
||||
|
||||
## ContactValues (what the visitor typed)
|
||||
|
||||
| Field | Type | Limit | Required |
|
||||
|---|---|---|---|
|
||||
| `naam` | string | 100 characters | yes |
|
||||
| `email` | string | 254 characters | yes, valid format |
|
||||
| `shoot` | string | one of the shoot option values | yes |
|
||||
| `bericht` | string | 2000 characters | yes |
|
||||
|
||||
The limits are also set as `maxLength` on the fields, so in practice they are rarely exceeded; the check is a safety net (and the server repeats it).
|
||||
|
||||
## ContactErrors
|
||||
`Partial<Record<'naam' | 'email' | 'shoot' | 'bericht', string>>` — one message per field at most.
|
||||
|
||||
## ContactPayload (sent to the API later)
|
||||
Same four fields, trimmed. `shoot` is a package id (e.g. `newborn`) or `overig`. The Friendly Captcha token is added in the API feature.
|
||||
|
||||
## ShootOption
|
||||
`{ value: string; label: string }` — the shown packages in their order (`value` = package id, `label` = name), then `{ value: 'overig', label: 'Overig' }`. The empty "Kies een optie..." is the placeholder, not an option.
|
||||
|
||||
## Contact form setting
|
||||
`siteContent.contactForm.enabled: boolean` — `false` today (coming-soon notice); later delivered by the CMS.
|
||||
|
||||
## Anti-spam inputs
|
||||
- Honeypot field `website` (hidden from people and assistive technology).
|
||||
- `shownAt`: when the form became usable (shown and enabled); minimum fill time **3000 ms**.
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
# Frontend Components — Unit 5: Contact
|
||||
|
||||
## Hierarchy
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Route["routes/index.tsx"] --> Section["home/ContactSection"]
|
||||
Section --> Home["HomeSection id contact, narrow"]
|
||||
Section --> Heading["SectionHeading, focus target"]
|
||||
Section --> Gate["ContactForm/ContactFormGate"]
|
||||
Gate --> Form["ContactForm/ContactForm"]
|
||||
Gate --> Notice["Coming-soon notice with mail button"]
|
||||
Form --> Fields["Chakra Field: Input, NativeSelect, Textarea"]
|
||||
Form --> Honeypot["Honeypot field"]
|
||||
Form --> Slot["Robot-check slot, empty"]
|
||||
Form --> Status["Sending, failure and thank-you"]
|
||||
Logic["lib: reducer, validation, spam, mail link"] -.-> Form
|
||||
Logic -.-> Gate
|
||||
Adapter["contact/submitContactForm"] -.-> Form
|
||||
|
||||
classDef root fill:#4CAF50,stroke:#2e7d32,stroke-width:1px,color:#000;
|
||||
classDef ui fill:#2196F3,stroke:#0d47a1,stroke-width:1px,color:#000;
|
||||
classDef logic fill:#9C27B0,stroke:#4a148c,stroke-width:1px,color:#000;
|
||||
classDef ext fill:#F44336,stroke:#b71c1c,stroke-width:1px,color:#000;
|
||||
class Route root;
|
||||
class Section,Home,Heading,Gate,Form,Notice,Fields,Honeypot,Slot,Status ui;
|
||||
class Logic logic;
|
||||
class Adapter ext;
|
||||
```
|
||||
|
||||
Text alternative: the home route renders ContactSection (HomeSection with id contact, the heading as focus target, and the gate); the gate wraps the form and the coming-soon notice; the form has Chakra fields, a honeypot, an empty robot-check slot and status messages; pure helpers and the submit adapter support it.
|
||||
|
||||
## ContactSection (`components/home/ContactSection`)
|
||||
- **Props**: `{ content: HomeContent['contact']; packages: PricingPackage[]; enabled: boolean; email: EmailAddress; pakket?: string }`
|
||||
- **Behaviour**: resolves `pakket` with `packageFromSearch`; passes the selected id to the form (`preselect`) and the package name to the mail subject; removes `pakket` from the URL (router `navigate({ search: {}, hash: 'contact', replace: true, resetScroll: false })`); moves focus to the heading when `pakket` was present (BR-PARAM-02, BR-FOCUS-01).
|
||||
- **Layout**: `HomeSection` `id="contact"`, `width="narrow"`, plain background, centred `SectionHeading` "Contact" with lead; the heading has `tabIndex={-1}` for the programmatic focus (no visible ring, theme rule `[tabindex="-1"]:focus`).
|
||||
|
||||
## ContactFormGate (`components/ContactForm/ContactFormGate`)
|
||||
- **Props**: `{ enabled: boolean; email: EmailAddress; subject: string; children }`
|
||||
- **Off**: wraps children in a dimmed (`opacity 0.35`, slight blur), `inert`, non-selectable box; renders the notice centred over it: eyebrow "Binnenkort", the text with the address as an underline link, and an accent `LinkButton`-style anchor "Stuur een e-mail" (`mailtoLink`). White panel, hairline border, `shadow` from the design (a theme token). Invalid address → text only.
|
||||
- **On**: renders children only.
|
||||
|
||||
## ContactForm (`components/ContactForm/ContactForm`)
|
||||
- **Props**: `{ idPrefix: string; options: ShootOption[]; preselect?: { shoot: string; key: number }; mailSubject: string; email: EmailAddress; submit?: (payload) => Promise<void> }` (`key` changes per "Boek" click so the same package can be applied again)
|
||||
- **State**: `useReducer(contactFormReducer)`; `shownAt` recorded when the form becomes usable.
|
||||
- **Fields**: Chakra `Field.Root` + `Field.Label` + control + `Field.ErrorText` (`invalid` from state); square inputs in the design style (theme), `autocomplete` name/email, `maxLength` per limit; the select has the placeholder "Kies een optie..." and the shoot options; the textarea min height 170 px with placeholder "Vul hier je bericht in".
|
||||
- **Honeypot**: label "Website" + input `name="website"`, off-screen, `aria-hidden`, `tabIndex={-1}`, `autoComplete="off"`.
|
||||
- **Robot-check slot**: an empty `div` with `data-robot-check` (FR-HP-09).
|
||||
- **Submit button**: accent `linkButton` style on a `button`, "(Aan)vraag versturen" / "Versturen…" while sending, disabled while sending.
|
||||
- **Failure**: a status box above the button (`role="alert"`) with the mail link.
|
||||
- **Sent**: the form is replaced by the thank-you (`role="status"`, `tabIndex={-1}`, focused).
|
||||
- **Layout**: name and e-mail side by side from `sm`, the rest full width; labels in the eyebrow style (`ink.soft` for contrast).
|
||||
- **Test ids**: `contact-form`, `contact-form-<field>`, `contact-form-submit`, `contact-form-status`, `contact-form-sent`, `contact-gate-notice`, `contact-gate-mail`.
|
||||
|
||||
## Loading
|
||||
The form is a lazy chunk, loaded when the section comes within 200 px of the screen or at once when arriving via "Boek …", and it stays once loaded; the heading and the gate's notice render immediately over a placeholder of the form's height (unit 5 code summary, performance).
|
||||
|
||||
## Content
|
||||
- `HomeContent.contact = { title: 'Contact', lead: 'Wil je meer informatie ontvangen? Neem gerust contact met mij op.' }`
|
||||
- `siteContent.contactForm = { enabled: false }`
|
||||
|
||||
## Accessibility (NFR-HP-01)
|
||||
- Labels visible and linked; errors via `aria-errormessage`/`aria-invalid` (Ark's Field) and announced; focus to the first invalid field on submit; thank-you focused; failure announced (`role="alert"`).
|
||||
- With the gate on, the inert form is skipped by keyboard and screen readers; the notice and its button are reachable.
|
||||
- Contrast: labels and placeholder text meet 4.5:1 (no `ink.muted` on paper); the dimmed form is decorative while inert.
|
||||
- Axe clean in both gate states; Lighthouse accessibility stays 1.0.
|
||||
Reference in New Issue
Block a user