|
| 1 | +import { getImageProps } from "next/image" |
| 2 | +import { getLocale, getTranslations } from "next-intl/server" |
| 3 | + |
1 | 4 | import type { ClassNameProp, CommonHeroProps } from "@/lib/types"
|
2 | 5 |
|
3 | 6 | import LanguageMorpher from "@/components/Homepage/LanguageMorpher"
|
4 |
| -import { Image } from "@/components/Image" |
5 | 7 |
|
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" |
7 | 13 |
|
8 | 14 | export type HomeHeroProps = Pick<CommonHeroProps, "heroImg"> & ClassNameProp
|
9 | 15 |
|
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 }) |
12 | 39 |
|
13 | 40 | 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> |
25 | 58 | </div>
|
26 | 59 | <div className="flex flex-col items-center border-t-[3px] border-primary-low-contrast px-4 py-10 text-center">
|
27 | 60 | <LanguageMorpher />
|
28 | 61 | <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> |
30 | 63 | <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")} |
32 | 65 | </p>
|
33 | 66 | </div>
|
34 | 67 | </div>
|
|
0 commit comments