Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed issue with border for image #3548

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions packages/app-page-builder-elements/src/renderers/image.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import styled from "@emotion/styled";
import { createRenderer, CreateRendererOptions } from "~/createRenderer";
import { useRenderer } from "~/hooks/useRenderer";
Expand Down Expand Up @@ -33,19 +33,53 @@ export const ImageRendererComponent: React.FC<ImageRendererComponentProps> = ({
}) => {
const LinkComponent = linkComponent || DefaultLinkComponent;

const { getElement } = useRenderer();

const { getElement, getElementStyles } = useRenderer();
const element = getElement<ImageElementData>();

let content;
/*
Border styles are being applied to pb-image instead of img itself,
so to fix that we need to remove border from pb-image and add it to the img.
*/
useEffect(() => {
const pbImage = document.getElementById(element.id);
/*
Reseting border styles for <pb-image></pb-image>
*/
if (pbImage) {
pbImage.style.border = "none";
pbImage.style.borderRadius = "0";
}
}, []);

const getBorderStyles = () => {
/*
Copied the element styles so we won't modify original styles.
*/
const elementStyles = {
...getElementStyles(element)
} as any;
/*
We are looping through element styles and we are removing styles that are not related to border.
*/
Object.keys(elementStyles).forEach(cssContainerKey => {
Object.keys(elementStyles[cssContainerKey]).forEach(styleKey => {
if (!styleKey.includes("border")) {
delete elementStyles[cssContainerKey][styleKey];
}
});
});
return elementStyles;
};

if (element.data?.image?.file?.src) {
// Image has its width / height set from its own settings.
const PbImg = styled.img({
width: element.data.image.width,
height: element.data.image.height,
maxWidth: "100%"
maxWidth: "100%",
...getBorderStyles()
});

const { title } = element.data.image;
const { src } = value || element.data?.image?.file;

Expand Down
Loading