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:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user