-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ImageBlock to demo * remove unused styling for growToIverflowWidth * add commonImageBlockStyles to MjmlHead * set loaded width to doubled value of maximum rendered width * fix prettier problems * remove unused allowedImageSizes * remove growToOverflow completely * use cssClass directly * add indentedSectionGroupStyles to fix responsive behaviour * rename variable contentWidth to mailWidth and add new variable contentWidth to theme to avoid repetitive calculation of width * use contentWidth from theme in imageBlockHelpers * use css helper * use variables from theme in IndentedSectionGroup * use theme variable directly instead of defining a new one * correct css class * remove heightValues to keep correct aspectRatio * correct contentWidth and aspectRatio * remove padding from image * pass paddingLeft and -Right directly to RichTextBlock to allow elements having full contentWidth * undo changes on RichTextBlock and instead pass padding on IndentedSectionGroup of the image itself * add MjmlAttributes to remove default padding * use MjmlSection in ImageBlock instead of IndentedSectionGroup * use inline styles for CommonImageBlock * remove padding of MjmlSection globally --------- Co-authored-by: Julia Wegmayr <[email protected]>
- Loading branch information
1 parent
72fb133
commit 7e56895
Showing
13 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"eslint.workingDirectories": ["demo", "package"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PropsWithData } from "@comet/cms-site"; | ||
import { MjmlColumn, MjmlSection } from "@luma-team/mjml-react"; | ||
import { PixelImageBlockData } from "@src/blocks.generated"; | ||
import { CommonImageBlock } from "@src/common/blocks/CommonImageBlock"; | ||
import { theme } from "@src/util/theme"; | ||
|
||
export const ImageBlock = ({ data }: PropsWithData<PixelImageBlockData>) => { | ||
return ( | ||
<MjmlSection> | ||
<MjmlColumn> | ||
<CommonImageBlock data={data} desktopRenderWidth={theme.mailSize.contentWidth} /> | ||
</MjmlColumn> | ||
</MjmlSection> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { calculateInheritAspectRatio, generateImageUrl } from "@comet/cms-site"; | ||
import { MjmlImage, MjmlStyle } from "@luma-team/mjml-react"; | ||
import { PixelImageBlockData } from "@src/blocks.generated"; | ||
import { css } from "@src/util/stylesHelper"; | ||
import { theme } from "@src/util/theme"; | ||
import * as React from "react"; | ||
|
||
import { getDamAllowedImageWidth } from "../helpers/imageBlockHelpers"; | ||
|
||
interface Props extends React.ComponentProps<typeof MjmlImage> { | ||
data: PixelImageBlockData; | ||
desktopRenderWidth: number; | ||
} | ||
|
||
export const commonImageBlockStyles = ( | ||
<MjmlStyle>{css` | ||
@media (max-width: ${theme.mailSize.contentWidth - 1}px) { | ||
.image-block > table > tbody > tr > td { | ||
width: 100% !important; | ||
} | ||
.image-block img { | ||
height: auto !important; | ||
} | ||
} | ||
`}</MjmlStyle> | ||
); | ||
|
||
export const CommonImageBlock = ({ data, desktopRenderWidth, ...restProps }: Props) => { | ||
const { damFile, cropArea, urlTemplate } = data; | ||
|
||
if (!damFile?.image) { | ||
return null; | ||
} | ||
|
||
const usedCropArea = cropArea ?? damFile.image.cropArea; | ||
const usedAspectRatio = calculateInheritAspectRatio(damFile.image, usedCropArea); | ||
|
||
const imageUrl: string = generateImageUrl( | ||
{ | ||
width: getDamAllowedImageWidth(desktopRenderWidth, theme.mailSize.contentWidth), | ||
src: urlTemplate, | ||
}, | ||
usedAspectRatio, | ||
); | ||
|
||
const desktopImageHeight = Math.round(desktopRenderWidth / usedAspectRatio); | ||
|
||
return ( | ||
<MjmlImage | ||
src={imageUrl} | ||
fluidOnMobile="true" | ||
cssClass="image-block" | ||
width={desktopRenderWidth} | ||
height={desktopImageHeight} | ||
alt={damFile.altText} | ||
title={damFile.title} | ||
padding={0} | ||
{...restProps} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const validSizes: number[] = (process.env.DAM_ALLOWED_IMAGE_SIZES as string) | ||
.split(",") | ||
.map((value) => parseInt(value)) | ||
.sort((a, b) => a - b); | ||
|
||
export const getDamAllowedImageWidth = (minimumWidth: number, contentWidth): number => { | ||
let width: number | null = null; | ||
const largestPossibleWidth = validSizes[validSizes.length - 1]; | ||
|
||
validSizes.forEach((validWidth) => { | ||
if (minimumWidth === contentWidth) { | ||
width = contentWidth * 2; | ||
} else if (!width && validWidth >= minimumWidth * 2) { | ||
width = validWidth; | ||
} | ||
}); | ||
|
||
if (!width) { | ||
return largestPossibleWidth; | ||
} | ||
|
||
return width; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters