1
+ "use client"
2
+
3
+ import { useState } from "react"
1
4
import Image from "next/image"
2
- import { getLocale , getTranslations } from "next-intl/server "
5
+ import { useTranslations } from "next-intl"
3
6
4
7
import { Heading2 } from "@/components/MdComponents"
5
8
6
9
import { breakpointAsNumber } from "@/lib/utils/screen"
7
10
8
11
import heroImage from "@/public/images/home/hero.png"
9
12
10
- export default async function HeroQualityDemo ( ) {
11
- const locale = getLocale ( )
12
- const t = await getTranslations ( { locale , namespace : "page-index" } )
13
+ export default function HeroQualityDemo ( ) {
14
+ const t = useTranslations ( "page-index" )
15
+ const [ selectedQualities , setSelectedQualities ] = useState < number [ ] > ( [ 100 , 5 ] )
13
16
14
17
const alt = t ( "page-index-hero-image-alt" )
15
18
16
19
// Generate quality values from 100% to 5% in 5% decrements
17
20
const qualityValues = Array . from ( { length : 20 } , ( _ , i ) => 100 - i * 5 )
18
21
22
+ const toggleQuality = ( quality : number ) => {
23
+ setSelectedQualities (
24
+ ( prev ) =>
25
+ prev . includes ( quality )
26
+ ? prev . filter ( ( q ) => q !== quality )
27
+ : [ ...prev , quality ] . sort ( ( a , b ) => b - a ) // Keep sorted descending
28
+ )
29
+ }
30
+
19
31
return (
20
32
< div className = "min-h-screen bg-background" >
21
33
< div className = "mb-8 p-8 text-center" >
@@ -24,20 +36,64 @@ export default async function HeroQualityDemo() {
24
36
</ h1 >
25
37
< p className = "text-body-medium" >
26
38
Comparing the homepage hero image at different quality settings (100%
27
- to 5% in 5% decrements)
39
+ to 5% in 5% decrements). Check the boxes below to compare selected
40
+ qualities side-by-side.
28
41
</ p >
29
42
</ div >
30
43
44
+ { /* Comparison Section */ }
45
+ { selectedQualities . length > 0 && (
46
+ < div className = "mb-24" >
47
+ < h2 className = "mb-6 text-center text-2xl font-bold" >
48
+ Selected Qualities Comparison ({ selectedQualities . length } selected)
49
+ </ h2 >
50
+ < div className = "space-y-6" >
51
+ { selectedQualities . map ( ( quality ) => (
52
+ < div key = { `comparison-${ quality } ` } className = "w-full" >
53
+ < div className = "relative mx-auto w-full max-w-[1536px]" >
54
+ < div className = "absolute start-4 top-4 text-center" >
55
+ < span className = "inline-block rounded bg-primary px-3 py-1 text-sm font-semibold text-primary-high-contrast" >
56
+ Quality: { quality } %
57
+ </ span >
58
+ </ div >
59
+ < div className = "h-[240px] overflow-hidden md:h-[380px] lg:h-[480px]" >
60
+ < Image
61
+ src = { heroImage }
62
+ alt = { `${ alt } (Quality: ${ quality } %)` }
63
+ width = { 1536 }
64
+ height = { 480 }
65
+ quality = { quality }
66
+ sizes = { `(max-width: ${ breakpointAsNumber [ "2xl" ] } px) 100vw, ${ breakpointAsNumber [ "2xl" ] } px` }
67
+ className = "h-full w-full object-cover"
68
+ />
69
+ </ div >
70
+ </ div >
71
+ </ div >
72
+ ) ) }
73
+ </ div >
74
+ < hr className = "my-8" />
75
+ </ div >
76
+ ) }
77
+
31
78
< div className = "space-y-8" >
32
79
{ qualityValues . map ( ( quality ) => (
33
80
< div key = { quality } className = "w-full" >
34
- < div className = "px-6 pb-4" >
35
- < Heading2
36
- id = { quality . toString ( ) }
37
- className = "m-0 text-xl font-semibold"
38
- >
39
- Quality: { quality } %
40
- </ Heading2 >
81
+ < div className = "flex items-center gap-4 px-6 pb-4" >
82
+ < input
83
+ type = "checkbox"
84
+ id = { `quality-${ quality } ` }
85
+ checked = { selectedQualities . includes ( quality ) }
86
+ onChange = { ( ) => toggleQuality ( quality ) }
87
+ className = "-ms-4 h-4 w-4 flex-shrink-0 rounded border-gray-300 text-primary focus:ring-primary"
88
+ />
89
+ < div className = "flex-1" >
90
+ < Heading2
91
+ id = { quality . toString ( ) }
92
+ className = "m-0 ms-4 text-xl font-semibold"
93
+ >
94
+ Quality: { quality } %
95
+ </ Heading2 >
96
+ </ div >
41
97
</ div >
42
98
< div className = "mx-auto w-full max-w-[1536px]" >
43
99
< div className = "h-[240px] overflow-hidden md:h-[380px] lg:h-[480px]" >
0 commit comments