diff --git a/src/components/Banner/Banner.tsx b/src/components/Banner/Banner.tsx index 673442b..1cc125b 100644 --- a/src/components/Banner/Banner.tsx +++ b/src/components/Banner/Banner.tsx @@ -1,12 +1,24 @@ +import Image from 'next/image' +import type { CSSProperties } from 'react' import { Logo } from '@/components/Logo/Logo' +import type { Media } from '@/payload-types' import styles from "./styles.module.scss" +const backgroundSizeToObjectFit: Record< + 'cover' | 'contain' | 'auto', + CSSProperties['objectFit'] +> = { + cover: 'cover', + contain: 'contain', + auto: 'none', +} + export interface BannerProps { textLine1?: string | null textLine2?: string | null textLine3?: string | null backgroundColor?: string | null - backgroundImage?: string | null + backgroundImage?: Media | null backgroundPosition?: | 'center center' | 'top center' @@ -30,15 +42,27 @@ export const Banner = ({ backgroundPosition = 'center center', backgroundSize = 'cover', }: BannerProps) => { - const bannerStyle: React.CSSProperties = { + const bannerStyle: CSSProperties = { ...(backgroundColor && { backgroundColor }), - ...(backgroundImage && { backgroundImage: `url(${backgroundImage})` }), - ...(backgroundPosition && { backgroundPosition }), - ...(backgroundSize && { backgroundSize }), } return (
+ {backgroundImage?.url && ( + {backgroundImage.alt + )}
diff --git a/src/components/Banner/styles.module.scss b/src/components/Banner/styles.module.scss index c0b100b..bb0554b 100644 --- a/src/components/Banner/styles.module.scss +++ b/src/components/Banner/styles.module.scss @@ -4,14 +4,17 @@ position: relative; height: 634px; background-color: $shade1; - background-image: url("banner2.jpg"); - background-size: cover; - background-position: center center; opacity: 0.7; + overflow: hidden; +} + +.backgroundImage { + z-index: 0; } .logo { position: absolute; + z-index: 1; bottom: 20px; left: 30px; } @@ -21,6 +24,7 @@ color: $white; font-family: var(--header-font); position: absolute; + z-index: 1; bottom: 50px; right: 0; width: 50vw; diff --git a/src/compositions/Blocks/Blocks.tsx b/src/compositions/Blocks/Blocks.tsx index 1cfc0fd..5e5b2f5 100644 --- a/src/compositions/Blocks/Blocks.tsx +++ b/src/compositions/Blocks/Blocks.tsx @@ -148,10 +148,9 @@ export function Blocks({ content }: BlocksProps) { } if (item.blockType === 'banner') { - const bannerImageUrl = - typeof item.backgroundImage === 'object' && - item.backgroundImage?.url - ? item.backgroundImage.url + const backgroundImage = + typeof item.backgroundImage === 'object' + ? item.backgroundImage : undefined return (