Skip to content

Commit

Permalink
feat: rendering of additional di params
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmistryamplience committed Nov 27, 2023
1 parent feba7dd commit c96d098
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
9 changes: 6 additions & 3 deletions components/cms-modern/AdaptiveImage/AdaptiveImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export interface AdaptiveImageProps extends React.DetailedHTMLProps<React.ImgHTM
imageRef?:any;
children?: React.ReactElement[];
imageAltText?: string;
diParams?:string;
}

type ContextState = {
image: CmsImage;
transformations?: ImageTransformations;

diParams?: string;
srcset?: {
[factor: string]: ImageTransformations
}
Expand All @@ -25,6 +26,7 @@ const AdaptiveImage: React.SFC<AdaptiveImageProps> = (props) => {
image,
imageAltText = "",
transformations,
diParams = "",
children,
imageRef,
...other
Expand All @@ -34,12 +36,13 @@ const AdaptiveImage: React.SFC<AdaptiveImageProps> = (props) => {
return null;
}

const defaultImageUrl = getImageURL(image, transformations);
const defaultImageUrl = getImageURL(image, transformations, false, diParams);

return (
<AdaptiveImageContext.Provider value={{
image,
transformations
transformations,
diParams
}}>
<picture>
{children}
Expand Down
12 changes: 8 additions & 4 deletions components/cms-modern/AdaptiveImage/AdaptiveImageSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const AdaptiveImageSource: React.SFC<Props> = (props) => {

const {
image,
transformations: rootTransformations
transformations: rootTransformations,
diParams
} = useContext(AdaptiveImageContext) || {};

const [imageUrl, imageUrl2x] = useMemo(() => {
Expand All @@ -28,15 +29,18 @@ const AdaptiveImageSource: React.SFC<Props> = (props) => {
}
else {
return [
getImageURL(image, params),
getImageURL(image, params, false, diParams),
getImageURL(image, {
...params,
width: params.width ? params.width * 2 : undefined,
height: params.height ? params.height * 2 : undefined
})
},
false,
diParams
)
]
}
}, [image, rootTransformations, transformations]);
}, [image, rootTransformations, transformations, diParams]);
return imageUrl ? <source srcSet={`${imageUrl} 1x, ${imageUrl2x} 2x`} src={imageUrl} {...other} /> : null
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { forwardRef } from 'react';
import AdaptiveImage, { AdaptiveImageProps } from './AdaptiveImage';
import AdaptiveImageSource from './AdaptiveImageSource';
import { ImageFormat } from '@utils/getImageURL';

const DefaultAdaptiveImage: React.SFC<Omit<AdaptiveImageProps, 'children'>> = (props) => {
const {imageRef} = props;
Expand Down
4 changes: 3 additions & 1 deletion components/cms-modern/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ type Props = {
query?: any;
format?: string;
imageAltText?: string;
di?: string;
} & CmsContent;

const Image: FC<Props> = ({
display,
image,
imageAltText,
seoText,
di = "",
query,
roundel
}) => {
Expand Down Expand Up @@ -89,7 +91,7 @@ const Image: FC<Props> = ({
if (roundel && roundel[0] && roundel[0].roundel && roundel[0].roundelPosition && roundel[0].roundelRatio) {
queryString += `&$roundel$&${getRoundelConfig(roundel)}`
}
return getImageURL(`${baseUrl}?${queryString}`, transformations);
return getImageURL(`${baseUrl}?${queryString}`, transformations, false, di);
};

const source = ({ minWidth, maxWidth, width, highDensityWidth, format, poiAspect }: any) => {
Expand Down
3 changes: 2 additions & 1 deletion components/cms-modern/SimpleBanner/SimpleBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface SimpleBannerProps {
};
disablePoiAspectRatio: boolean;
imageAltText: string;
di: string;
},

/**
Expand Down Expand Up @@ -153,7 +154,7 @@ const SimpleBanner: React.FC<SimpleBannerProps> = ({
}>
{imageLoading ? <DefaultAdaptiveImageSkeleton/> : null}
<Box style={{display: `${imageLoading ? 'none': 'block'}`}}>
<DefaultAdaptiveImage ref={imageRef} onLoad={() => handleImageLoaded()} image={img?.image.image} imageAltText={image?.imageAltText} transformations={transformations} className={classes.image} />
<DefaultAdaptiveImage ref={imageRef} onLoad={() => handleImageLoaded()} image={img?.image.image} imageAltText={image?.imageAltText} transformations={transformations} diParams={image?.di} className={classes.image} />
</Box>

</Overlay>
Expand Down

1 comment on commit c96d098

@vercel
Copy link

@vercel vercel bot commented on c96d098 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.