Shows the Lifestyle fotografie photos as a swipeable row on phones
Four stacked photos were too much on a phone screen. Below the small breakpoint the gallery is now a scroll-snap row with one photo at a time and the next one peeking in; tablets and desktops keep the grid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,4 +50,22 @@ describe('DeferredImage', () => {
|
||||
});
|
||||
expect(img).toHaveAttribute('src', '/foto.jpg');
|
||||
});
|
||||
|
||||
it('follows the near prop from a parent instead of observing itself', async () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
const { unmount } = await renderWithProviders(
|
||||
<DeferredImage image={image} near={false} />,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('img', { name: 'Een foto' }),
|
||||
).not.toHaveAttribute('src');
|
||||
unmount();
|
||||
|
||||
await renderWithProviders(<DeferredImage image={image} near />);
|
||||
expect(screen.getByRole('img', { name: 'Een foto' })).toHaveAttribute(
|
||||
'src',
|
||||
'/foto.jpg',
|
||||
);
|
||||
expect(FakeIntersectionObserver.instances).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,9 @@ const LOAD_MARGIN = '600px 0px';
|
||||
|
||||
type DeferredImageProps = Omit<ImageProps, 'src' | 'alt'> & {
|
||||
image: ContentImage;
|
||||
// Set by a parent that knows better, e.g. a horizontal scroller whose
|
||||
// off-screen items are clipped and would never intersect on their own
|
||||
near?: boolean;
|
||||
};
|
||||
|
||||
// A below-the-fold image that only starts downloading once the page has
|
||||
@@ -16,16 +19,22 @@ type DeferredImageProps = Omit<ImageProps, 'src' | 'alt'> & {
|
||||
// below the screen straight away, so photos right under the hero compete
|
||||
// with it for bandwidth and delay the largest contentful paint.
|
||||
// Width and height reserve the space, so nothing shifts when it loads.
|
||||
export default function DeferredImage({ image, ...rest }: DeferredImageProps) {
|
||||
export default function DeferredImage({
|
||||
image,
|
||||
near,
|
||||
...rest
|
||||
}: DeferredImageProps) {
|
||||
const pageLoaded = usePageLoaded();
|
||||
const { ref, inView } = useInView<HTMLImageElement>({
|
||||
rootMargin: LOAD_MARGIN,
|
||||
skip: near !== undefined,
|
||||
});
|
||||
const load = pageLoaded && (near ?? inView);
|
||||
|
||||
return (
|
||||
<Image
|
||||
ref={ref}
|
||||
src={pageLoaded && inView ? image.src : undefined}
|
||||
src={load ? image.src : undefined}
|
||||
alt={image.alt}
|
||||
htmlWidth={image.width}
|
||||
htmlHeight={image.height}
|
||||
|
||||
Reference in New Issue
Block a user