Skip to content

Commit 598f4c2

Browse files
committed
🎨 layout shift on news image
1 parent bd012ad commit 598f4c2

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

web/core/Picture/Picture.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use client'
12
import type { SanityImageObject } from '@sanity/image-url'
23
import type { ImageProps } from 'next/image'
34
import { forwardRef } from 'react'
@@ -20,6 +21,11 @@ type PictureProps = {
2021
*/
2122
mobileAspectRatio?: ImageRatioKeys
2223
figCaptionClassName?: string
24+
figureClassName?: string
25+
/** if figure caption should have the default px layouts
26+
* @default true
27+
*/
28+
withLayoutPx?: boolean
2329
} & Omit<ImageProps, 'src' | 'alt'>
2430

2531
export const Picture = forwardRef<HTMLElement, PictureProps>(function Picture(
@@ -30,7 +36,9 @@ export const Picture = forwardRef<HTMLElement, PictureProps>(function Picture(
3036
caption,
3137
attribution,
3238
className = '',
39+
figureClassName = '',
3340
figCaptionClassName = '',
41+
withLayoutPx = true,
3442
},
3543
ref,
3644
) {
@@ -47,16 +55,6 @@ export const Picture = forwardRef<HTMLElement, PictureProps>(function Picture(
4755
})
4856
console.log('desktopUrl', desktopUrl)
4957

50-
// Get props for the desktop image source
51-
/* const {
52-
props: { srcSet: desktopSrcSet },
53-
} = getImageProps({
54-
alt: 'alt' in image && image.alt ? image.alt : '',
55-
width,
56-
height,
57-
src: desktopUrl as string,
58-
}) */
59-
6058
const pictureElement = (
6159
<picture ref={ref} className={twMerge(`relative h-full w-full`, className)}>
6260
<source media='(min-width: 768px)' srcSet={desktopUrl} />
@@ -73,10 +71,10 @@ export const Picture = forwardRef<HTMLElement, PictureProps>(function Picture(
7371
)
7472

7573
return caption || attribution ? (
76-
<figure>
74+
<figure className={figureClassName}>
7775
{pictureElement}
7876
<FigureCaption
79-
withLayoutPx
77+
withLayoutPx={withLayoutPx}
8078
className={figCaptionClassName}
8179
caption={caption}
8280
attribution={attribution}

web/sections/Hero/DefaultHero.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
'use client'
12
import type { PortableTextBlock } from '@portabletext/types'
23
import type { HTMLAttributes, ReactNode } from 'react'
3-
import { Image, type ImageRatioKeys } from '@/core/Image/Image'
4+
import type { ImageRatioKeys } from '@/core/Image/Image'
5+
import { Picture } from '@/core/Picture/Picture'
46
import { Typography } from '@/core/Typography'
57
import { twMerge } from '@/lib/twMerge/twMerge'
68
import Blocks from '@/portableText/Blocks'
@@ -85,7 +87,19 @@ export const DefaultHero = ({
8587
</div>
8688
</div>
8789
{figure && (
88-
<Image
90+
<Picture
91+
image={figure.image}
92+
desktopAspectRatio={ratio}
93+
figCaptionClassName={figCaptionClassName}
94+
caption={figure?.caption}
95+
attribution={figure?.attribution}
96+
figureClassName={twMerge(
97+
`${isColorBg ? 'lg:-mt-news-banner-vertical' : ''} lg:px-layout-md`,
98+
imageWrapperClassName,
99+
)}
100+
withLayoutPx={false}
101+
/>
102+
/* <Image
89103
grid='sm'
90104
loading='eager'
91105
className={twMerge(
@@ -98,7 +112,7 @@ export const DefaultHero = ({
98112
attribution={figure.attribution}
99113
imageClassName={twMerge(``, imageClassName)}
100114
figCaptionClassName={figCaptionClassName}
101-
/>
115+
/> */
102116
)}
103117
{magazineTags && magazineTags?.length > 0 && (
104118
<MagazineTagBar tags={magazineTags} />

web/templates/news/News.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const NewsPage = async ({
107107
ratio='21:9'
108108
subTitle={publishedInformation}
109109
imageWrapperClassName='lg:px-layout-md'
110-
figCaptionClassName='light px-layout-sm lg:px-layout-lg'
110+
figCaptionClassName='light'
111111
/>
112112
{ingress && ingress.length > 0 && (
113113
<Blocks

0 commit comments

Comments
 (0)