Last active
December 13, 2023 15:49
-
-
Save sandeepvpote/3b024ab748ba104ebb627c323b90196d to your computer and use it in GitHub Desktop.
Sitecore Headless Background Image to the component
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
import React from 'react'; | |
import { | |
Field, | |
Text, | |
RichText, | |
ImageField, | |
Image, | |
useSitecoreContext, | |
} from '@sitecore-jss/sitecore-jss-nextjs'; | |
interface Fields { | |
Heading: Field<string>; | |
Title: Field<string>; | |
Description: Field<string>; | |
'Background Image': ImageField; | |
} | |
type TextTileProps = { | |
params: { [key: string]: string }; | |
fields: Fields; | |
}; | |
const Banner = (props: TextTileProps): JSX.Element => { | |
let backgroundImage = props.fields['Background Image'] as string; | |
let backgroundStyle: { [key: string]: string } = {}; | |
backgroundImage = backgroundImage?.value?.src; | |
if (backgroundImage) { | |
backgroundStyle = { | |
backgroundImage: `url('${backgroundImage}')`, | |
}; | |
} | |
console.log(backgroundStyle); | |
return ( | |
<div className="page-header pl-4 pr-4 pt-0" style={backgroundStyle}> | |
<h3 className="page-subtitle font-weight-bold"> | |
<Text field={props.fields.Heading} /> | |
</h3> | |
<h1 className="page-title font-white-bold lh-1 text-white text-capitalize"> | |
<Text field={props.fields.Title} /> | |
</h1> | |
<RichText className="page-desc text-white mb-0" field={props.fields.Description} /> | |
</div> | |
); | |
}; | |
export default Banner; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment