11import React from "react"
2- import { Link } from "gatsby"
32import MarkdownView from "react-showdown"
43//import ReactMarkdown from "react-markdown"
5- import Lottie from ' react-lottie'
4+ import Lottie from " react-lottie"
65import { useTheme } from "../../context/themeContext"
7- import { useLandingUrl } from '../../hooks'
86import "./Banner.scss"
9- import PropTypes from 'prop-types'
7+ import PropTypes from "prop-types"
8+ import CustomLink from "../CustomLink/CustomLink"
9+ import CustomImage from "../CustomImage/CustomImage"
1010
1111const Banner = ( { data } ) => {
1212 const { theme } = useTheme ( )
1313 const { title, variant, summary, animation, image, imageDark, button } = data
14- const getUrl = useLandingUrl ( )
1514
1615 const defaultOptions = {
1716 loop : true ,
1817 autoplay : true ,
1918 rendererSettings : {
20- preserveAspectRatio : ' xMidYMid slice'
19+ preserveAspectRatio : " xMidYMid slice" ,
2120 } ,
2221 }
2322
24- const Button = ( { button } ) => {
25- if ( button ?. english_landing_page ) {
26- return (
27- < Link
28- className = "button"
29- araa-label = { `Navigate to ${ button . content } ` }
30- to = { getUrl ( button . english_landing_page . slug ) }
31- >
32- { button ?. content }
33- </ Link >
34- )
35- } else if ( button ?. url ) {
36- if ( button . url ?. startsWith ( 'https' ) ) {
37- return (
38- < a href = { button . url }
39- target = "_blank"
40- rel = "noreferrer"
41- className = "button"
42- aria-label = "External Link"
43- >
44- { button ?. content }
45- </ a >
46- )
47- } else {
48- return (
49- < a
50- href = { button . url }
51- className = "button"
52- aria-label = { `Navigate to ${ button . content } ` }
53- >
54- { button ?. content }
55- </ a >
56- )
57- }
58- }
59-
60- return null
61- } ;
62-
6323 const showTitle = ( ) => {
64- if ( variant === "hero" ) {
65- return < h1 > { title } </ h1 >
66- } else {
24+ if ( variant === "diagonal" || variant === "diagonalReverse" ) {
6725 return < h2 > { title } </ h2 >
6826 }
27+
28+ return < h1 > { title } </ h1 >
6929 }
7030
7131 return (
72- < div
73- className = { `banner ${ variant } ` }
74- id = { data ?. strapi_component + "-" + data ?. id }
75- >
32+ < div className = { `banner ${ variant } ` } >
7633 < div className = "container banner__wrapper" >
77- { variant === "background" ?
78- < div
79- className = "bgImage"
80- style = { {
81- backgroundImage : `url(${ image ?. url } )` ,
82- backgroundPosition : 'center' ,
83- // backgroundSize: 'cover',
84- } } >
85- < div className = "title-background " >
86- < h1 style = { { color : theme === 'dark' ? 'white' : '#3F6BE8' } } > { title } </ h1 >
87- { < MarkdownView
34+ < div className = "title container-md" >
35+ < div >
36+ { /* {variant === "hero" ? <h1>{title}</h1> : <h2>{title}</h2> } */ }
37+ { showTitle ( ) }
38+ {
39+ < MarkdownView
8840 markdown = { summary }
8941 dangerouslySetInnerHTML = { { __html : summary } }
90- /> }
91- < Button button = { button } />
92- </ div >
93- </ div > :
94- < >
95- < div className = "title container-md" >
96- < div >
97- { /* {variant === "hero" ? <h1>{title}</h1> : <h2>{title}</h2> } */ }
98- { showTitle ( ) }
99- { < MarkdownView
100- markdown = { summary }
101- dangerouslySetInnerHTML = { { __html : summary } }
102- /> }
103- { /* <ReactMarkdown source={summary} className="banner-markdown" />*/ }
104- < Button button = { button } />
105- </ div >
106- </ div >
42+ />
43+ }
44+ < CustomLink
45+ content = { button ?. content }
46+ url = { button ?. url }
47+ landing = { button ?. english_landing_page }
48+ className = { "button" }
49+ />
50+ </ div >
51+ </ div >
10752
108- < div className = "imagen" >
109- { /* <img src={image?.url} alt={title} /> */ }
110- { image ?. url ? (
111- < img
112- src = { theme === "dark" && imageDark ? imageDark ?. url : image ?. url }
113- width = { 290 }
114- height = { 200 }
115- alt = { image ?. alternativeText
116- ? image . alternativeText
117- : title
118- }
119- /> ) : (
120- < div className = "cont-lottie" >
121- { animation && < Lottie options = { {
53+ < div className = "imagen" >
54+ { image ? (
55+ < CustomImage
56+ image = { theme === "dark" && imageDark ? imageDark : image }
57+ width = { 290 }
58+ height = { 200 }
59+ alt = { image ?. alternativeText || title }
60+ />
61+ ) : (
62+ < div className = "cont-lottie" >
63+ { animation && (
64+ < Lottie
65+ options = { {
12266 ...defaultOptions ,
12367 animationData : animation ,
12468 } }
125- /> }
126- </ div >
69+ />
12770 ) }
12871 </ div >
129- </ >
130- }
72+ ) }
73+ </ div >
13174 </ div >
13275 </ div >
13376 )
@@ -142,15 +85,29 @@ Banner.propTypes = {
14285 content : PropTypes . string . isRequired ,
14386 url : PropTypes . string ,
14487 english_landing_page : PropTypes . shape ( {
145- slug : PropTypes . string . isRequired
146- } )
88+ slug : PropTypes . string . isRequired ,
89+ } ) ,
14790 } ) ,
14891 animation : PropTypes . object ,
14992 image : PropTypes . shape ( {
15093 alternativeText : PropTypes . string ,
15194 url : PropTypes . string ,
152- } )
153- } ) . isRequired
95+ localFile : PropTypes . shape ( {
96+ childImageSharp : PropTypes . shape ( {
97+ gatsbyImageData : PropTypes . object ,
98+ } ) ,
99+ } ) ,
100+ } ) ,
101+ imageDark : PropTypes . shape ( {
102+ alternativeText : PropTypes . string ,
103+ url : PropTypes . string ,
104+ localFile : PropTypes . shape ( {
105+ childImageSharp : PropTypes . shape ( {
106+ gatsbyImageData : PropTypes . object ,
107+ } ) ,
108+ } ) ,
109+ } ) ,
110+ } ) . isRequired ,
154111}
155112
156113export default Banner
0 commit comments