Adds the Over mij section to the homepage
Adds the introduction block with a framed photo of Andrea and a link to the about page. Brings in FramedImage and an underline link variant for the later blocks, and narrows the load margin of deferred photos so nothing below the hero starts loading before the hero has painted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,6 +129,9 @@ describe('homepage', () => {
|
||||
});
|
||||
const sections = [
|
||||
screen.getByRole('region', { name: 'Lifestyle fotografie' }),
|
||||
screen.getByRole('region', {
|
||||
name: 'Lifestyle fotograaf met een passie voor storytelling',
|
||||
}),
|
||||
];
|
||||
|
||||
let previous: Element = hero;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
@@ -2,7 +2,7 @@ import { act, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import DeferredImage from './DeferredImage';
|
||||
import DeferredImage, { DEFERRED_LOAD_MARGIN } from './DeferredImage';
|
||||
|
||||
const image = {
|
||||
src: '/foto.jpg',
|
||||
@@ -33,7 +33,7 @@ describe('DeferredImage', () => {
|
||||
const [observer] = FakeIntersectionObserver.instances;
|
||||
|
||||
expect(img).not.toHaveAttribute('src');
|
||||
expect(observer.options?.rootMargin).toBe('600px 0px');
|
||||
expect(observer.options?.rootMargin).toBe(DEFERRED_LOAD_MARGIN);
|
||||
|
||||
act(() => observer.trigger(true));
|
||||
expect(img).toHaveAttribute('src', '/foto.jpg');
|
||||
|
||||
@@ -3,8 +3,12 @@ import usePageLoaded from '@/hooks/usePageLoaded';
|
||||
import useInView from '@/hooks/useInView';
|
||||
import type { ContentImage } from '@/content/types';
|
||||
|
||||
// How far below the viewport an image starts loading
|
||||
const LOAD_MARGIN = '600px 0px';
|
||||
// How far outside the viewport an image starts loading. Kept small on
|
||||
// purpose: everything below the full-height hero must be out of range when
|
||||
// the page opens, or its photos start before the hero has painted. In
|
||||
// Lighthouse's throttled simulation that pushed the largest contentful
|
||||
// paint from 3.8 s to 5.3 s whenever the request won the race.
|
||||
export const DEFERRED_LOAD_MARGIN = '200px 0px';
|
||||
|
||||
type DeferredImageProps = Omit<ImageProps, 'src' | 'alt'> & {
|
||||
image: ContentImage;
|
||||
@@ -26,7 +30,7 @@ export default function DeferredImage({
|
||||
}: DeferredImageProps) {
|
||||
const pageLoaded = usePageLoaded();
|
||||
const { ref, inView } = useInView<HTMLImageElement>({
|
||||
rootMargin: LOAD_MARGIN,
|
||||
rootMargin: DEFERRED_LOAD_MARGIN,
|
||||
skip: near !== undefined,
|
||||
});
|
||||
const load = pageLoaded && (near ?? inView);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import FramedImage from './FramedImage';
|
||||
|
||||
const image = {
|
||||
src: '/andrea.jpg',
|
||||
alt: 'Andrea met haar camera',
|
||||
width: 1200,
|
||||
height: 800,
|
||||
};
|
||||
|
||||
describe('FramedImage', () => {
|
||||
it('renders only the photo for assistive technology, with its size', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<FramedImage image={image} aspectRatio="4 / 3" />,
|
||||
);
|
||||
const img = screen.getByRole('img');
|
||||
expect(img).toHaveAccessibleName('Andrea met haar camera');
|
||||
expect(img).toHaveAttribute('src', '/andrea.jpg');
|
||||
expect(img).toHaveAttribute('width', '1200');
|
||||
expect(img).toHaveAttribute('height', '800');
|
||||
expect(img).toHaveAttribute('loading', 'lazy');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Box } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import type { ContentImage } from '@/content/types';
|
||||
|
||||
type FramedImageProps = {
|
||||
image: ContentImage;
|
||||
// CSS aspect ratio of the visible crop, e.g. '4 / 3'
|
||||
aspectRatio: string;
|
||||
};
|
||||
|
||||
// A photo with a soft sand-coloured block offset behind its lower left
|
||||
// corner (design .about__media). The block is pure decoration (a CSS
|
||||
// pseudo-element), so assistive technology never announces it. On phones it
|
||||
// is left out, since it would stick out past the page edge.
|
||||
export default function FramedImage({ image, aspectRatio }: FramedImageProps) {
|
||||
return (
|
||||
<Box
|
||||
position="relative"
|
||||
// Own stacking context, so the block can sit behind the photo
|
||||
isolation="isolate"
|
||||
_before={{
|
||||
content: '""',
|
||||
display: { base: 'none', sm: 'block' },
|
||||
position: 'absolute',
|
||||
left: '-1.5rem',
|
||||
bottom: '-1.5rem',
|
||||
width: '55%',
|
||||
height: '55%',
|
||||
bg: 'sand',
|
||||
zIndex: -1,
|
||||
}}
|
||||
>
|
||||
<DeferredImage
|
||||
image={image}
|
||||
display="block"
|
||||
w="100%"
|
||||
h="auto"
|
||||
aspectRatio={aspectRatio}
|
||||
objectFit="cover"
|
||||
// Shown until the deferred photo arrives
|
||||
bg="paper.deep"
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -31,4 +31,23 @@ describe('SectionHeading', () => {
|
||||
).toBeInTheDocument();
|
||||
expect(container.querySelectorAll('p')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('supports a compact, start-aligned variant above running text', async () => {
|
||||
await renderWithProviders(
|
||||
<SectionHeading
|
||||
id="about-title"
|
||||
eyebrow="Over mij"
|
||||
title="Lifestyle fotograaf"
|
||||
align="start"
|
||||
spacing="compact"
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('heading', {
|
||||
level: 2,
|
||||
name: 'Lifestyle fotograaf',
|
||||
}),
|
||||
).toHaveAttribute('id', 'about-title');
|
||||
expect(screen.getByText('Over mij')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,8 @@ type SectionHeadingProps = {
|
||||
eyebrow?: string;
|
||||
lead?: string;
|
||||
align?: 'center' | 'start';
|
||||
// compact: little space below, for a heading above running text
|
||||
spacing?: 'default' | 'compact';
|
||||
};
|
||||
|
||||
// Heading block of a homepage section (design .section__head): optional
|
||||
@@ -17,6 +19,7 @@ export default function SectionHeading({
|
||||
eyebrow,
|
||||
lead,
|
||||
align = 'center',
|
||||
spacing = 'default',
|
||||
}: SectionHeadingProps) {
|
||||
const centered = align === 'center';
|
||||
|
||||
@@ -24,7 +27,7 @@ export default function SectionHeading({
|
||||
<Box
|
||||
maxW="620px"
|
||||
mx={centered ? 'auto' : undefined}
|
||||
mb="sectionHeadGap"
|
||||
mb={spacing === 'compact' ? 6 : 'sectionHeadGap'}
|
||||
textAlign={centered ? 'center' : 'start'}
|
||||
>
|
||||
{eyebrow && (
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import homeContent from '@/content/homeContent';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import AboutBlock from './AboutBlock';
|
||||
|
||||
const about = homeContent.about;
|
||||
|
||||
describe('AboutBlock', () => {
|
||||
it('shows the label, heading, text, photo and link', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<AboutBlock content={about} />,
|
||||
);
|
||||
const section = screen.getByRole('region', { name: about.title });
|
||||
expect(
|
||||
within(section).getByRole('heading', { level: 2 }),
|
||||
).toHaveTextContent(about.title);
|
||||
expect(within(section).getByText(about.eyebrow)).toBeInTheDocument();
|
||||
about.paragraphs.forEach((paragraph) =>
|
||||
expect(within(section).getByText(paragraph)).toBeInTheDocument(),
|
||||
);
|
||||
expect(within(section).getByRole('img')).toHaveAccessibleName(
|
||||
about.image.alt,
|
||||
);
|
||||
expect(
|
||||
within(section).getByRole('link', { name: about.link.label }),
|
||||
).toHaveAttribute('href', '/over-mij');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Grid, Link, Stack, Text } from '@chakra-ui/react';
|
||||
import FramedImage from '@/components/FramedImage/FramedImage';
|
||||
import HomeSection from '@/components/HomeSection/HomeSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import RouterLink from '@/components/RouterLink';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
import type { HomeContent } from '@/content/types';
|
||||
|
||||
const TITLE_ID = 'about-title';
|
||||
|
||||
type AboutBlockProps = {
|
||||
content: HomeContent['about'];
|
||||
};
|
||||
|
||||
// "Over mij": a framed photo of Andrea next to a short introduction with a
|
||||
// link to the about page (design .about). Stacked on phones and tablets.
|
||||
export default function AboutBlock({ content }: AboutBlockProps) {
|
||||
return (
|
||||
<HomeSection labelledBy={TITLE_ID} tone="alt" data-testid="about-block">
|
||||
<Grid
|
||||
templateColumns={{ base: '1fr', lg: '1fr 1fr' }}
|
||||
gap="clamp(2rem, 6vw, 5.5rem)"
|
||||
alignItems="center"
|
||||
>
|
||||
<Reveal>
|
||||
<FramedImage image={content.image} aspectRatio="4 / 3" />
|
||||
</Reveal>
|
||||
<Reveal>
|
||||
<SectionHeading
|
||||
id={TITLE_ID}
|
||||
eyebrow={content.eyebrow}
|
||||
title={content.title}
|
||||
align="start"
|
||||
spacing="compact"
|
||||
/>
|
||||
<Stack gap={4} color="ink.soft">
|
||||
{content.paragraphs.map((paragraph) => (
|
||||
<Text key={paragraph}>{paragraph}</Text>
|
||||
))}
|
||||
<Text>
|
||||
<Link variant="underline" asChild>
|
||||
<RouterLink
|
||||
to={content.link.to}
|
||||
data-testid="about-block-link"
|
||||
>
|
||||
{content.link.label}
|
||||
</RouterLink>
|
||||
</Link>
|
||||
</Text>
|
||||
</Stack>
|
||||
</Reveal>
|
||||
</Grid>
|
||||
</HomeSection>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { chakra, useBreakpointValue } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import DeferredImage, {
|
||||
DEFERRED_LOAD_MARGIN,
|
||||
} from '@/components/DeferredImage/DeferredImage';
|
||||
import HomeSection from '@/components/HomeSection/HomeSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
@@ -24,7 +26,7 @@ export default function IntroGallery({ content }: IntroGalleryProps) {
|
||||
// Photos outside the row are clipped by the scroller and never intersect
|
||||
// on their own, so the whole gallery decides when they load.
|
||||
const { ref, inView } = useInView<HTMLUListElement>({
|
||||
rootMargin: '600px 0px',
|
||||
rootMargin: DEFERRED_LOAD_MARGIN,
|
||||
});
|
||||
// Only the swipeable row scrolls, so only then is it a focus stop for
|
||||
// keyboard scrolling
|
||||
|
||||
@@ -5,6 +5,7 @@ import intro1 from '../assets/home/intro-1.jpg';
|
||||
import intro2 from '../assets/home/intro-2.jpg';
|
||||
import intro3 from '../assets/home/intro-3.jpg';
|
||||
import intro4 from '../assets/home/intro-4.jpg';
|
||||
import andrea from '../assets/home/andrea.jpg';
|
||||
|
||||
// Static content of the homepage sections until the CMS API exists; the API
|
||||
// will then deliver this object.
|
||||
@@ -39,6 +40,22 @@ const homeContent: HomeContent = {
|
||||
},
|
||||
],
|
||||
},
|
||||
about: {
|
||||
eyebrow: 'Over mij',
|
||||
title: 'Lifestyle fotograaf met een passie voor storytelling',
|
||||
paragraphs: [
|
||||
'Hi! Ik ben Andrea, lifestyle fotograaf uit Huizen. Leuk dat je een kijkje neemt op mijn website!',
|
||||
"Foto's vertellen verhalen. Ze brengen je terug naar je favoriete momenten. Met mijn camera leg ik momenten vast die je voor altijd bij je houdt.",
|
||||
'Mijn stijl is natuurlijk en ongedwongen. Ik leg jullie vast zoals jullie zijn. Geen ongemakkelijke poses maar spontane momenten.',
|
||||
],
|
||||
image: {
|
||||
src: andrea,
|
||||
alt: 'Andrea Slop met haar camera, glimlachend over haar schouder',
|
||||
width: 1200,
|
||||
height: 800,
|
||||
},
|
||||
link: { label: 'Lees mijn verhaal', to: '/over-mij' },
|
||||
},
|
||||
};
|
||||
|
||||
export default homeContent;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { RoutePath } from '../navigation.ts';
|
||||
import type { SocialPlatform } from './socialPlatforms.ts';
|
||||
|
||||
// Vorm van de content die straks uit de CMS-API komt. Bewust platte data
|
||||
@@ -37,6 +38,14 @@ export interface HomeContent {
|
||||
lead: string;
|
||||
photos: ContentImage[];
|
||||
};
|
||||
about: {
|
||||
eyebrow: string;
|
||||
title: string;
|
||||
paragraphs: string[];
|
||||
image: ContentImage;
|
||||
// A route, so a wrong link is a type error
|
||||
link: { label: string; to: RoutePath };
|
||||
};
|
||||
}
|
||||
|
||||
export interface HeroSlide {
|
||||
|
||||
@@ -17,6 +17,37 @@ const linkRecipe = defineRecipe({
|
||||
_hover: { color: 'accent.deep' },
|
||||
_focusVisible: { color: 'accent.deep' },
|
||||
},
|
||||
// Ink text with an underline that slides in from the left on
|
||||
// hover and focus (design .link-underline)
|
||||
underline: {
|
||||
position: 'relative',
|
||||
display: 'inline-block',
|
||||
color: 'ink',
|
||||
textDecoration: 'none',
|
||||
rounded: 'none',
|
||||
_after: {
|
||||
content: '""',
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
bottom: '-2px',
|
||||
width: '100%',
|
||||
height: '1px',
|
||||
bg: 'currentColor',
|
||||
transform: 'scaleX(0)',
|
||||
transformOrigin: 'right',
|
||||
transitionProperty: 'transform',
|
||||
transitionDuration: 'interaction',
|
||||
transitionTimingFunction: 'smooth',
|
||||
_motionReduce: { transition: 'none' },
|
||||
},
|
||||
_hover: {
|
||||
textDecoration: 'none',
|
||||
_after: { transform: 'scaleX(1)', transformOrigin: 'left' },
|
||||
},
|
||||
_focusVisible: {
|
||||
_after: { transform: 'scaleX(1)', transformOrigin: 'left' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import Hero from '../components/Hero/Hero';
|
||||
import AboutBlock from '../components/home/AboutBlock/AboutBlock';
|
||||
import IntroGallery from '../components/home/IntroGallery/IntroGallery';
|
||||
import heroContent from '../content/heroContent';
|
||||
import homeContent from '../content/homeContent';
|
||||
@@ -17,6 +18,7 @@ function Index() {
|
||||
<>
|
||||
<Hero content={heroContent} socials={siteContent.socials} />
|
||||
<IntroGallery content={homeContent.intro} />
|
||||
<AboutBlock content={homeContent.about} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user