File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed
examples/next/faustwp-getting-started/components/FeaturedImage Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -10,25 +10,33 @@ export default function FeaturedImage({
1010 ...props
1111} ) {
1212 const src = image ?. sourceUrl ;
13- const { altText } = image || '' ;
1413
15- width = width ? width : image ?. mediaDetails ?. width ;
16- height = height ? height : image ?. mediaDetails ?. height ;
14+ if ( ! src ) return null ;
15+
16+ const { altText = '' , mediaDetails = { } } = image ?? { } ;
17+
1718 layout = layout ?? 'fill' ;
1819
19- return src && width && height ? (
20+ const dimensions = {
21+ width : layout === 'fill' ? undefined : width ?? mediaDetails ?. width ,
22+ height : layout === 'fill' ? undefined : height ?? mediaDetails ?. height
23+ } ;
24+
25+ if ( layout !== 'fill' && ( ! dimensions . width || ! dimensions . height ) ) return null ;
26+
27+ return (
2028 < figure className = { className } >
2129 < Image
2230 src = { src }
2331 alt = { altText }
24- layout = { layout }
25- width = { width }
26- height = { height }
32+ fill = { layout }
33+ width = { dimensions . width }
34+ height = { dimensions . height }
2735 priority = { priority }
2836 { ...props }
2937 />
3038 </ figure >
31- ) : null ;
39+ ) ;
3240}
3341
3442FeaturedImage . fragments = {
You can’t perform that action at this time.
0 commit comments