11'use client' ;
22import { tcls } from '@/lib/tailwind' ;
33import type { ImageSize } from '../utils' ;
4- import { getRecommendedCoverDimensions } from './coverDimensions' ;
54import { useCoverPosition } from './useCoverPosition' ;
65
76interface ImageAttributes {
@@ -18,14 +17,15 @@ interface Images {
1817 dark ?: ImageAttributes ;
1918}
2019
21- export function PageCoverImage ( { imgs, y, height } : { imgs : Images ; y : number ; height : number } ) {
22- const { containerRef, objectPositionY, isLoading } = useCoverPosition ( imgs , y ) ;
20+ const PAGE_COVER_SIZE : ImageSize = { width : 1990 , height : 480 } ;
2321
24- // Calculate the recommended aspect ratio for this height
25- // This maintains the 4:1 ratio, allowing images to scale proportionally
26- // and adapt their height when container width doesn't match the ideal ratio
27- const recommendedDimensions = getRecommendedCoverDimensions ( height ) ;
28- const aspectRatio = recommendedDimensions . width / recommendedDimensions . height ;
22+ export function PageCoverImage ( {
23+ imgs,
24+ y,
25+ height,
26+ coverType,
27+ } : { imgs : Images ; y : number ; height : number ; coverType : 'hero' | 'full' } ) {
28+ const { containerRef, objectPositionY, isLoading } = useCoverPosition ( imgs , y ) ;
2929
3030 if ( isLoading ) {
3131 return (
@@ -36,17 +36,23 @@ export function PageCoverImage({ imgs, y, height }: { imgs: Images; y: number; h
3636 }
3737
3838 return (
39- < div className = "h-full w-full overflow-hidden" ref = { containerRef } style = { { height } } >
39+ < div className = "h-full w-full overflow-hidden" ref = { containerRef } >
4040 < img
4141 src = { imgs . light . src }
4242 srcSet = { imgs . light . srcSet }
4343 sizes = { imgs . light . sizes }
4444 fetchPriority = "high"
4545 alt = "Page cover"
46- className = { tcls ( 'w-full' , 'object-cover' , imgs . dark ? 'dark:hidden' : '' ) }
46+ className = { tcls (
47+ 'w-full' ,
48+ coverType === 'hero' ? 'object-contain' : 'object-cover' ,
49+ imgs . dark ? 'dark:hidden' : ''
50+ ) }
4751 style = { {
48- aspectRatio : `${ aspectRatio } ` ,
52+ aspectRatio :
53+ coverType === 'hero' ? `${ height } /${ PAGE_COVER_SIZE . height } ` : undefined ,
4954 objectPosition : `50% ${ objectPositionY } %` ,
55+ height : coverType === 'full' ? `${ height } px` : undefined ,
5056 } }
5157 />
5258 { imgs . dark && (
@@ -58,7 +64,7 @@ export function PageCoverImage({ imgs, y, height }: { imgs: Images; y: number; h
5864 alt = "Page cover"
5965 className = { tcls ( 'w-full' , 'object-cover' , 'dark:inline' , 'hidden' ) }
6066 style = { {
61- aspectRatio : `${ aspectRatio } ` ,
67+ aspectRatio : `${ PAGE_COVER_SIZE . width } / ${ PAGE_COVER_SIZE . height } ` ,
6268 objectPosition : `50% ${ objectPositionY } %` ,
6369 } }
6470 />
0 commit comments