fix: quicker loading
This commit is contained in:
parent
24bf6d352d
commit
a86eee52ce
3 changed files with 40 additions and 13 deletions
|
|
@ -1,12 +1,24 @@
|
||||||
|
import Image from 'next/image'
|
||||||
|
import type { CSSProperties } from 'react'
|
||||||
import { Logo } from '@/components/Logo/Logo'
|
import { Logo } from '@/components/Logo/Logo'
|
||||||
|
import type { Media } from '@/payload-types'
|
||||||
import styles from "./styles.module.scss"
|
import styles from "./styles.module.scss"
|
||||||
|
|
||||||
|
const backgroundSizeToObjectFit: Record<
|
||||||
|
'cover' | 'contain' | 'auto',
|
||||||
|
CSSProperties['objectFit']
|
||||||
|
> = {
|
||||||
|
cover: 'cover',
|
||||||
|
contain: 'contain',
|
||||||
|
auto: 'none',
|
||||||
|
}
|
||||||
|
|
||||||
export interface BannerProps {
|
export interface BannerProps {
|
||||||
textLine1?: string | null
|
textLine1?: string | null
|
||||||
textLine2?: string | null
|
textLine2?: string | null
|
||||||
textLine3?: string | null
|
textLine3?: string | null
|
||||||
backgroundColor?: string | null
|
backgroundColor?: string | null
|
||||||
backgroundImage?: string | null
|
backgroundImage?: Media | null
|
||||||
backgroundPosition?:
|
backgroundPosition?:
|
||||||
| 'center center'
|
| 'center center'
|
||||||
| 'top center'
|
| 'top center'
|
||||||
|
|
@ -30,15 +42,27 @@ export const Banner = ({
|
||||||
backgroundPosition = 'center center',
|
backgroundPosition = 'center center',
|
||||||
backgroundSize = 'cover',
|
backgroundSize = 'cover',
|
||||||
}: BannerProps) => {
|
}: BannerProps) => {
|
||||||
const bannerStyle: React.CSSProperties = {
|
const bannerStyle: CSSProperties = {
|
||||||
...(backgroundColor && { backgroundColor }),
|
...(backgroundColor && { backgroundColor }),
|
||||||
...(backgroundImage && { backgroundImage: `url(${backgroundImage})` }),
|
|
||||||
...(backgroundPosition && { backgroundPosition }),
|
|
||||||
...(backgroundSize && { backgroundSize }),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.banner} style={bannerStyle}>
|
<div className={styles.banner} style={bannerStyle}>
|
||||||
|
{backgroundImage?.url && (
|
||||||
|
<Image
|
||||||
|
src={backgroundImage.url}
|
||||||
|
alt={backgroundImage.alt ?? ''}
|
||||||
|
fill
|
||||||
|
priority
|
||||||
|
sizes="100vw"
|
||||||
|
unoptimized
|
||||||
|
className={styles.backgroundImage}
|
||||||
|
style={{
|
||||||
|
objectFit: backgroundSizeToObjectFit[backgroundSize ?? 'cover'],
|
||||||
|
objectPosition: backgroundPosition ?? 'center center',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<div className={styles.logo}>
|
<div className={styles.logo}>
|
||||||
<Logo color={"#ffffff33"} height={200} />
|
<Logo color={"#ffffff33"} height={200} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 634px;
|
height: 634px;
|
||||||
background-color: $shade1;
|
background-color: $shade1;
|
||||||
background-image: url("banner2.jpg");
|
|
||||||
background-size: cover;
|
|
||||||
background-position: center center;
|
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.backgroundImage {
|
||||||
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
left: 30px;
|
left: 30px;
|
||||||
}
|
}
|
||||||
|
|
@ -21,6 +24,7 @@
|
||||||
color: $white;
|
color: $white;
|
||||||
font-family: var(--header-font);
|
font-family: var(--header-font);
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
bottom: 50px;
|
bottom: 50px;
|
||||||
right: 0;
|
right: 0;
|
||||||
width: 50vw;
|
width: 50vw;
|
||||||
|
|
|
||||||
|
|
@ -148,10 +148,9 @@ export function Blocks({ content }: BlocksProps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.blockType === 'banner') {
|
if (item.blockType === 'banner') {
|
||||||
const bannerImageUrl =
|
const backgroundImage =
|
||||||
typeof item.backgroundImage === 'object' &&
|
typeof item.backgroundImage === 'object'
|
||||||
item.backgroundImage?.url
|
? item.backgroundImage
|
||||||
? item.backgroundImage.url
|
|
||||||
: undefined
|
: undefined
|
||||||
return (
|
return (
|
||||||
<Banner
|
<Banner
|
||||||
|
|
@ -160,7 +159,7 @@ export function Blocks({ content }: BlocksProps) {
|
||||||
textLine2={item.textLine2}
|
textLine2={item.textLine2}
|
||||||
textLine3={item.textLine3}
|
textLine3={item.textLine3}
|
||||||
backgroundColor={item.backgroundColor}
|
backgroundColor={item.backgroundColor}
|
||||||
backgroundImage={bannerImageUrl}
|
backgroundImage={backgroundImage}
|
||||||
backgroundPosition={item.backgroundPosition}
|
backgroundPosition={item.backgroundPosition}
|
||||||
backgroundSize={item.backgroundSize}
|
backgroundSize={item.backgroundSize}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue