Skip to content

Commit e0e3de2

Browse files
committed
refactor: home hero source and srcset
add trimmed version for 2xl screens where top/bottom never display; drop quality progressively on smaller devices
1 parent 96805c8 commit e0e3de2

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

app/[locale]/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ import { fetchRSS } from "@/lib/api/fetchRSS"
9292
import { fetchTotalEthStaked } from "@/lib/api/fetchTotalEthStaked"
9393
import { fetchTotalValueLocked } from "@/lib/api/fetchTotalValueLocked"
9494
import EventFallback from "@/public/images/events/event-placeholder.png"
95-
import Hero from "@/public/images/home/hero.png"
9695

9796
const BentoCardSwiper = dynamic(
9897
() => import("@/components/Homepage/BentoCardSwiper"),
@@ -444,7 +443,7 @@ const Page = async ({ params }: { params: Promise<{ locale: Lang }> }) => {
444443
</Link>
445444
</p>
446445
</BannerNotification>
447-
<HomeHero heroImg={Hero} className="w-full" />
446+
<HomeHero />
448447
<div className="w-full space-y-32 px-4 md:mx-6 lg:space-y-48">
449448
<div className="my-20 grid w-full grid-cols-2 gap-x-4 gap-y-8 md:grid-cols-4 md:gap-x-10">
450449
{subHeroCTAs.map(

public/images/home/hero-2xl.png

1.85 MB
Loading

public/images/home/hero.png

-5.16 MB
Loading

src/components/Hero/HomeHero/index.tsx

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,67 @@
1+
import { getImageProps } from "next/image"
2+
import { getLocale, getTranslations } from "next-intl/server"
3+
14
import type { ClassNameProp, CommonHeroProps } from "@/lib/types"
25

36
import LanguageMorpher from "@/components/Homepage/LanguageMorpher"
4-
import { Image } from "@/components/Image"
57

6-
import useTranslation from "@/hooks/useTranslation"
8+
import { cn } from "@/lib/utils/cn"
9+
import { breakpointAsNumber } from "@/lib/utils/screen"
10+
11+
import heroBase from "@/public/images/home/hero.png"
12+
import hero2xl from "@/public/images/home/hero-2xl.png"
713

814
export type HomeHeroProps = Pick<CommonHeroProps, "heroImg"> & ClassNameProp
915

10-
const HomeHero = ({ heroImg, className }: HomeHeroProps) => {
11-
const { t } = useTranslation("page-index")
16+
const HomeHero = async ({ className }: HomeHeroProps) => {
17+
const locale = getLocale()
18+
const t = await getTranslations({ locale, namespace: "page-index" })
19+
20+
const alt = t("page-index-hero-image-alt")
21+
22+
const common = {
23+
alt,
24+
sizes: `(max-width: ${breakpointAsNumber["2xl"]}px) 100vw, ${breakpointAsNumber["2xl"]}px`,
25+
priority: true,
26+
}
27+
28+
const {
29+
props: { srcSet: srcSet2xl },
30+
} = getImageProps({ ...common, ...hero2xl, quality: 20 })
31+
32+
const {
33+
props: { srcSet: srcSetMd },
34+
} = getImageProps({ ...common, ...heroBase, quality: 10 })
35+
36+
const {
37+
props: { srcSet: srcSetBase, ...rest },
38+
} = getImageProps({ ...common, ...heroBase, quality: 5 })
1239

1340
return (
14-
<div className={className}>
15-
<div className="h-[240px] md:h-[380px] lg:h-[480px]">
16-
<Image
17-
src={heroImg}
18-
alt={t("page-index:page-index-hero-image-alt")}
19-
// TODO: adjust value when the old theme breakpoints are removed (src/theme.ts)
20-
sizes="(max-width: 1504px) 100vw, 1504px"
21-
className="h-full w-full object-cover"
22-
quality={20}
23-
priority
24-
/>
41+
<div className={cn("w-full", className)}>
42+
<div className="h-[240px] overflow-hidden md:h-[380px] lg:h-[480px]">
43+
<picture>
44+
<source
45+
media={`(min-width: ${breakpointAsNumber["2xl"]}px)`}
46+
srcSet={srcSet2xl}
47+
/>
48+
<source
49+
media={`(min-width: ${breakpointAsNumber["md"]}px) and (max-width: ${breakpointAsNumber["2xl"] - 1}px)`}
50+
srcSet={srcSetMd}
51+
/>
52+
<source
53+
media={`(max-width: ${breakpointAsNumber["md"] - 1}px)`}
54+
srcSet={srcSetBase}
55+
/>
56+
<img {...rest} alt={alt} className="h-full w-full object-cover" />
57+
</picture>
2558
</div>
2659
<div className="flex flex-col items-center border-t-[3px] border-primary-low-contrast px-4 py-10 text-center">
2760
<LanguageMorpher />
2861
<div className="flex flex-col items-center gap-y-5 lg:max-w-2xl">
29-
<h1 className="font-black">{t("page-index:page-index-title")}</h1>
62+
<h1 className="font-black">{t("page-index-title")}</h1>
3063
<p className="max-w-96 text-md text-body-medium lg:text-lg">
31-
{t("page-index:page-index-description")}
64+
{t("page-index-description")}
3265
</p>
3366
</div>
3467
</div>

0 commit comments

Comments
 (0)