Completes the front-end shell with footer, status pages and SEO
Adds the footer, back-to-top button, skip link, placeholder routes, 404 and error pages inside the shell, plus per-page SEO from a single page registry (canonical URLs, Open Graph image, JSON-LD, generated sitemap.xml and robots.txt). Theme tokens and recipes replace repeated styling, the hero loads only the active and neighbouring slides, and the e-mail address is joined in the browser to keep it out of the HTML and bundle. Adds Vitest with property-based (fast-check) and axe tests, ESLint, security headers for dev and preview, Lighthouse CI and a `pnpm check` script that runs all quality gates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import AppShell from './AppShell';
|
||||
|
||||
describe('AppShell', () => {
|
||||
it('heeft de landmarks van de shell', async () => {
|
||||
const { container } = await renderWithProviders(<AppShell />);
|
||||
expect(screen.getByRole('banner')).toBeInTheDocument();
|
||||
expect(screen.getByRole('main')).toHaveAttribute('id', 'main');
|
||||
expect(screen.getByRole('contentinfo')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('navigation', { name: 'Hoofdmenu' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('navigation', { name: 'Footermenu' }),
|
||||
).toBeInTheDocument();
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('begint met een skip link naar de inhoud', async () => {
|
||||
const { container } = await renderWithProviders(<AppShell />);
|
||||
const skip = screen.getByRole('link', {
|
||||
name: 'Direct naar de inhoud',
|
||||
});
|
||||
expect(skip).toHaveAttribute('href', '#main');
|
||||
// Eerste focusbare element van de pagina
|
||||
expect(container.querySelector('a, button')).toBe(skip);
|
||||
expect(screen.getByRole('main')).toHaveAttribute('tabindex', '-1');
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,27 @@
|
||||
import { SkipNavContent, SkipNavLink } from '@chakra-ui/react';
|
||||
import { Outlet } from '@tanstack/react-router';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import useRouteFocus from '@/hooks/useRouteFocus';
|
||||
import BackToTop from './BackToTop/BackToTop';
|
||||
import Footer from './Footer/Footer';
|
||||
import NavigationBar from './NavigationBar/NavigationBar';
|
||||
import Footer from './Footer';
|
||||
|
||||
// Het frame om elke pagina (LAYOUT.md "Shell"): header, inhoud en footer.
|
||||
// Hier komt de site-brede content binnen; straks uit een loader of de API.
|
||||
export default function AppShell() {
|
||||
useRouteFocus();
|
||||
|
||||
return (
|
||||
<>
|
||||
<SkipNavLink id="main" data-testid="skip-link">
|
||||
Direct naar de inhoud
|
||||
</SkipNavLink>
|
||||
<NavigationBar />
|
||||
<Outlet />
|
||||
<Footer />
|
||||
<SkipNavContent as="main" id="main">
|
||||
<Outlet />
|
||||
</SkipNavContent>
|
||||
<Footer content={siteContent} />
|
||||
<BackToTop />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { act, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import BackToTop from './BackToTop';
|
||||
|
||||
const scrollTo = (y: number) =>
|
||||
act(() => {
|
||||
Object.defineProperty(window, 'scrollY', {
|
||||
value: y,
|
||||
configurable: true,
|
||||
});
|
||||
window.dispatchEvent(new Event('scroll'));
|
||||
});
|
||||
|
||||
const reducedMotion = (matches: boolean) =>
|
||||
vi.spyOn(window, 'matchMedia').mockImplementation(
|
||||
(query: string) =>
|
||||
({
|
||||
matches: matches && query.includes('reduce'),
|
||||
media: query,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
}) as unknown as MediaQueryList,
|
||||
);
|
||||
|
||||
const renderButton = () =>
|
||||
renderWithProviders(
|
||||
<>
|
||||
<main id="main" tabIndex={-1}>
|
||||
inhoud
|
||||
</main>
|
||||
<BackToTop />
|
||||
</>,
|
||||
);
|
||||
|
||||
const button = () => screen.getByTestId('back-to-top-button');
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(window, 'scrollY', { value: 0, configurable: true });
|
||||
});
|
||||
|
||||
describe('BackToTop', () => {
|
||||
it('is bovenaan inert: niet focusbaar en niet voorgelezen', async () => {
|
||||
await renderButton();
|
||||
expect(button()).toHaveAttribute('inert');
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Terug naar boven' }),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('verschijnt pas voorbij 60% van de viewporthoogte', async () => {
|
||||
await renderButton();
|
||||
const threshold = 0.6 * window.innerHeight;
|
||||
await scrollTo(threshold);
|
||||
expect(button()).toHaveAttribute('inert');
|
||||
await scrollTo(threshold + 1);
|
||||
expect(button()).not.toHaveAttribute('inert');
|
||||
expect(screen.getByRole('button', { name: 'Terug naar boven' })).toBe(
|
||||
button(),
|
||||
);
|
||||
});
|
||||
|
||||
it('scrolt soepel naar boven en zet de focus op de inhoud', async () => {
|
||||
const scroll = vi
|
||||
.spyOn(window, 'scrollTo')
|
||||
.mockImplementation(() => {});
|
||||
const { container } = await renderButton();
|
||||
await scrollTo(2000);
|
||||
await userEvent.click(button());
|
||||
expect(scroll).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' });
|
||||
expect(document.activeElement).toBe(document.getElementById('main'));
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('springt direct naar boven bij reduced motion', async () => {
|
||||
reducedMotion(true);
|
||||
const scroll = vi
|
||||
.spyOn(window, 'scrollTo')
|
||||
.mockImplementation(() => {});
|
||||
await renderButton();
|
||||
await scrollTo(2000);
|
||||
await userEvent.click(button());
|
||||
expect(scroll).toHaveBeenCalledWith({ top: 0, behavior: 'instant' });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { chakra } from '@chakra-ui/react';
|
||||
import { Icon } from '@iconify/react/offline';
|
||||
import upOutlined from '@iconify-icons/ant-design/up-outlined';
|
||||
import useScrolledPast from '@/hooks/useScrolledPast';
|
||||
import { backToTopThreshold } from '@/lib/backToTopThreshold';
|
||||
|
||||
// Buiten het component, zodat de functie stabiel is voor useScrolledPast
|
||||
const threshold = () => backToTopThreshold(window.innerHeight);
|
||||
|
||||
// Afstand tot de rand zoals in het design. Op hele brede schermen lijnt de
|
||||
// knop uit met de rand van de content in plaats van de hoek van het scherm.
|
||||
const EDGE = 'clamp(1rem, 3vw, 2rem)';
|
||||
|
||||
// Vaste knop rechtsonder om terug naar boven te gaan (FR-06, BR-TOP-*)
|
||||
export default function BackToTop() {
|
||||
const visible = useScrolledPast(threshold);
|
||||
|
||||
const scrollToTop = () => {
|
||||
const reduced = window.matchMedia(
|
||||
'(prefers-reduced-motion: reduce)',
|
||||
).matches;
|
||||
window.scrollTo({ top: 0, behavior: reduced ? 'instant' : 'smooth' });
|
||||
// De knop verdwijnt bovenaan; de focus gaat naar de inhoud
|
||||
document.getElementById('main')?.focus({ preventScroll: true });
|
||||
};
|
||||
|
||||
return (
|
||||
<chakra.button
|
||||
type="button"
|
||||
onClick={scrollToTop}
|
||||
aria-label="Terug naar boven"
|
||||
data-testid="back-to-top-button"
|
||||
position="fixed"
|
||||
bottom={EDGE}
|
||||
right={`max(${EDGE}, calc((100vw - {sizes.content}) / 2 + {spacing.8}))`}
|
||||
zIndex="backToTop"
|
||||
display="inline-flex"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
w="46px"
|
||||
h="46px"
|
||||
bg="ink"
|
||||
color="white"
|
||||
fontSize="1.1rem"
|
||||
cursor="pointer"
|
||||
// Verborgen = niet zichtbaar, niet focusbaar, niet klikbaar en
|
||||
// niet voorgelezen (BR-TOP-03); inert dekt dat ook zonder CSS af
|
||||
inert={!visible}
|
||||
visibility={visible ? 'visible' : 'hidden'}
|
||||
opacity={visible ? 1 : 0}
|
||||
transform={visible ? 'none' : 'translateY(8px)'}
|
||||
transitionProperty="opacity, transform, visibility, background-color"
|
||||
transitionDuration="interaction"
|
||||
transitionTimingFunction="smooth"
|
||||
_hover={{ bg: 'accent.deep' }}
|
||||
_focusVisible={{ bg: 'accent.deep' }}
|
||||
_motionReduce={{ transitionDuration: '0s', transform: 'none' }}
|
||||
>
|
||||
<Icon icon={upOutlined} aria-hidden />
|
||||
</chakra.button>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
export default function Footer() {
|
||||
return (
|
||||
<footer className="p-2 text-center">
|
||||
<p className="text-sm text-gray-500">
|
||||
© {new Date().getFullYear()} Andrea Slop Fotografie. All
|
||||
rights reserved.
|
||||
</p>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import type { SiteContent } from '@/content/types';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Footer from './Footer';
|
||||
|
||||
const renderFooter = (content: SiteContent = siteContent, path = '/') =>
|
||||
renderWithProviders(<Footer content={content} />, { path });
|
||||
|
||||
describe('Footer', () => {
|
||||
it('toont merk, socials en contact met h2-koppen', async () => {
|
||||
const { container } = await renderFooter();
|
||||
expect(
|
||||
screen.getByRole('img', { name: 'Andrea Slop Fotografie' }),
|
||||
).toBeInTheDocument();
|
||||
// Regelafbreking uit de content blijft in de tekst staan
|
||||
expect(
|
||||
screen.getByText(siteContent.footerIntro, {
|
||||
normalizer: (text) => text,
|
||||
}),
|
||||
).toHaveStyle({ whiteSpace: 'pre-line' });
|
||||
const headings = screen.getAllByRole('heading', { level: 2 });
|
||||
// Naam in gewone schrijfwijze, los van de CSS-hoofdletters
|
||||
expect(headings.map((h) => h.getAttribute('aria-label'))).toEqual([
|
||||
'Socials',
|
||||
'Contact',
|
||||
]);
|
||||
expect(headings.map((h) => h.textContent)).toEqual([
|
||||
'Socials',
|
||||
'Contact',
|
||||
]);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('opent socials veilig in een nieuw tabblad en meldt dat', async () => {
|
||||
await renderFooter();
|
||||
const link = screen.getByRole('link', {
|
||||
name: 'Facebook (opent in nieuw tabblad)',
|
||||
});
|
||||
expect(link).toHaveAttribute('target', '_blank');
|
||||
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
expect(link).toHaveAttribute('href', siteContent.socials[0].href);
|
||||
});
|
||||
|
||||
it('voegt het e-mailadres pas bij het tonen samen', async () => {
|
||||
await renderFooter();
|
||||
const link = screen.getByTestId('footer-email-link');
|
||||
expect(link).toHaveAttribute('href', 'mailto:info@andreaslop.nl');
|
||||
expect(link).toHaveTextContent('info@andreaslop.nl');
|
||||
});
|
||||
|
||||
it('toont het huidige jaar', async () => {
|
||||
await renderFooter();
|
||||
expect(
|
||||
screen.getByText(
|
||||
`© ${new Date().getFullYear()} Andrea Slop Fotografie`,
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('heeft een footermenu dat de actieve pagina markeert', async () => {
|
||||
await renderFooter(siteContent, '/portfolio');
|
||||
const nav = screen.getByRole('navigation', { name: 'Footermenu' });
|
||||
const links = within(nav).getAllByRole('link');
|
||||
expect(links.map((l) => l.textContent)).toEqual([
|
||||
'Portfolio',
|
||||
'Soorten fotoshoots',
|
||||
'Contact',
|
||||
'Privacyverklaring',
|
||||
]);
|
||||
expect(links[0]).toHaveAttribute('aria-current', 'page');
|
||||
expect(links[1]).not.toHaveAttribute('aria-current');
|
||||
});
|
||||
|
||||
it('laat lege kolommen weg', async () => {
|
||||
await renderFooter({
|
||||
...siteContent,
|
||||
socials: [{ platform: 'facebook', href: '' }],
|
||||
email: { user: '', domain: 'andreaslop.nl' },
|
||||
});
|
||||
expect(screen.queryByRole('heading', { name: 'Socials' })).toBeNull();
|
||||
expect(screen.queryByRole('heading', { name: 'Contact' })).toBeNull();
|
||||
expect(screen.queryByTestId('footer-email-link')).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,154 @@
|
||||
import {
|
||||
Box,
|
||||
chakra,
|
||||
Container,
|
||||
Flex,
|
||||
Grid,
|
||||
Image,
|
||||
Text,
|
||||
VisuallyHidden,
|
||||
} from '@chakra-ui/react';
|
||||
import socialPlatforms from '@/content/socialPlatforms';
|
||||
import type { SiteContent } from '@/content/types';
|
||||
import { copyrightLine } from '@/lib/copyrightLine';
|
||||
import { emailAddress } from '@/lib/emailAddress';
|
||||
import { visibleSocials } from '@/lib/visibleSocials';
|
||||
import { footerNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import FooterColumn from './FooterColumn';
|
||||
import FooterLink from './FooterLink';
|
||||
|
||||
// Images
|
||||
import logoDark from '../../assets/logo-dark.png';
|
||||
|
||||
type FooterProps = {
|
||||
content: SiteContent;
|
||||
};
|
||||
|
||||
// Footer uit het design (FR-05): merk, socials en contact, met daaronder de
|
||||
// copyright en het footermenu. Een lege kolom valt weg (BR-FOOT-01).
|
||||
export default function Footer({ content }: FooterProps) {
|
||||
const socials = visibleSocials(content.socials);
|
||||
// Pas hier samengevoegd, zodat het adres nergens letterlijk staat
|
||||
const email = emailAddress(content.email);
|
||||
const year = new Date().getFullYear();
|
||||
|
||||
return (
|
||||
<Box
|
||||
as="footer"
|
||||
bg="paper.alt"
|
||||
borderTopWidth="1px"
|
||||
borderTopColor="line"
|
||||
pt="clamp(3.5rem, 7vw, 6rem)"
|
||||
>
|
||||
<Container>
|
||||
<Grid
|
||||
templateColumns={{
|
||||
base: '1fr',
|
||||
md: 'repeat(2, 1fr)',
|
||||
lg: '1.2fr 1fr 1fr',
|
||||
}}
|
||||
gap="clamp(2rem, 5vw, 4rem)"
|
||||
pb="clamp(2.5rem, 5vw, 4rem)"
|
||||
>
|
||||
{/* Merk: op mobiel gecentreerd onder elkaar, vanaf tablet
|
||||
het logo met de tekst ernaast */}
|
||||
<Flex
|
||||
direction={{ base: 'column', md: 'row' }}
|
||||
alignItems="center"
|
||||
alignSelf="start"
|
||||
gap={5}
|
||||
textAlign={{ base: 'center', md: 'start' }}
|
||||
>
|
||||
<Image
|
||||
src={logoDark}
|
||||
alt="Andrea Slop Fotografie"
|
||||
htmlWidth={500}
|
||||
htmlHeight={500}
|
||||
w={{ base: '150px', md: '110px' }}
|
||||
h="auto"
|
||||
flexShrink={0}
|
||||
loading="lazy"
|
||||
/>
|
||||
{/* Regelafbrekingen uit de content blijven staan */}
|
||||
<Text color="ink.soft" whiteSpace="pre-line">
|
||||
{content.footerIntro}
|
||||
</Text>
|
||||
</Flex>
|
||||
|
||||
{socials.length > 0 && (
|
||||
<FooterColumn title="Socials">
|
||||
{socials.map((social) => (
|
||||
<chakra.li key={social.platform}>
|
||||
<FooterLink
|
||||
href={social.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
data-testid={`footer-social-${social.platform}`}
|
||||
>
|
||||
{/* Spatie buiten de verborgen tekst, anders
|
||||
valt hij weg uit de voorgelezen naam */}
|
||||
{socialPlatforms[social.platform].name}{' '}
|
||||
<VisuallyHidden>
|
||||
(opent in nieuw tabblad)
|
||||
</VisuallyHidden>
|
||||
</FooterLink>
|
||||
</chakra.li>
|
||||
))}
|
||||
</FooterColumn>
|
||||
)}
|
||||
|
||||
{email && (
|
||||
<FooterColumn title="Contact">
|
||||
<chakra.li>
|
||||
<FooterLink
|
||||
href={`mailto:${email}`}
|
||||
data-testid="footer-email-link"
|
||||
>
|
||||
{email}
|
||||
</FooterLink>
|
||||
</chakra.li>
|
||||
</FooterColumn>
|
||||
)}
|
||||
</Grid>
|
||||
|
||||
<Flex
|
||||
direction={{ base: 'column', md: 'row' }}
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
gap={{ base: 2, md: 6 }}
|
||||
py={6}
|
||||
borderTopWidth="1px"
|
||||
borderTopColor="line"
|
||||
textAlign={{ base: 'center', md: 'start' }}
|
||||
>
|
||||
<Text fontSize="sm" color="ink.soft">
|
||||
{copyrightLine(year)}
|
||||
</Text>
|
||||
<chakra.nav aria-label="Footermenu">
|
||||
<Flex
|
||||
as="ul"
|
||||
listStyleType="none"
|
||||
wrap="wrap"
|
||||
justifyContent="center"
|
||||
columnGap={6}
|
||||
>
|
||||
{footerNav.map((item) => (
|
||||
<chakra.li key={item.to}>
|
||||
<FooterLink asChild>
|
||||
<RouterLink
|
||||
to={item.to}
|
||||
data-testid={`footer-nav-${item.to.slice(1)}`}
|
||||
>
|
||||
{item.label}
|
||||
</RouterLink>
|
||||
</FooterLink>
|
||||
</chakra.li>
|
||||
))}
|
||||
</Flex>
|
||||
</chakra.nav>
|
||||
</Flex>
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Box, Heading, Stack } from '@chakra-ui/react';
|
||||
|
||||
type FooterColumnProps = {
|
||||
title: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
// Kolom in de footer: kopje als label, daaronder een lijst. De kop is een h2,
|
||||
// want de kolommen zijn hoofdsecties van de pagina (BR-SEO-09).
|
||||
export default function FooterColumn({ title, children }: FooterColumnProps) {
|
||||
return (
|
||||
<Box>
|
||||
<Heading
|
||||
as="h2"
|
||||
// Mobiele schermlezers lezen de CSS-hoofdletters ("SOCIALS") als
|
||||
// afkorting; het label geeft ze het woord in gewone schrijfwijze
|
||||
aria-label={title}
|
||||
textStyle="eyebrow"
|
||||
fontFamily="body"
|
||||
color="ink.soft"
|
||||
mb={{ base: 2, lg: 4 }}
|
||||
>
|
||||
{title}
|
||||
</Heading>
|
||||
<Stack as="ul" listStyleType="none" gap={{ base: 0, lg: 2 }}>
|
||||
{children}
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Link, type LinkProps } from '@chakra-ui/react';
|
||||
|
||||
// Link in de footer: de rustige `subtle`-stijl, en op touch minimaal 44px
|
||||
// hoog als klikdoel (BR-RWD-04)
|
||||
export default function FooterLink(props: LinkProps) {
|
||||
return (
|
||||
<Link
|
||||
variant="subtle"
|
||||
minH={{ base: '44px', lg: 'auto' }}
|
||||
fontSize="sm"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import heroContent from '@/content/heroContent';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Hero from './Hero';
|
||||
|
||||
describe('Hero', () => {
|
||||
it('toont alleen geldige socials, met melding over het nieuwe tabblad', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Hero
|
||||
content={heroContent}
|
||||
socials={[
|
||||
...siteContent.socials,
|
||||
{ platform: 'facebook', href: 'javascript:alert(1)' },
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
const links = screen.getAllByRole('link', {
|
||||
name: /opent in nieuw tabblad/,
|
||||
});
|
||||
expect(links).toHaveLength(2);
|
||||
expect(links[0]).toHaveAccessibleName(
|
||||
'Facebook (opent in nieuw tabblad)',
|
||||
);
|
||||
expect(links[0]).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('laadt eerst de eerste foto, daarna alleen de volgende en vorige', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Hero content={heroContent} socials={siteContent.socials} />,
|
||||
);
|
||||
const sources = () =>
|
||||
[...container.querySelectorAll('img')].map((img) =>
|
||||
img.getAttribute('src'),
|
||||
);
|
||||
const slide = (i: number) => heroContent.slides[i].src;
|
||||
const last = heroContent.slides.length - 1;
|
||||
|
||||
expect(sources()).toEqual([slide(0)]);
|
||||
fireEvent.load(container.querySelector('img')!);
|
||||
// Vanaf de eerste foto is de vorige de laatste
|
||||
await waitFor(() =>
|
||||
expect(sources()).toEqual([slide(0), slide(1), slide(last)]),
|
||||
);
|
||||
|
||||
await userEvent.click(
|
||||
screen.getByRole('button', { name: 'Volgende foto' }),
|
||||
);
|
||||
expect(sources()).toEqual([slide(0), slide(1), slide(2)]);
|
||||
});
|
||||
|
||||
it('heeft pijlen met een toegankelijke naam', async () => {
|
||||
await renderWithProviders(
|
||||
<Hero content={heroContent} socials={siteContent.socials} />,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Vorige foto' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Volgende foto' }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,20 +1,35 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, chakra, Container, Heading, Image } from '@chakra-ui/react';
|
||||
import LinkButton from '../LinkButton';
|
||||
import HeroArrows from './HeroArrows';
|
||||
import HeroSocials from './HeroSocials';
|
||||
import useHeroSlider from './useHeroSlider';
|
||||
import type { HeroContent } from './types';
|
||||
import type { HeroContent, SocialLink } from '@/content/types';
|
||||
import { slidesToLoad } from '@/lib/slidesToLoad';
|
||||
|
||||
const SLIDE_DURATION = '6s';
|
||||
|
||||
type HeroProps = {
|
||||
content: HeroContent;
|
||||
socials: SocialLink[];
|
||||
};
|
||||
|
||||
export default function Hero({ content }: HeroProps) {
|
||||
const { title, tagline, cta, slides, socials } = content;
|
||||
export default function Hero({ content, socials }: HeroProps) {
|
||||
const { title, tagline, cta, slides } = content;
|
||||
const { active, reducedMotion, autoplay, paused, next, prev, handlers } =
|
||||
useHeroSlider(slides.length);
|
||||
// De slides liggen op elkaar in beeld, dus loading="lazy" stelt niets uit.
|
||||
// Eerst alleen de actieve foto; zodra die binnen en getekend is (twee
|
||||
// frames later, dus na de eerste paint) ook de volgende en de vorige.
|
||||
// Verder weg laden we pas als de slider in de buurt komt (BR-HERO-01).
|
||||
const [firstPainted, setFirstPainted] = useState(false);
|
||||
const onFirstLoaded = () =>
|
||||
requestAnimationFrame(() =>
|
||||
requestAnimationFrame(() => setFirstPainted(true)),
|
||||
);
|
||||
const loaded = firstPainted
|
||||
? slidesToLoad(active, slides.length)
|
||||
: [active];
|
||||
|
||||
return (
|
||||
<Box
|
||||
@@ -48,21 +63,28 @@ export default function Hero({ content }: HeroProps) {
|
||||
transitionDuration="fade"
|
||||
transitionTimingFunction="smooth"
|
||||
>
|
||||
<Image
|
||||
src={slide.src}
|
||||
alt={slide.alt}
|
||||
fetchPriority={i === 0 ? 'high' : undefined}
|
||||
loading={i === 0 ? undefined : 'lazy'}
|
||||
w="100%"
|
||||
h="100%"
|
||||
objectFit="cover"
|
||||
transform={
|
||||
reducedMotion || i === active
|
||||
? 'scale(1)'
|
||||
: 'scale(1.06)'
|
||||
}
|
||||
transition="transform 9s linear"
|
||||
/>
|
||||
{loaded.includes(i) && (
|
||||
<Image
|
||||
src={slide.src}
|
||||
alt={slide.alt}
|
||||
fetchPriority={i === 0 ? 'high' : undefined}
|
||||
onLoad={
|
||||
firstPainted ? undefined : onFirstLoaded
|
||||
}
|
||||
onError={
|
||||
firstPainted ? undefined : onFirstLoaded
|
||||
}
|
||||
w="100%"
|
||||
h="100%"
|
||||
objectFit="cover"
|
||||
transform={
|
||||
reducedMotion || i === active
|
||||
? 'scale(1)'
|
||||
: 'scale(1.06)'
|
||||
}
|
||||
transition="transform 9s linear"
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { chakra } from '@chakra-ui/react';
|
||||
import { chakra, useRecipe } from '@chakra-ui/react';
|
||||
import { Icon } from '@iconify/react/offline';
|
||||
import leftOutlined from '@iconify-icons/ant-design/left-outlined';
|
||||
import rightOutlined from '@iconify-icons/ant-design/right-outlined';
|
||||
@@ -12,10 +12,20 @@ type HeroArrowsProps = {
|
||||
export default function HeroArrows({ onPrev, onNext }: HeroArrowsProps) {
|
||||
return (
|
||||
<>
|
||||
<ArrowButton side="left" aria-label="Vorige foto" onClick={onPrev}>
|
||||
<ArrowButton
|
||||
side="left"
|
||||
aria-label="Vorige foto"
|
||||
data-testid="hero-prev-button"
|
||||
onClick={onPrev}
|
||||
>
|
||||
<Icon icon={leftOutlined} aria-hidden />
|
||||
</ArrowButton>
|
||||
<ArrowButton side="right" aria-label="Volgende foto" onClick={onNext}>
|
||||
<ArrowButton
|
||||
side="right"
|
||||
aria-label="Volgende foto"
|
||||
data-testid="hero-next-button"
|
||||
onClick={onNext}
|
||||
>
|
||||
<Icon icon={rightOutlined} aria-hidden />
|
||||
</ArrowButton>
|
||||
</>
|
||||
@@ -29,26 +39,20 @@ type ArrowButtonProps = React.ComponentProps<typeof chakra.button> & {
|
||||
const ARROW_OFFSET = 'clamp(0.5rem, 3vw, 2.5rem)';
|
||||
|
||||
function ArrowButton({ side, ...props }: ArrowButtonProps) {
|
||||
// Doorzichtigheid, hover en witte focusring komen uit de iconControl-recipe
|
||||
const iconControl = useRecipe({ key: 'iconControl' });
|
||||
|
||||
return (
|
||||
<chakra.button
|
||||
type="button"
|
||||
css={iconControl()}
|
||||
position="absolute"
|
||||
top="50%"
|
||||
left={side === 'left' ? ARROW_OFFSET : undefined}
|
||||
right={side === 'right' ? ARROW_OFFSET : undefined}
|
||||
zIndex={2}
|
||||
transform="translateY(-50%)"
|
||||
display="flex"
|
||||
p={2}
|
||||
color="white"
|
||||
fontSize={{ base: '1.5rem', md: '2rem' }}
|
||||
cursor="pointer"
|
||||
opacity={0.6}
|
||||
transitionProperty="opacity"
|
||||
transitionDuration="interaction"
|
||||
transitionTimingFunction="smooth"
|
||||
_hover={{ opacity: 1 }}
|
||||
_focusVisible={{ opacity: 1, outline: '1px solid white', outlineOffset: '2px' }}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,48 +1,43 @@
|
||||
import { chakra, HStack } from '@chakra-ui/react';
|
||||
import { chakra, HStack, useRecipe } from '@chakra-ui/react';
|
||||
import { Icon } from '@iconify/react/offline';
|
||||
import socialPlatforms from './socialPlatforms';
|
||||
import type { HeroSocial } from './types';
|
||||
import socialPlatforms from '@/content/socialPlatforms';
|
||||
import type { SocialLink } from '@/content/types';
|
||||
import { visibleSocials } from '@/lib/visibleSocials';
|
||||
|
||||
type HeroSocialsProps = {
|
||||
socials: HeroSocial[];
|
||||
socials: SocialLink[];
|
||||
};
|
||||
|
||||
// Socials linksonder, naast elkaar
|
||||
export default function HeroSocials({ socials }: HeroSocialsProps) {
|
||||
const iconControl = useRecipe({ key: 'iconControl' });
|
||||
|
||||
return (
|
||||
<HStack
|
||||
position="absolute"
|
||||
left="gutter"
|
||||
bottom={{ base: 6, md: 10 }}
|
||||
zIndex={2}
|
||||
gap={5}
|
||||
color="white"
|
||||
gap={2}
|
||||
fontSize="1.5rem"
|
||||
>
|
||||
{socials
|
||||
.filter((social) => social.href)
|
||||
.map((social) => {
|
||||
const { name, icon } = socialPlatforms[social.platform];
|
||||
{visibleSocials(socials).map((social) => {
|
||||
const { name, icon } = socialPlatforms[social.platform];
|
||||
|
||||
return (
|
||||
<chakra.a
|
||||
key={social.platform}
|
||||
href={social.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={name}
|
||||
display="flex"
|
||||
opacity={0.6}
|
||||
transitionProperty="opacity"
|
||||
transitionDuration="interaction"
|
||||
transitionTimingFunction="smooth"
|
||||
_hover={{ opacity: 1 }}
|
||||
_focusVisible={{ opacity: 1 }}
|
||||
>
|
||||
<Icon icon={icon} aria-hidden />
|
||||
</chakra.a>
|
||||
);
|
||||
})}
|
||||
return (
|
||||
<chakra.a
|
||||
key={social.platform}
|
||||
href={social.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={`${name} (opent in nieuw tabblad)`}
|
||||
data-testid={`hero-social-${social.platform}`}
|
||||
css={iconControl()}
|
||||
>
|
||||
<Icon icon={icon} aria-hidden />
|
||||
</chakra.a>
|
||||
);
|
||||
})}
|
||||
</HStack>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import type { HeroContent } from './types';
|
||||
|
||||
// Images
|
||||
import hero1 from '../../assets/hero-1.jpg';
|
||||
import hero2 from '../../assets/hero-2.jpg';
|
||||
import newborn from '../../assets/newborn.jpg';
|
||||
import hero4 from '../../assets/hero-4.jpg';
|
||||
import hero5 from '../../assets/hero-5.jpg';
|
||||
import hero6 from '../../assets/hero-6.jpg';
|
||||
|
||||
// Statische content tot de CMS-API er is. Daarna komt dit object uit de API.
|
||||
const heroContent: HeroContent = {
|
||||
title: 'Andrea Slop',
|
||||
tagline: 'Lifestyle fotograaf · Huizen',
|
||||
cta: { label: 'Lees meer', to: '/over-mij' },
|
||||
slides: [
|
||||
{ id: 'hero-1', src: hero1, alt: 'Lifestyle fotografie van Andrea Slop' },
|
||||
{ id: 'hero-2', src: hero2, alt: 'Zwangerschapsshoot in de buitenlucht' },
|
||||
{ id: 'newborn', src: newborn, alt: 'Newbornshoot van een pasgeboren baby' },
|
||||
{ id: 'hero-4', src: hero4, alt: 'Spontaan portret buiten' },
|
||||
{ id: 'hero-5', src: hero5, alt: 'Natuurlijke lifestylefoto' },
|
||||
{ id: 'hero-6', src: hero6, alt: 'Portret in de natuur' },
|
||||
],
|
||||
socials: [
|
||||
{
|
||||
platform: 'facebook',
|
||||
href: 'https://www.facebook.com/andreaslopfotografie/',
|
||||
},
|
||||
{
|
||||
platform: 'instagram',
|
||||
href: 'https://www.instagram.com/andreaslopfotografie/',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default heroContent;
|
||||
@@ -1,13 +0,0 @@
|
||||
import facebookFilled from '@iconify-icons/ant-design/facebook-filled';
|
||||
import instagramFilled from '@iconify-icons/ant-design/instagram-filled';
|
||||
|
||||
// Vaste set ondersteunde platforms. De icon-data zit in de build, dus er gaat
|
||||
// geen request naar de Iconify API. Het CMS levert alleen de links aan.
|
||||
const socialPlatforms = {
|
||||
facebook: { name: 'Facebook', icon: facebookFilled },
|
||||
instagram: { name: 'Instagram', icon: instagramFilled },
|
||||
};
|
||||
|
||||
export type SocialPlatform = keyof typeof socialPlatforms;
|
||||
|
||||
export default socialPlatforms;
|
||||
@@ -1,30 +0,0 @@
|
||||
import type { SocialPlatform } from './socialPlatforms';
|
||||
|
||||
// Vorm van de hero-content. Deze types zijn bewust platte data (strings en
|
||||
// arrays) zodat ze later 1-op-1 uit de CMS-API kunnen komen.
|
||||
|
||||
export interface HeroSlide {
|
||||
id: string;
|
||||
src: string;
|
||||
alt: string;
|
||||
}
|
||||
|
||||
export interface HeroCta {
|
||||
label: string;
|
||||
to: string;
|
||||
}
|
||||
|
||||
export interface HeroSocial {
|
||||
platform: SocialPlatform;
|
||||
href: string; // leeg = niet tonen
|
||||
}
|
||||
|
||||
export interface HeroContent {
|
||||
title: string;
|
||||
// Klein label in hoofdletters boven de titel: wat en waar, voor bezoekers
|
||||
// en zoekmachines (bv. "Lifestyle fotograaf · Huizen")
|
||||
tagline: string;
|
||||
cta: HeroCta;
|
||||
slides: HeroSlide[];
|
||||
socials: HeroSocial[];
|
||||
}
|
||||
@@ -12,15 +12,22 @@ export default function useHeroSlider(count: number) {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [focused, setFocused] = useState(false);
|
||||
const [hidden, setHidden] = useState(() => document.hidden);
|
||||
const [reducedMotion] = useMediaQuery(['(prefers-reduced-motion: reduce)'], {
|
||||
ssr: false,
|
||||
});
|
||||
const [reducedMotion] = useMediaQuery(
|
||||
['(prefers-reduced-motion: reduce)'],
|
||||
{
|
||||
ssr: false,
|
||||
},
|
||||
);
|
||||
const touchStart = useRef<{ x: number; y: number } | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const onVisibilityChange = () => setHidden(document.hidden);
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
return () => document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
return () =>
|
||||
document.removeEventListener(
|
||||
'visibilitychange',
|
||||
onVisibilityChange,
|
||||
);
|
||||
}, []);
|
||||
|
||||
// Als de API minder slides teruggeeft dan de huidige index, begin vooraan.
|
||||
@@ -65,7 +72,11 @@ export default function useHeroSlider(count: number) {
|
||||
const dy = touch.clientY - start.y;
|
||||
|
||||
// Horizontaal genoeg, en niet bedoeld als verticaal scrollen
|
||||
if (Math.abs(dx) < SWIPE_THRESHOLD || Math.abs(dx) < Math.abs(dy)) return;
|
||||
if (
|
||||
Math.abs(dx) < SWIPE_THRESHOLD ||
|
||||
Math.abs(dx) < Math.abs(dy)
|
||||
)
|
||||
return;
|
||||
if (dx < 0) next();
|
||||
else prev();
|
||||
},
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { chakra, useRecipe, type RecipeVariantProps } from '@chakra-ui/react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import { useRecipe, type RecipeVariantProps } from '@chakra-ui/react';
|
||||
import type linkButtonRecipe from '../recipes/linkButton';
|
||||
import RouterLink from './RouterLink';
|
||||
|
||||
const ChakraLink = chakra(Link);
|
||||
|
||||
type LinkButtonProps = React.ComponentProps<typeof ChakraLink> &
|
||||
type LinkButtonProps = React.ComponentProps<typeof RouterLink> &
|
||||
RecipeVariantProps<typeof linkButtonRecipe>;
|
||||
|
||||
// Router-link in de knopstijl uit het design. Styling komt uit de
|
||||
@@ -13,5 +11,5 @@ export default function LinkButton(props: LinkButtonProps) {
|
||||
const recipe = useRecipe({ key: 'linkButton' });
|
||||
const [variantProps, rest] = recipe.splitVariantProps(props);
|
||||
|
||||
return <ChakraLink css={recipe(variantProps)} {...rest} />;
|
||||
return <RouterLink css={recipe(variantProps)} {...rest} />;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Box, chakra, Stack } from '@chakra-ui/react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import navItems from './navItems';
|
||||
|
||||
const ChakraLink = chakra(Link);
|
||||
import { Box, Stack } from '@chakra-ui/react';
|
||||
import { mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
|
||||
type MobileNavProps = {
|
||||
id: string;
|
||||
@@ -37,7 +35,7 @@ export default function MobileNav({ id, open, onClose }: MobileNavProps) {
|
||||
insetX={0}
|
||||
bottom={0}
|
||||
// Net onder de balk, zodat de schaduw van de balk erover valt
|
||||
zIndex="calc({zIndex.docked} - 1)"
|
||||
zIndex="mobileNav"
|
||||
display={{ base: 'flex', lg: 'none' }}
|
||||
flexDirection="column"
|
||||
justifyContent="center"
|
||||
@@ -54,9 +52,9 @@ export default function MobileNav({ id, open, onClose }: MobileNavProps) {
|
||||
>
|
||||
<nav aria-label="Mobiel menu">
|
||||
<Stack as="ul" gap={5} listStyleType="none">
|
||||
{navItems.map((item) => (
|
||||
{mainNav.map((item) => (
|
||||
<li key={item.to}>
|
||||
<ChakraLink
|
||||
<RouterLink
|
||||
to={item.to}
|
||||
onClick={onClose}
|
||||
display="block"
|
||||
@@ -66,7 +64,7 @@ export default function MobileNav({ id, open, onClose }: MobileNavProps) {
|
||||
_currentPage={{ color: 'accent' }}
|
||||
>
|
||||
{item.label}
|
||||
</ChakraLink>
|
||||
</RouterLink>
|
||||
</li>
|
||||
))}
|
||||
</Stack>
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { chakra } from '@chakra-ui/react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import RouterLink from '../RouterLink';
|
||||
|
||||
const ChakraLink = chakra(Link);
|
||||
|
||||
type NavLinkProps = React.ComponentProps<typeof ChakraLink>;
|
||||
type NavLinkProps = React.ComponentProps<typeof RouterLink>;
|
||||
|
||||
export default function NavLink({ children, ...props }: NavLinkProps) {
|
||||
return (
|
||||
<ChakraLink
|
||||
<RouterLink
|
||||
textStyle="eyebrow"
|
||||
fontWeight="300"
|
||||
position="relative"
|
||||
@@ -38,6 +35,6 @@ export default function NavLink({ children, ...props }: NavLinkProps) {
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</ChakraLink>
|
||||
</RouterLink>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import NavigationBar from './NavigationBar';
|
||||
|
||||
describe('NavigationBar', () => {
|
||||
it('heeft het logo als link naar home', async () => {
|
||||
await renderWithProviders(<NavigationBar />, { path: '/portfolio' });
|
||||
expect(
|
||||
screen.getByRole('link', {
|
||||
name: 'Andrea Slop Fotografie, naar de homepage',
|
||||
}),
|
||||
).toHaveAttribute('href', '/');
|
||||
});
|
||||
|
||||
it('toont het hoofdmenu in de vaste volgorde', async () => {
|
||||
const { container } = await renderWithProviders(<NavigationBar />);
|
||||
const nav = screen.getByRole('navigation', { name: 'Hoofdmenu' });
|
||||
expect(
|
||||
within(nav)
|
||||
.getAllByRole('link', { hidden: true })
|
||||
.map((link) => link.textContent),
|
||||
).toEqual([
|
||||
'Home',
|
||||
'Over mij',
|
||||
'Portfolio',
|
||||
'Soorten fotoshoots',
|
||||
'Contact',
|
||||
]);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('heeft een menuknop met een toegankelijke naam', async () => {
|
||||
await renderWithProviders(<NavigationBar />);
|
||||
expect(screen.getByTestId('nav-menu-toggle')).toHaveAccessibleName(
|
||||
'Menu openen',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -3,13 +3,13 @@ import {
|
||||
HStack,
|
||||
chakra,
|
||||
Image,
|
||||
Box,
|
||||
Container,
|
||||
useBreakpointValue,
|
||||
} from '@chakra-ui/react';
|
||||
import NavLink from './NavLink';
|
||||
import MobileNav from './MobileNav';
|
||||
import navItems from './navItems';
|
||||
import { mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import useScrolledPast from '@/hooks/useScrolledPast';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useRouterState } from '@tanstack/react-router';
|
||||
@@ -19,7 +19,7 @@ import logoLight from '../../assets/logo-light.png';
|
||||
import logoDark from '../../assets/logo-dark.png';
|
||||
|
||||
export default function NavigationBar() {
|
||||
let [open, setOpen] = useState(false);
|
||||
const [open, setOpen] = useState(false);
|
||||
const closeMenu = useCallback(() => setOpen(false), []);
|
||||
|
||||
// Het mobiele menu bestaat alleen onder lg; wordt het scherm breder, dan
|
||||
@@ -47,7 +47,7 @@ export default function NavigationBar() {
|
||||
position="fixed"
|
||||
top={0}
|
||||
insetX={0}
|
||||
zIndex="docked"
|
||||
zIndex="header"
|
||||
// Zelfde hoogte als waar de hero-content onder begint; kleiner na scrollen
|
||||
h={pastHero ? 'header.sticky' : 'header'}
|
||||
display="flex"
|
||||
@@ -69,7 +69,11 @@ export default function NavigationBar() {
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
>
|
||||
<Box
|
||||
<RouterLink
|
||||
to="/"
|
||||
aria-label="Andrea Slop Fotografie, naar de homepage"
|
||||
data-testid="nav-logo-link"
|
||||
display="block"
|
||||
flexBasis="auto"
|
||||
flexGrow={1}
|
||||
flexShrink={0}
|
||||
@@ -84,17 +88,22 @@ export default function NavigationBar() {
|
||||
transitionTimingFunction="smooth"
|
||||
>
|
||||
{/* Twee logo's, zodat de kleur per schermbreedte kan wisselen */}
|
||||
{/* De link heeft de naam; de logo's zelf zijn decoratief */}
|
||||
<Image
|
||||
src={logoDark}
|
||||
alt="Andrea Slop Fotografie"
|
||||
alt=""
|
||||
htmlWidth={500}
|
||||
htmlHeight={500}
|
||||
display={overlay('block', 'none')}
|
||||
/>
|
||||
<Image
|
||||
src={logoLight}
|
||||
alt="Andrea Slop Fotografie"
|
||||
alt=""
|
||||
htmlWidth={500}
|
||||
htmlHeight={500}
|
||||
display={overlay('none', 'block')}
|
||||
/>
|
||||
</Box>
|
||||
</RouterLink>
|
||||
<chakra.nav
|
||||
aria-label="Hoofdmenu"
|
||||
flexBasis="100%"
|
||||
@@ -109,7 +118,7 @@ export default function NavigationBar() {
|
||||
// Op mobiel staan de links in het hamburgermenu
|
||||
display={{ base: 'none', lg: 'flex' }}
|
||||
>
|
||||
{navItems.map((item) => (
|
||||
{mainNav.map((item) => (
|
||||
<chakra.li key={item.to}>
|
||||
<NavLink to={item.to}>
|
||||
{item.label}
|
||||
@@ -135,15 +144,17 @@ export default function NavigationBar() {
|
||||
data-open={menuOpen || undefined}
|
||||
// Op desktop opent deze knop straks het info-menu (side area)
|
||||
display={{ base: 'block', lg: 'none' }}
|
||||
data-testid="nav-menu-toggle"
|
||||
position="relative"
|
||||
w="32px"
|
||||
h="32px"
|
||||
// 44px: minimaal klikdoel op touch (BR-RWD-04)
|
||||
w="44px"
|
||||
h="44px"
|
||||
cursor="pointer"
|
||||
zIndex="modal"
|
||||
zIndex="menuToggle"
|
||||
css={{
|
||||
'& > span': {
|
||||
position: 'absolute',
|
||||
left: '4px',
|
||||
left: '10px',
|
||||
width: '24px',
|
||||
height: '2px',
|
||||
bg: 'currentColor',
|
||||
@@ -151,22 +162,22 @@ export default function NavigationBar() {
|
||||
transition:
|
||||
'transform 0.3s ease, opacity 0.2s ease, top 0.3s ease',
|
||||
},
|
||||
'& > span:nth-of-type(1)': { top: '9px' },
|
||||
'& > span:nth-of-type(2)': { top: '15px' },
|
||||
'& > span:nth-of-type(3)': { top: '21px' },
|
||||
'& > span:nth-of-type(1)': { top: '15px' },
|
||||
'& > span:nth-of-type(2)': { top: '21px' },
|
||||
'& > span:nth-of-type(3)': { top: '27px' },
|
||||
|
||||
// open kruisje
|
||||
'&[data-open] > span:nth-of-type(1)': {
|
||||
top: '15px',
|
||||
top: '21px',
|
||||
transform: 'rotate(45deg)',
|
||||
},
|
||||
'&[data-open] > span:nth-of-type(2)': {
|
||||
opacity: 0,
|
||||
top: '15px',
|
||||
top: '21px',
|
||||
transform: 'rotate(45deg)',
|
||||
},
|
||||
'&[data-open] > span:nth-of-type(3)': {
|
||||
top: '15px',
|
||||
top: '21px',
|
||||
transform: 'rotate(-45deg)',
|
||||
},
|
||||
}}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// Menu-items, gedeeld door de desktopnavigatie en het mobiele menu
|
||||
const navItems = [
|
||||
{ to: '/', label: 'Home' },
|
||||
{ to: '/over-mij', label: 'Over mij' },
|
||||
] as const;
|
||||
|
||||
export default navItems;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import PageIntro from './PageIntro';
|
||||
|
||||
describe('PageIntro', () => {
|
||||
it('toont label, de enige h1 en de intro', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<PageIntro eyebrow="Werk" title="Portfolio">
|
||||
Deze pagina is nog in de maak.
|
||||
</PageIntro>,
|
||||
);
|
||||
expect(screen.getAllByRole('heading', { level: 1 })).toHaveLength(1);
|
||||
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
||||
'Portfolio',
|
||||
);
|
||||
expect(screen.getByText('Werk')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Deze pagina is nog in de maak.'),
|
||||
).toBeInTheDocument();
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('werkt zonder label en intro', async () => {
|
||||
await renderWithProviders(<PageIntro title="Contact" />);
|
||||
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
||||
'Contact',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Container, Heading, Text } from '@chakra-ui/react';
|
||||
|
||||
type PageIntroProps = {
|
||||
title: string;
|
||||
eyebrow?: string;
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
// Bovenste blok van een gewone pagina (.page-head in het design): label,
|
||||
// de enige h1 van de pagina en een korte intro
|
||||
export default function PageIntro({
|
||||
title,
|
||||
eyebrow,
|
||||
children,
|
||||
}: PageIntroProps) {
|
||||
return (
|
||||
<Container
|
||||
as="section"
|
||||
pt="pageTop"
|
||||
pb={{ base: 8, md: 12, lg: 16 }}
|
||||
textAlign="center"
|
||||
>
|
||||
{eyebrow && (
|
||||
// accent.deep i.p.v. accent uit het design: haalt 4.5:1 (NFR-01)
|
||||
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
|
||||
{eyebrow}
|
||||
</Text>
|
||||
)}
|
||||
<Heading as="h1" textStyle="pageTitle" mb={4}>
|
||||
{title}
|
||||
</Heading>
|
||||
{children && (
|
||||
<Text color="ink.soft" maxW="680px" mx="auto">
|
||||
{children}
|
||||
</Text>
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { chakra } from '@chakra-ui/react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
|
||||
// De router-link met Chakra-styleprops. Eén gedeelde versie, zodat niet elk
|
||||
// component zijn eigen chakra(Link) maakt.
|
||||
const RouterLink = chakra(Link);
|
||||
|
||||
export default RouterLink;
|
||||
@@ -0,0 +1,55 @@
|
||||
import { useEffect } from 'react';
|
||||
import { chakra, useRecipe } from '@chakra-ui/react';
|
||||
import { useRouter, type ErrorComponentProps } from '@tanstack/react-router';
|
||||
import LinkButton from '../LinkButton';
|
||||
import StatusPage from './StatusPage';
|
||||
|
||||
// Algemene foutpagina (FR-10). Toont nooit de foutmelding zelf; die gaat
|
||||
// alleen naar de console (BR-ERR-02/03).
|
||||
export default function ErrorPage({ error, reset }: ErrorComponentProps) {
|
||||
const router = useRouter();
|
||||
const buttonRecipe = useRecipe({ key: 'linkButton' });
|
||||
|
||||
useEffect(() => {
|
||||
console.error(error);
|
||||
}, [error]);
|
||||
|
||||
// Foutgrens resetten en de route opnieuw laden (BR-ERR-04)
|
||||
const retry = () => {
|
||||
reset();
|
||||
router.invalidate();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<title>Er ging iets mis | Andrea Slop Fotografie</title>
|
||||
<meta name="robots" content="noindex" />
|
||||
<StatusPage
|
||||
title="Er ging iets mis"
|
||||
actions={
|
||||
<>
|
||||
<chakra.button
|
||||
type="button"
|
||||
onClick={retry}
|
||||
css={buttonRecipe({ variant: 'accent' })}
|
||||
cursor="pointer"
|
||||
data-testid="error-page-retry-button"
|
||||
>
|
||||
Opnieuw proberen
|
||||
</chakra.button>
|
||||
<LinkButton
|
||||
to="/"
|
||||
variant="outline"
|
||||
data-testid="error-page-home-link"
|
||||
>
|
||||
Terug naar home
|
||||
</LinkButton>
|
||||
</>
|
||||
}
|
||||
>
|
||||
Door een fout kan deze pagina nu niet worden getoond. Probeer
|
||||
het opnieuw of ga terug naar de homepage.
|
||||
</StatusPage>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import StatusPage from './StatusPage';
|
||||
|
||||
// Pagina voor een onbekende URL, binnen de shell (FR-09). Een globale
|
||||
// not-found heeft geen eigen route-head; React 19 zet <title> en <meta>
|
||||
// daarom zelf in <head> en haalt ze weer weg bij het verlaten (BR-404-02).
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<>
|
||||
<title>Pagina niet gevonden | Andrea Slop Fotografie</title>
|
||||
<meta name="robots" content="noindex" />
|
||||
<StatusPage title="Pagina niet gevonden">
|
||||
Deze pagina bestaat niet (meer). Misschien is de link verouderd
|
||||
of zit er een typfout in het adres.
|
||||
</StatusPage>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import ErrorPage from './ErrorPage';
|
||||
import NotFound from './NotFound';
|
||||
|
||||
describe('NotFound', () => {
|
||||
it('toont de 404-tekst met een link naar home', async () => {
|
||||
const { container } = await renderWithProviders(<NotFound />, {
|
||||
path: '/bestaat-niet',
|
||||
});
|
||||
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
||||
'Pagina niet gevonden',
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'Terug naar home' }),
|
||||
).toHaveAttribute('href', '/');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('zet een eigen titel en noindex in de head', async () => {
|
||||
await renderWithProviders(<NotFound />, { path: '/bestaat-niet' });
|
||||
expect(document.title).toBe(
|
||||
'Pagina niet gevonden | Andrea Slop Fotografie',
|
||||
);
|
||||
expect(
|
||||
document.head.querySelector('meta[name="robots"]'),
|
||||
).toHaveAttribute('content', 'noindex');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ErrorPage', () => {
|
||||
const error = new Error('Geheime interne fout in de database');
|
||||
|
||||
const renderError = async () => {
|
||||
const reset = vi.fn();
|
||||
const consoleError = vi
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
const result = await renderWithProviders(
|
||||
<ErrorPage error={error} reset={reset} />,
|
||||
);
|
||||
return { ...result, reset, consoleError };
|
||||
};
|
||||
|
||||
it('toont een algemene melding zonder foutdetails', async () => {
|
||||
const { container } = await renderError();
|
||||
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
||||
'Er ging iets mis',
|
||||
);
|
||||
expect(container).not.toHaveTextContent('Geheime interne fout');
|
||||
expect(container.innerHTML).not.toContain('database');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('logt de fout precies een keer', async () => {
|
||||
const { consoleError } = await renderError();
|
||||
expect(consoleError).toHaveBeenCalledTimes(1);
|
||||
expect(consoleError).toHaveBeenCalledWith(error);
|
||||
});
|
||||
|
||||
it('opnieuw proberen reset de foutgrens en laadt de route opnieuw', async () => {
|
||||
const { reset, router } = await renderError();
|
||||
const invalidate = vi.spyOn(router, 'invalidate');
|
||||
await userEvent.click(
|
||||
screen.getByRole('button', { name: 'Opnieuw proberen' }),
|
||||
);
|
||||
expect(reset).toHaveBeenCalledTimes(1);
|
||||
expect(invalidate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('biedt een link naar home en zet noindex', async () => {
|
||||
await renderError();
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'Terug naar home' }),
|
||||
).toHaveAttribute('href', '/');
|
||||
expect(document.title).toBe(
|
||||
'Er ging iets mis | Andrea Slop Fotografie',
|
||||
);
|
||||
expect(
|
||||
document.head.querySelector('meta[name="robots"]'),
|
||||
).toHaveAttribute('content', 'noindex');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Container, Flex, Heading, Text } from '@chakra-ui/react';
|
||||
import LinkButton from '../LinkButton';
|
||||
|
||||
type StatusPageProps = {
|
||||
title: string;
|
||||
children: ReactNode;
|
||||
// Standaard één knop terug naar home
|
||||
actions?: ReactNode;
|
||||
};
|
||||
|
||||
// Gedeelde opmaak van de 404- en de foutpagina
|
||||
export default function StatusPage({
|
||||
title,
|
||||
children,
|
||||
actions,
|
||||
}: StatusPageProps) {
|
||||
return (
|
||||
<Container
|
||||
as="section"
|
||||
maxW="2xl"
|
||||
pt="pageTop"
|
||||
pb={{ base: 16, md: 24 }}
|
||||
textAlign="center"
|
||||
>
|
||||
<Heading as="h1" textStyle="pageTitle" mb={4}>
|
||||
{title}
|
||||
</Heading>
|
||||
<Text color="ink.soft" mb={8}>
|
||||
{children}
|
||||
</Text>
|
||||
<Flex gap={4} justifyContent="center" wrap="wrap">
|
||||
{actions ?? (
|
||||
<LinkButton to="/" data-testid="status-page-home-link">
|
||||
Terug naar home
|
||||
</LinkButton>
|
||||
)}
|
||||
</Flex>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user