Skip to content
Merged
Show file tree
Hide file tree
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
174 changes: 97 additions & 77 deletions src/components/Banner/Banner.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import React from "react"
import { Link } from "gatsby"
import ReactMarkdown from "react-markdown"
import MarkdownView from "react-showdown"
import Lottie from 'react-lottie'
import { useTheme } from "../../context/themeContext"
import useLandingUrl from "../../hooks/useLandingUrl"

import "./Banner.scss"
import PropTypes from 'prop-types'
import CustomLink from "../CustomLink/CustomLink"

const Banner = ({ data }) => {
const { theme } = useTheme()
const title = data?.title
const variant = data?.variant
const summary = data?.summary
const animation = data?.animation
const image = data?.image
const imageDark = data?.imageDark
const button = data?.button
const diagonalReverseState =
variant === "diagonalReverse" ? "col-md-4" : "col-lg-6"
const { title, variant, summary, animation, image, imageDark, button } = data

const defaultOptions = {
loop: true,
Expand All @@ -27,81 +18,110 @@ const Banner = ({ data }) => {
},
}

const getUrl = useLandingUrl();

const addButton = button &&
(button?.landing_page ? (
<Link to={getUrl(button.landing_page.slug)} className="button">
{button.content}
</Link>
) : (
<a
href={button.url}
target={button.url?.startsWith('http') && '_blank'}
rel={button.url?.startsWith('http') && 'noreferrer noopener'}
className="button"
>
{button.content}
</a>
))

const showTitle = () => {
if (variant === "hero") {
return <h1>{title}</h1>
} else {
if (variant === "diagonal" || variant === "diagonalReverse") {
return <h2>{title}</h2>
} else {
return <h1>{title}</h1>
}
}

return (
<div
className={`banner ${variant}`}
id={data.strapi_component + "-" + data.id}
>
{variant === "background" ?
<div className="bgImage" style={{
backgroundImage: `url(${image?.url})`,
}}>
<div className="title-background">
<h1 style={{ color: theme === 'dark' ? 'white' : '#3F6BE8' }}>{title}</h1>
{addButton}
</div>
</div> :
<>
<div className="title container-md">
<div className="col-12 col-lg-6">
{/* {variant === "hero" ? <h1>{title}</h1> : <h2>{title}</h2>} */}
{showTitle()}
<ReactMarkdown source={summary} className="banner-markdown" />
{addButton}
</div>
</div>

<div className={`banner ${variant}`}>
<div className="container banner__wrapper">
{variant === "background" ?
<div
className={`imagen col-12 ${variant === "diagonal" ? "col-md-8" : diagonalReverseState
} `}
>
{/* <img src={image?.url} alt={title} /> */}

{image?.url ?
<img
src={theme === "dark" && imageDark ? imageDark?.url : image?.url}
alt={title}
/> :
<div className="cont-lottie">
{animation && <Lottie options={{
...defaultOptions,
animationData: animation,
}}
/>}
className="bgImage"
style={{
backgroundImage: `url(${image?.url})`,
backgroundPosition: 'center',
// backgroundSize: 'cover',
}}>
<div className="title-background ">
<h1 style={{ color: theme === 'dark' ? 'white' : '#3F6BE8' }}>{title}</h1>
{summary && (
<MarkdownView
markdown={summary}
dangerouslySetInnerHTML={{ __html: summary }}
/>
)}
{button && (
<CustomLink
content={button.content}
url={button?.url}
landing={button?.landing_page}
className={'button'}
/>
)}
</div>
</div> :
<>
<div className="title container-md">
<div>
{showTitle()}
{summary && (
<MarkdownView
markdown={summary}
dangerouslySetInnerHTML={{ __html: summary }}
/>
)}
{button && (
<CustomLink
content={button.content}
url={button?.url}
landing={button?.landing_page}
className={'button'}
/>
)}
</div>
}
</div>
</>
}
</div>

<div className="imagen">
{image?.url ? (
<img
src={theme === "dark" && imageDark ? imageDark?.url : image?.url}
width={290}
height={200}
alt={image?.alternativeText || title}
/>) : (
<div className="cont-lottie">
{animation && <Lottie options={{
...defaultOptions,
animationData: animation,
}}
/>}
</div>
)}
</div>
</>
}
</div>
</div>
)
}

Banner.propTypes = {
data: PropTypes.shape({
title: PropTypes.string.isRequired,
variant: PropTypes.string.isRequired,
summary: PropTypes.string,
button: PropTypes.shape({
content: PropTypes.string.isRequired,
url: PropTypes.string,
landing_page: PropTypes.shape({
slug: PropTypes.string.isRequired
})
}),
animation: PropTypes.object,
image: PropTypes.shape({
alternativeText: PropTypes.string,
url: PropTypes.string,
}),
imageDark: PropTypes.shape({
alternativeText: PropTypes.string,
url: PropTypes.string,
})
}).isRequired
};

export default Banner
Loading