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

#545156: added possibility to change image #1168

Merged
merged 1 commit into from
Sep 27, 2022
Merged
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
#545156: added pisibility to change image into banner variant of ima…
…ge component
sc-ruslanmatkovskyi committed Sep 27, 2022
commit 3616b59e55d5231fde266b5a7c3c6ba550a4f7a8
Original file line number Diff line number Diff line change
@@ -9,4 +9,7 @@
height: 300px;
}
}
.sc-image-wrapper {
opacity: 0;
}
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import {
Text,
useSitecoreContext,
} from '@sitecore-jss/sitecore-jss-nextjs';
import { getEEMarkup } from '@sitecore-jss/sitecore-jss-react';

interface Fields {
Image: ImageField;
@@ -29,11 +30,21 @@ const ImageDefault = (props: ImageProps): JSX.Element => (
);

export const Banner = (props: ImageProps): JSX.Element => {
const { sitecoreContext } = useSitecoreContext();
const backgroundStyle = { backgroundImage: `url('${props?.fields?.Image?.value?.src}')` };
const modifyImageProps = {
...props.fields.Image,
editable: props?.fields?.Image?.editable
?.replace(`width="${props?.fields?.Image?.value?.width}"`, 'width="100%"')
.replace(`height="${props?.fields?.Image?.value?.height}"`, 'height="100%"'),
};
const Image = () => getEEMarkup(modifyImageProps);

return (
<div className={`component hero-banner ${props.params.styles}`}>
<div className="component-content" style={backgroundStyle} />
<div className="component-content" style={backgroundStyle}>
{sitecoreContext.pageState === 'edit' ? <Image /> : ''}
</div>
</div>
);
};