Pakketblok: elk aantal pakketten, filterchips, swipe-rij op mobiel en optionele banner

Pure logica (splitsen, chips, filter, labels), useSwipeRow en usePackageFilter,
ContactPreselect voor het formulier, kaarten in stijl B en tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 10:34:09 +01:00
co-authored by Claude Sonnet 5.5
parent e1d950cd33
commit 9661b64635
28 changed files with 1353 additions and 137 deletions
@@ -1,96 +1,339 @@
import { render, screen, waitFor } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { PackagesSection } from '../components/PackagesSection';
import { packages } from '../data/content';
import { packages, packagesSettings, type PackageCardData } from '../data/content';
import { ContactPreselectProvider } from '../../../shared/contact/ContactPreselectProvider';
import { useContactPreselect } from '../../../shared/contact/useContactPreselect';
import { clearMatchMedia, mockMatchMedia } from '../../../test/matchMedia';
import { REDUCED_MOTION_QUERY } from '../../../shared/hooks/usePrefersReducedMotion';
function renderWithQueryClient() {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
function PreselectProbe() {
const { subject, key } = useContactPreselect();
return <span data-testid="preselect">{`${subject ?? '-'}:${key}`}</span>;
}
function renderSection() {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<QueryClientProvider client={queryClient}>
<PackagesSection />
<ContactPreselectProvider>
<PackagesSection />
<PreselectProbe />
<div id="contact" />
</ContactPreselectProvider>
</QueryClientProvider>,
);
}
function mockFetchOnce(response: Response) {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue(response),
function mockApi(data: unknown, init: ResponseInit = { status: 200 }) {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify(data), init)));
}
function pkg(slug: string, extra: Partial<PackageCardData> = {}): PackageCardData {
return {
id: `id_${slug}`,
slug,
title: `Titel ${slug}`,
description: `Omschrijving ${slug}`,
price: '€ 100',
priceNote: 'eenmalig',
features: ['een', 'twee'],
ctaLabel: `Kies ${slug}`,
...extra,
};
}
const six: PackageCardData[] = [
pkg('landing', { category: 'Websites' }),
pkg('website', { category: 'Websites', featured: true }),
pkg('webshop', { category: 'Websites' }),
pkg('onderhoud', { category: 'Onderhoud' }),
pkg('hosting', { category: 'Onderhoud' }),
pkg('zonder'),
];
async function loaded() {
await waitFor(() =>
expect(screen.queryByTestId('package-card-skeleton')).not.toBeInTheDocument(),
);
}
describe('PackagesSection', () => {
beforeEach(() => {
// Force a deterministic relative URL regardless of the developer's local
// .env.local (VITE_API_BASE_URL is only meant to override this outside tests).
vi.stubEnv('VITE_API_BASE_URL', '');
Element.prototype.scrollIntoView = vi.fn();
});
afterEach(() => {
vi.unstubAllGlobals();
vi.unstubAllEnvs();
clearMatchMedia();
packagesSettings.bannerSlugs = [];
});
it('fetches packages from /api/v1/offerings and renders one PackageCard per package', async () => {
mockFetchOnce(new Response(JSON.stringify(packages), { status: 200 }));
describe('with the three live packages', () => {
it('fetches /api/v1/offerings and renders one card per package, no chips, no banner', async () => {
mockApi(packages);
renderSection();
await loaded();
renderWithQueryClient();
await waitFor(() => {
expect(screen.queryByTestId('package-card-skeleton')).not.toBeInTheDocument();
expect(fetch).toHaveBeenCalledWith('/api/v1/offerings');
expect(screen.getByTestId('packages-grid').children.length).toBe(packages.length);
for (const p of packages) {
expect(screen.getByTestId(`package-card-${p.id}`)).toBeInTheDocument();
}
expect(screen.queryByRole('group', { name: 'Filter pakketten' })).not.toBeInTheDocument();
expect(screen.queryByTestId('package-banner')).not.toBeInTheDocument();
// Maatwerk is a normal card at SLP Software.
expect(screen.getByTestId('package-card-pakket_03')).toBeInTheDocument();
expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent(
'Drie manieren om te starten',
);
expect(screen.getByTestId('packages-status')).toHaveTextContent(
'3 pakketten met vaste prijs',
);
});
expect(fetch).toHaveBeenCalledWith('/api/v1/offerings');
expect(screen.getByTestId('packages-grid').children.length).toBe(packages.length);
for (const pkg of packages) {
expect(screen.getByTestId(`package-card-${pkg.id}`)).toBeInTheDocument();
expect(screen.getByText(pkg.title)).toBeInTheDocument();
}
});
it('marks the featured package as "Meest gekozen"', async () => {
mockFetchOnce(new Response(JSON.stringify(packages), { status: 200 }));
renderWithQueryClient();
await waitFor(() => {
expect(screen.getByText('Meest gekozen')).toBeInTheDocument();
it('marks the featured package as "Meest gekozen"', async () => {
mockApi(packages);
renderSection();
expect(await screen.findByText('Meest gekozen')).toBeInTheDocument();
});
});
it('shows skeleton placeholders while the request is in flight, reserving the grid space', async () => {
let resolveFetch: (response: Response) => void;
vi.stubGlobal(
'fetch',
vi.fn().mockReturnValue(
new Promise<Response>((resolve) => {
resolveFetch = resolve;
describe('states (BR-U3-10)', () => {
it('shows three skeletons while loading and reserves the same container', async () => {
let resolveFetch: (r: Response) => void;
vi.stubGlobal(
'fetch',
vi.fn().mockReturnValue(new Promise<Response>((resolve) => (resolveFetch = resolve))),
);
renderSection();
expect(screen.getAllByTestId('package-card-skeleton')).toHaveLength(3);
expect(screen.queryByTestId('packages-status')).not.toBeInTheDocument();
resolveFetch!(new Response(JSON.stringify(packages), { status: 200 }));
await loaded();
expect(screen.getByTestId('packages-grid').children.length).toBe(3);
});
it('shows an error with a retry button that refetches', async () => {
vi.stubGlobal(
'fetch',
vi
.fn()
.mockResolvedValueOnce(new Response(null, { status: 500 }))
.mockResolvedValue(new Response(JSON.stringify(packages), { status: 200 })),
);
renderSection();
expect(await screen.findByTestId('packages-error')).toHaveTextContent(
'Pakketten konden niet worden geladen.',
);
fireEvent.click(screen.getByTestId('packages-retry'));
await waitFor(() => expect(screen.getByTestId('package-card-pakket_01')).toBeInTheDocument());
expect(fetch).toHaveBeenCalledTimes(2);
});
it('shows a short note when there are no packages', async () => {
mockApi([]);
renderSection();
expect(await screen.findByTestId('packages-empty')).toHaveTextContent(
'Binnenkort meer informatie.',
);
expect(screen.queryByTestId('packages-grid')).not.toBeInTheDocument();
});
});
describe('six packages with categories', () => {
it('shows chips with counts, filters on click and announces the count', async () => {
mockApi(six);
renderSection();
await loaded();
const group = screen.getByRole('group', { name: 'Filter pakketten' });
const chips = within(group).getAllByRole('button');
expect(chips.map((c) => c.textContent)).toEqual(['Alles6', 'Websites3', 'Onderhoud2']);
expect(chips[0]).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent('Manieren om te starten');
expect(screen.getByTestId('packages-status')).toHaveTextContent(
'6 pakketten met vaste prijs',
);
fireEvent.click(chips[2]);
expect(chips[2]).toHaveAttribute('aria-pressed', 'true');
expect(chips[0]).toHaveAttribute('aria-pressed', 'false');
expect(screen.getByTestId('packages-grid').children.length).toBe(2);
expect(screen.getByTestId('packages-status')).toHaveTextContent(
'2 pakketten met vaste prijs',
);
expect(screen.queryByTestId('package-card-id_landing')).not.toBeInTheDocument();
expect(screen.getByTestId('package-card-id_hosting')).toBeInTheDocument();
fireEvent.click(chips[0]);
expect(screen.getByTestId('packages-grid').children.length).toBe(6);
});
it('has no chips with three card packages even when they have categories', async () => {
mockApi(six.slice(0, 3));
renderSection();
await loaded();
expect(screen.queryByRole('group', { name: 'Filter pakketten' })).not.toBeInTheDocument();
});
});
describe('banner (BR-U3-6)', () => {
it('renders the listed slug as the banner instead of a card and keeps it for every chip', async () => {
packagesSettings.bannerSlugs = ['maatwerk'];
mockApi([
...six,
pkg('maatwerk', {
description: 'Op maat gemaakt',
price: 'Op maat',
priceNote: 'offerte na intake',
ctaLabel: 'Vraag offerte aan',
}),
),
);
]);
renderSection();
await loaded();
renderWithQueryClient();
const banner = screen.getByTestId('package-banner');
expect(banner).toHaveTextContent('Past er niets bij?');
expect(banner).toHaveTextContent('Op maat gemaakt');
expect(banner).toHaveTextContent('Vraag offerte aan');
expect(screen.queryByTestId('package-card-id_maatwerk')).not.toBeInTheDocument();
expect(screen.getByTestId('packages-status')).toHaveTextContent(', plus maatwerk');
expect(screen.getAllByTestId('package-card-skeleton')).toHaveLength(packages.length);
resolveFetch!(new Response(JSON.stringify(packages), { status: 200 }));
await waitFor(() => {
expect(screen.queryAllByTestId('package-card-skeleton')).toHaveLength(0);
fireEvent.click(screen.getByTestId('package-chip-cat:Onderhoud'));
expect(screen.getByTestId('package-banner')).toBeInTheDocument();
});
it('uses the fallback texts when no package matches the configured slug', async () => {
packagesSettings.bannerSlugs = ['maatwerk'];
mockApi(packages.filter((p) => p.slug !== 'maatwerk'));
renderSection();
await loaded();
expect(screen.getByTestId('package-banner')).toHaveTextContent(
packagesSettings.bannerFallback.text,
);
});
it('banner button preselects the package and jumps to the contact block', async () => {
packagesSettings.bannerSlugs = ['maatwerk'];
mockApi([...packages.slice(0, 2), pkg('maatwerk')]);
renderSection();
await loaded();
fireEvent.click(screen.getByTestId('package-banner-cta'));
expect(screen.getByTestId('preselect')).toHaveTextContent('maatwerk:1');
});
expect(screen.getByTestId('packages-grid').children.length).toBe(packages.length);
});
it('shows an error message when the API request fails', async () => {
mockFetchOnce(new Response(null, { status: 500, statusText: 'Internal Server Error' }));
describe('contact preselect (BR-U3-9)', () => {
it('sets the slug and increments the key on every click and scrolls to #contact', async () => {
mockApi(packages);
renderSection();
await loaded();
const cta = screen.getByTestId('package-cta-pakket_02');
expect(cta).toHaveAttribute('href', '#contact');
fireEvent.click(cta);
expect(screen.getByTestId('preselect')).toHaveTextContent('website:1');
fireEvent.click(cta);
expect(screen.getByTestId('preselect')).toHaveTextContent('website:2');
expect(Element.prototype.scrollIntoView).toHaveBeenCalled();
});
});
renderWithQueryClient();
describe('swipe row (BR-U3-5, 7, 8, 11)', () => {
it('is a focusable labelled group with snap classes and cards that peek', async () => {
mockApi(packages);
renderSection();
await loaded();
const row = screen.getByRole('group', { name: 'Pakketten' });
expect(row).toHaveAttribute('tabindex', '0');
expect(row).toHaveClass('snap-x', 'snap-mandatory', 'overflow-x-auto', 'sm:grid');
expect(row.children[0]).toHaveClass('w-[85%]', 'snap-center');
});
await waitFor(() => {
expect(screen.getByTestId('packages-error')).toBeInTheDocument();
it('offers one labelled dot per card with the featured card active first', async () => {
mockApi(packages);
renderSection();
await loaded();
const dots = within(screen.getByTestId('swipe-dots')).getAllByRole('button');
expect(dots).toHaveLength(3);
expect(dots[1]).toHaveAttribute('aria-label', 'Pakket 2 van 3: Website');
expect(dots[1]).toHaveAttribute('aria-current', 'true');
expect(dots[0]).not.toHaveAttribute('aria-current');
});
it('scrolls to a card when its dot is clicked (smooth, or instant under reduced motion)', async () => {
mockApi(packages);
renderSection();
await loaded();
const row = screen.getByTestId('packages-grid');
const scrollTo = vi.fn();
row.scrollTo = scrollTo as unknown as typeof row.scrollTo;
fireEvent.click(within(screen.getByTestId('swipe-dots')).getAllByRole('button')[2]);
expect(scrollTo).toHaveBeenCalledWith(expect.objectContaining({ behavior: 'smooth' }));
expect(within(screen.getByTestId('swipe-dots')).getAllByRole('button')[2]).toHaveAttribute(
'aria-current',
'true',
);
});
it('does not animate the scroll under reduced motion', async () => {
mockMatchMedia({ [REDUCED_MOTION_QUERY]: true });
mockApi(packages);
renderSection();
await loaded();
const row = screen.getByTestId('packages-grid');
const scrollTo = vi.fn();
row.scrollTo = scrollTo as unknown as typeof row.scrollTo;
fireEvent.click(within(screen.getByTestId('swipe-dots')).getAllByRole('button')[0]);
expect(scrollTo).toHaveBeenCalledWith(expect.objectContaining({ behavior: 'auto' }));
});
it('follows the scroll position with the active dot', async () => {
mockApi(packages);
renderSection();
await loaded();
const row = screen.getByTestId('packages-grid');
Object.defineProperty(row, 'clientWidth', { value: 360, configurable: true });
Array.from(row.children).forEach((child, i) => {
Object.defineProperty(child, 'offsetLeft', { value: 24 + i * 316, configurable: true });
Object.defineProperty(child, 'offsetWidth', { value: 300, configurable: true });
});
vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback) => {
cb(0);
return 1;
});
row.scrollLeft = 632;
fireEvent.scroll(row);
const dots = within(screen.getByTestId('swipe-dots')).getAllByRole('button');
await waitFor(() => expect(dots[2]).toHaveAttribute('aria-current', 'true'));
});
it('hides the dots with a single package', async () => {
mockApi([packages[0]]);
renderSection();
await loaded();
expect(screen.queryByTestId('swipe-dots')).not.toBeInTheDocument();
});
});
describe('accessibility (BR-U3-11)', () => {
it('labels the section by its heading and renders each package as an article with an h3', async () => {
mockApi(packages);
renderSection();
await loaded();
expect(screen.getByRole('region', { name: /manieren om te starten/i })).toBeInTheDocument();
expect(screen.getAllByRole('article')).toHaveLength(3);
expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(3);
expect(screen.getByTestId('packages-status')).toHaveAttribute('aria-live', 'polite');
});
it('gives chips a 44px touch target', async () => {
mockApi(six);
renderSection();
await loaded();
expect(screen.getByTestId('package-chip-all')).toHaveClass('min-h-[44px]');
});
});
});
@@ -0,0 +1,33 @@
import type { Chip } from '../../../shared/packages/packageLogic';
interface FilterChipsProps {
chips: Chip[];
activeId: string;
onSelect: (id: string) => void;
}
/** Square filter chips of design B (BR-U3-3, BR-U3-11). */
export function FilterChips({ chips, activeId, onSelect }: FilterChipsProps) {
return (
<div role="group" aria-label="Filter pakketten" className="flex flex-wrap gap-2">
{chips.map((chip) => {
const active = chip.id === activeId;
return (
<button
key={chip.id}
type="button"
aria-pressed={active}
onClick={() => onSelect(chip.id)}
data-testid={`package-chip-${chip.id}`}
className={`min-h-[44px] border-2 border-text px-5 text-[15px] font-bold ${
active ? 'bg-text text-bg' : 'bg-transparent text-text'
}`}
>
{chip.label}
<span className="ml-2 font-medium opacity-80">{chip.count}</span>
</button>
);
})}
</div>
);
}
@@ -0,0 +1,53 @@
import type { PackageCardData, PackagesSettings } from '../data/content';
import { handleAnchorClick } from '../../../utils/scrollToHash';
import { useContactPreselect } from '../../../shared/contact/useContactPreselect';
interface PackageBannerProps {
/** The package shown as banner, or undefined to use the fallback texts. */
pkg?: PackageCardData;
settings: PackagesSettings;
}
/** Black "Past er niets bij?" banner under the cards (BR-U3-6). */
export function PackageBanner({ pkg, settings }: PackageBannerProps) {
const { select } = useContactPreselect();
const text = pkg?.description ?? settings.bannerFallback.text;
const price = pkg?.price ?? settings.bannerFallback.priceLabel;
const note = pkg?.priceNote ?? settings.bannerFallback.priceNote;
const cta = pkg?.ctaLabel ?? settings.bannerFallback.ctaLabel;
return (
<div
className="mt-4 flex flex-wrap items-center justify-between gap-x-14 gap-y-8 bg-inv p-[clamp(28px,4vw,48px)] text-white"
data-testid="package-banner"
>
<div className="flex-[1_1_340px]">
<h3 className="mb-2.5 text-[clamp(30px,3.4vw,44px)] font-extrabold leading-none tracking-[-0.02em] [font-stretch:112%]">
{settings.bannerTitle}
</h3>
<p className="max-w-[52ch] text-[#cfcac5]">{text}</p>
</div>
<div className="flex flex-wrap items-center gap-x-8 gap-y-5">
<div>
<div className="text-4xl font-extrabold leading-none tracking-[-0.02em] [font-stretch:125%]">
{price}
</div>
<div className="mt-1.5 text-sm text-[#b9b3ae]">{note}</div>
</div>
<a
href="#contact"
onClick={(event) => {
if (pkg) {
select(pkg.slug);
}
handleAnchorClick(event, '#contact');
}}
className="bg-white px-[26px] py-[17px] text-base font-bold text-[#0e0d0d] no-underline hover:opacity-90"
data-testid="package-banner-cta"
>
{cta}
</a>
</div>
</div>
);
}
+38 -24
View File
@@ -1,49 +1,63 @@
import type { PackageCardData } from '../data/content';
import { handleAnchorClick } from '../../../utils/scrollToHash';
import { useContactPreselect } from '../../../shared/contact/useContactPreselect';
/** Package card of design B: flat block, featured package in the brand colour with a badge. */
export function PackageCard({ pkg }: { pkg: PackageCardData }) {
const { select } = useContactPreselect();
const featured = Boolean(pkg.featured);
return (
<div
className={`relative flex flex-col rounded border p-8 transition-all hover:-translate-y-1 ${
pkg.featured
? 'border-accent-line bg-surface-2'
: 'border-line bg-surface hover:border-accent-line'
<article
className={`relative flex h-full flex-col px-9 pb-9 pt-10 ${
featured ? 'bg-brand text-on-brand' : 'bg-surface-2 text-text'
}`}
data-testid={`package-card-${pkg.id}`}
>
{pkg.featured && (
<span className="font-mono absolute -top-3 left-7 rounded-full bg-accent px-3 py-1 text-[0.7rem] font-bold uppercase tracking-wide text-[var(--color-accent-contrast)]">
{featured && (
<span className="absolute right-0 top-0 bg-[#0e0d0d] px-3.5 py-2 text-[13px] font-bold text-white">
Meest gekozen
</span>
)}
<span className="font-mono mb-3.5 text-[0.78rem] text-accent">{pkg.slug}</span>
<h3 className="mb-2.5 text-xl font-bold">{pkg.title}</h3>
<p className="mb-6 text-[0.95rem] text-muted">{pkg.description}</p>
<div className="font-mono mb-1 text-3xl font-bold">
<h3 className="mb-2.5 text-[30px] font-extrabold leading-[1.05] tracking-[-0.02em] [font-stretch:112%]">
{pkg.title}
</h3>
<p className={`mb-9 text-base ${featured ? 'text-on-brand' : 'text-muted'}`}>
{pkg.description}
</p>
<div className="text-[clamp(40px,4vw,54px)] font-extrabold leading-none tracking-[-0.03em] [font-stretch:125%]">
{pkg.price}
<small className="mt-0.5 block text-[0.78rem] font-normal text-muted">{pkg.priceNote}</small>
</div>
<ul className="my-6 flex-1 list-none">
<div className={`mt-2 text-sm ${featured ? 'text-on-brand' : 'text-muted'}`}>
{pkg.priceNote}
</div>
<ul className="my-8 flex-1 list-none p-0 text-[15px]">
{pkg.features.map((feature) => (
<li key={feature} className="relative mb-2.5 pl-6 text-[0.93rem] text-muted">
<span className="font-mono absolute left-0 text-accent" aria-hidden="true">
→
</span>
{feature}
<li
key={feature}
className={`flex gap-3 border-t py-[9px] ${featured ? 'border-white/30' : 'border-line'}`}
>
<span
aria-hidden="true"
className={`mt-[9px] h-[7px] w-[7px] flex-none ${featured ? 'bg-white' : 'bg-accent'}`}
/>
<span>{feature}</span>
</li>
))}
</ul>
<a
href="#contact"
onClick={(event) => handleAnchorClick(event, '#contact')}
className={`rounded-lg px-6 py-3.5 text-center text-[0.98rem] font-semibold ${
pkg.featured
? 'bg-accent text-[var(--color-accent-contrast)] hover:bg-[var(--color-accent-hover)]'
: 'border border-line text-text hover:border-accent-line'
onClick={(event) => {
select(pkg.slug);
handleAnchorClick(event, '#contact');
}}
className={`block px-5 py-4 text-center text-base font-bold no-underline hover:opacity-90 ${
featured ? 'bg-white text-[#0e0d0d]' : 'bg-text text-bg'
}`}
data-testid={`package-cta-${pkg.id}`}
>
{pkg.ctaLabel}
</a>
</div>
</article>
);
}
@@ -1,26 +1,25 @@
// Mirrors PackageCard's structure/spacing 1-to-1 so the grid doesn't reflow once
// real data arrives — only the content becomes pulsing placeholder blocks.
// Mirrors PackageCard's structure/spacing so the layout doesn't reflow once real data arrives;
// only the content becomes pulsing placeholder blocks.
export function PackageCardSkeleton() {
return (
<div
className="flex animate-pulse flex-col rounded border border-line bg-surface p-8"
className="flex h-full animate-pulse flex-col bg-surface-2 px-9 pb-9 pt-10"
data-testid="package-card-skeleton"
aria-hidden="true"
>
<div className="mb-3.5 h-[0.78rem] w-16 rounded bg-line" />
<div className="mb-2.5 h-6 w-3/4 rounded bg-line" />
<div className="mb-6 space-y-2">
<div className="h-4 w-full rounded bg-line" />
<div className="h-4 w-2/3 rounded bg-line" />
<div className="mb-2.5 h-8 w-3/4 bg-line" />
<div className="mb-9 space-y-2">
<div className="h-4 w-full bg-line" />
<div className="h-4 w-2/3 bg-line" />
</div>
<div className="mb-1 h-8 w-24 rounded bg-line" />
<div className="mb-6 h-[0.78rem] w-28 rounded bg-line" />
<ul className="my-6 flex-1 list-none space-y-2.5">
<div className="h-12 w-32 bg-line" />
<div className="mt-2 h-3.5 w-28 bg-line" />
<ul className="my-8 flex-1 list-none space-y-3 p-0">
{[1, 2, 3, 4].map((i) => (
<li key={i} className="h-4 w-full rounded bg-line" />
<li key={i} className="h-4 w-full bg-line" />
))}
</ul>
<div className="h-[3.4rem] w-full rounded-lg bg-line" />
<div className="h-[52px] w-full bg-line" />
</div>
);
}
@@ -0,0 +1,57 @@
import type { ReactNode } from 'react';
import type { PackageCardData } from '../data/content';
import { initialIndex } from '../../../shared/packages/packageLogic';
import { useSwipeRow } from '../../../shared/packages/useSwipeRow';
import { PackageCard } from './PackageCard';
import { PackageCardSkeleton } from './PackageCardSkeleton';
import { SwipeDots } from './SwipeDots';
const SKELETON_COUNT = 3;
interface PackageListProps {
packages: PackageCardData[];
loading?: boolean;
/** Changes when the filter changes so the swipe row returns to its start position. */
resetKey: string;
}
/**
* One render path for all sizes (BR-U3-5): below `sm` a horizontal scroll-snap row with
* peeking cards and dots, from `sm` a grid (2 columns, 3 above 1000px).
*/
export function PackageList({ packages, loading = false, resetKey }: PackageListProps) {
const items: ReactNode[] = loading
? Array.from({ length: SKELETON_COUNT }, (_, i) => <PackageCardSkeleton key={i} />)
: packages.map((pkg) => <PackageCard key={pkg.id} pkg={pkg} />);
const { ref, activeIndex, scrollToIndex } = useSwipeRow(
items.length,
loading ? 0 : initialIndex(packages),
resetKey,
);
return (
<>
<div
ref={ref}
role="group"
aria-label="Pakketten"
tabIndex={0}
data-testid="packages-grid"
className="-mx-6 flex snap-x snap-mandatory items-stretch gap-4 overflow-x-auto px-6 pb-2 sm:mx-0 sm:grid sm:snap-none sm:grid-cols-2 sm:overflow-visible sm:px-0 sm:pb-0 min-[1001px]:grid-cols-3"
>
{items.map((item, index) => (
<div key={index} className="w-[85%] flex-none snap-center sm:w-auto">
{item}
</div>
))}
</div>
{!loading && (
<SwipeDots
titles={packages.map((pkg) => pkg.title)}
activeIndex={activeIndex}
onSelect={scrollToIndex}
/>
)}
</>
);
}
@@ -1,43 +1,87 @@
import { packagesSettings } from '../data/content';
import { usePackagesQuery } from '../hooks/usePackagesQuery';
import { PackageCard } from './PackageCard';
import { PackageCardSkeleton } from './PackageCardSkeleton';
import { usePackageFilter } from '../../../shared/packages/usePackageFilter';
import { FilterChips } from './FilterChips';
import { PackageBanner } from './PackageBanner';
import { PackageList } from './PackageList';
// Matches the fixed number of packages (see content.ts) so the skeleton grid has the
// same shape as the loaded grid — no layout shift once the real cards arrive.
const SKELETON_COUNT = 3;
function headingFor(count: number): string {
return count === 3 ? 'Drie manieren om te starten' : 'Manieren om te starten';
}
/**
* Packages block of design B: any number of packages, optional filter chips (4+), a swipe row on
* mobile and an optional black banner (per-site setting). See Functional Design BR-U3-1..12.
*/
export function PackagesSection() {
const { data: packages, isLoading, isError } = usePackagesQuery();
const { data, isLoading, isError, refetch } = usePackagesQuery();
const filter = usePackageFilter(data ?? [], packagesSettings);
const loaded = !isLoading && !isError && data !== undefined;
const banner = filter.hasBanner ? (
<PackageBanner pkg={filter.banners[0]} settings={packagesSettings} />
) : null;
return (
<section className="bg-gradient-to-b from-transparent via-surface/50 to-transparent py-[88px]">
<div className="mx-auto max-w-[1080px] px-6">
<div className="mb-[52px]">
<span
id="pakketten"
className="font-mono block scroll-mt-16 text-sm uppercase tracking-wider text-accent"
<section id="pakketten" aria-labelledby="pakketten-heading" className="bg-surface">
<div className="mx-auto max-w-[1280px] px-6 pb-24 pt-20 sm:px-8 md:pb-[136px] md:pt-32">
<div className="mb-12 flex flex-wrap items-end justify-between gap-x-16 gap-y-6 md:mb-[88px]">
<h2
id="pakketten-heading"
className="max-w-[12ch] text-[clamp(40px,5.4vw,80px)] font-extrabold leading-[0.95] tracking-[-0.03em] [font-stretch:112%]"
>
// pakketten
</span>
<h2 className="font-display mt-3.5 text-3xl font-bold sm:text-4xl">
Drie manieren om te starten
{headingFor(loaded ? filter.cards.length : 3)}.
</h2>
<p className="mt-3 max-w-[56ch] text-muted">
<p className="max-w-[40ch] text-body">
Van één sterke pagina tot volledig maatwerk met eigen back-end. Elk pakket heeft een
vaste scope en een vaste prijs.
</p>
</div>
<div className="grid grid-cols-1 gap-[22px] sm:grid-cols-3" data-testid="packages-grid">
{isError ? (
<p className="col-span-full text-center text-muted" data-testid="packages-error">
Pakketten konden niet worden geladen. Probeer het later opnieuw.
{isError ? (
<div className="text-center" data-testid="packages-error" role="alert">
<p className="mb-4 text-muted">Pakketten konden niet worden geladen.</p>
<button
type="button"
onClick={() => void refetch()}
data-testid="packages-retry"
className="min-h-[44px] border-2 border-text px-5 text-[15px] font-bold"
>
Opnieuw proberen
</button>
</div>
) : loaded && data.length === 0 ? (
<div data-testid="packages-empty">
<p className="mb-4 text-muted">
Binnenkort meer informatie. Neem contact op voor een voorstel.
</p>
) : isLoading || !packages ? (
Array.from({ length: SKELETON_COUNT }, (_, i) => <PackageCardSkeleton key={i} />)
) : (
packages.map((pkg) => <PackageCard key={pkg.id} pkg={pkg} />)
)}
</div>
{banner}
</div>
) : (
<>
{loaded && (
<div className="mb-8 flex flex-wrap items-center justify-between gap-x-8 gap-y-4">
{filter.chips ? (
<FilterChips
chips={filter.chips}
activeId={filter.activeId}
onSelect={filter.setActive}
/>
) : (
<span />
)}
<p
className="text-[15px] text-muted"
aria-live="polite"
data-testid="packages-status"
>
{filter.label}
</p>
</div>
)}
<PackageList packages={filter.visible} loading={!loaded} resetKey={filter.activeId} />
{loaded && banner}
</>
)}
</div>
</section>
);
@@ -0,0 +1,34 @@
interface SwipeDotsProps {
titles: string[];
activeIndex: number;
onSelect: (index: number) => void;
}
/** Dot indicator of the mobile swipe row; real buttons with labels (BR-U3-8). */
export function SwipeDots({ titles, activeIndex, onSelect }: SwipeDotsProps) {
if (titles.length < 2) {
return null;
}
return (
<div className="mt-5 flex justify-center gap-1 sm:hidden" data-testid="swipe-dots">
{titles.map((title, index) => {
const active = index === activeIndex;
return (
<button
key={`${title}-${index}`}
type="button"
aria-label={`Pakket ${index + 1} van ${titles.length}: ${title}`}
aria-current={active ? 'true' : undefined}
onClick={() => onSelect(index)}
className="flex h-11 w-8 items-center justify-center"
>
<span
aria-hidden="true"
className={`block h-2.5 w-2.5 rounded-full ${active ? 'bg-text' : 'bg-line'}`}
/>
</button>
);
})}
</div>
);
}
+28
View File
@@ -37,6 +37,21 @@ export interface PackageCardData {
features: string[];
ctaLabel: string;
featured?: boolean;
/** Category name from the CMS (null/absent = no chip). Additive API field. */
category?: string | null;
/** Additive API fields, ignored by the UI. */
categoryId?: string | null;
displayOrder?: number;
}
export interface PackagesSettings {
/** Slugs shown as the black banner under the cards instead of as a card (empty = none). */
bannerSlugs: string[];
/** Filter chips appear from this many card packages on (FR-8). */
chipThreshold: number;
/** Banner title and the texts used when `bannerSlugs` is set but no package matches. */
bannerTitle: string;
bannerFallback: { text: string; priceLabel: string; priceNote: string; ctaLabel: string };
}
export interface ProcessStepData {
@@ -129,6 +144,19 @@ export const packages: PackageCardData[] = [
},
];
/** Per-site packages block settings. SLP Software: Maatwerk stays a normal card (no banner). */
export const packagesSettings: PackagesSettings = {
bannerSlugs: [],
chipThreshold: 4,
bannerTitle: 'Past er niets bij?',
bannerFallback: {
text: 'Grotere websites, een eigen back-end of andere .NET-projecten. Na een intake krijg je een offerte op maat.',
priceLabel: 'Op maat',
priceNote: 'offerte na intake',
ctaLabel: 'Vraag offerte aan',
},
};
export const processSteps: ProcessStepData[] = [
{
label: 'stap 01 — intake',