design upgrade

This commit is contained in:
Nermin Karic
2026-11-23 00:59:47 +01:00
parent 9e84140474
commit ada6fd857c
198 changed files with 6626 additions and 2539 deletions

View File

@@ -0,0 +1,188 @@
"use client"
import Image from "next/image"
import { useCallback, useRef, useState } from "react"
import LocalizedClientLink from "@modules/common/components/localized-client-link"
import landing from "@/config/landing.json"
type Slide = (typeof landing.hero.slides)[number]
/**
* Home hero carousel (suncobrani, pergole, tende). Each slide brings its own
* headline, CTA and three product facts on the right.
*
* Autoplay is driven by the CSS progress bar (`.hero-progress` in
* globals.css): when the active bar's animation ends, the next slide shows.
* Keyboard focus pauses the bar; reduced motion disables the animation and so
* autoplay. Slides under the transparent header (see HeaderShell).
*/
export default function LandingHero() {
const { slides, intervalMs } = landing.hero
const [active, setActive] = useState(0)
const [paused, setPaused] = useState(false)
const touchX = useRef<number | null>(null)
const go = useCallback(
(index: number) => setActive((index + slides.length) % slides.length),
[slides.length]
)
return (
<section
data-hero-overlay
aria-roledescription="carousel"
aria-label="Suman proizvodi"
className="relative -mt-[57px] sm:-mt-[65px] h-[100svh] min-h-[600px] max-h-[1020px] w-full overflow-hidden bg-muted"
// Pause only for keyboard users (visible focus); hover and mouse clicks
// never pause, so the progress bar always runs smoothly
onFocus={(e) => setPaused((e.target as HTMLElement).matches(":focus-visible"))}
onBlur={() => setPaused(false)}
onKeyDown={(e) => {
if (e.key === "ArrowRight") go(active + 1)
if (e.key === "ArrowLeft") go(active - 1)
}}
onTouchStart={(e) => (touchX.current = e.touches[0].clientX)}
onTouchEnd={(e) => {
if (touchX.current === null) return
const dx = e.changedTouches[0].clientX - touchX.current
if (Math.abs(dx) > 50) go(active + (dx < 0 ? 1 : -1))
touchX.current = null
}}
>
{/* Images, cross-faded */}
{slides.map((slide, i) => (
<div
key={slide.id}
aria-hidden={i !== active}
className={`absolute inset-0 transition-opacity duration-1000 ease-out ${
i === active ? "opacity-100" : "opacity-0"
}`}
>
<Image
src={slide.image}
alt={slide.title}
fill
priority={i === 0}
// Only three slides: load all up front so a switch never shows a blank frame
loading={i === 0 ? undefined : "eager"}
sizes="100vw"
className={`object-cover will-change-transform transition-transform duration-[8000ms] ease-out ${
i === active ? "scale-100" : "scale-105"
}`}
/>
{/* Per-slide darkening (landing.json hero.slides[].overlay, 0–1) */}
{slide.overlay > 0 && (
<div className="absolute inset-0 bg-black" style={{ opacity: slide.overlay }} />
)}
</div>
))}
<div className="absolute inset-0 bg-gradient-to-t from-black/65 via-black/15 to-transparent" />
<div className="absolute inset-x-0 top-0 h-40 bg-gradient-to-b from-black/40 to-transparent" />
<div className="absolute inset-x-0 bottom-0 content-container pb-8 sm:pb-12">
<div className="flex flex-col gap-10 lg:flex-row lg:items-end lg:justify-between">
{/* Text: all slides stacked in one grid cell, only the active one visible */}
<div className="grid max-w-3xl text-white">
{slides.map((slide, i) => (
<SlideText key={slide.id} slide={slide} index={i} total={slides.length} active={i === active} />
))}
</div>
{/* Product facts for the visible slide */}
<div className="grid">
{slides.map((slide, i) => (
<dl
key={slide.id}
aria-hidden={i !== active}
className={`col-start-1 row-start-1 grid grid-cols-3 divide-x divide-white/25 text-white transition-[opacity,transform] duration-700 ${
i === active ? "translate-y-0 opacity-100" : "pointer-events-none translate-y-2 opacity-0"
}`}
>
{slide.stats.map((stat) => (
<div key={stat.label} className="px-4 sm:px-6 first:pl-0 last:pr-0 text-center lg:text-left">
<dt className="font-display text-lg sm:text-2xl whitespace-nowrap">{stat.value}</dt>
<dd className="mt-1 text-[11px] sm:text-xs text-white/70">{stat.label}</dd>
</div>
))}
</dl>
))}
</div>
</div>
{/* Slide selector with progress (drives autoplay) */}
<div className="mt-8 grid grid-cols-3 gap-3 sm:gap-6 border-t border-white/20 pt-4 sm:max-w-xl" role="tablist" aria-label="Odaberite proizvod">
{slides.map((slide, i) => (
<button
key={slide.id}
type="button"
role="tab"
aria-selected={i === active}
aria-label={`Prikaži: ${slide.kicker}`}
onClick={() => go(i)}
className="group text-left"
>
<span className="relative block h-0.5 w-full overflow-hidden bg-white/25">
{i === active && (
<span
key={`${slide.id}-${active}`}
className="hero-progress absolute inset-0 origin-left bg-white will-change-transform"
style={{
animationDuration: `${intervalMs}ms`,
animationPlayState: paused ? "paused" : "running",
}}
onAnimationEnd={() => go(active + 1)}
/>
)}
{i < active && <span className="absolute inset-0 bg-white/60" />}
</span>
<span
className={`mt-3 flex items-baseline gap-2 text-xs sm:text-sm transition-colors ${
i === active ? "text-white" : "text-white/60 group-hover:text-white"
}`}
>
<span className="tabular-nums opacity-70">0{i + 1}</span>
{slide.kicker}
</span>
</button>
))}
</div>
</div>
</section>
)
}
function SlideText({
slide,
index,
total,
active,
}: {
slide: Slide
index: number
total: number
active: boolean
}) {
const Heading = index === 0 ? "h1" : "h2"
return (
<div
role="group"
aria-roledescription="slide"
aria-label={`${index + 1} od ${total}: ${slide.kicker}`}
aria-hidden={!active}
className={`col-start-1 row-start-1 transition-[opacity,transform] duration-700 ${
active ? "translate-y-0 opacity-100" : "pointer-events-none translate-y-3 opacity-0"
}`}
>
<p className="eyebrow text-white/80">{slide.kicker}</p>
<Heading className="display-heading mt-4 text-[2.6rem] sm:text-6xl lg:text-7xl">{slide.title}</Heading>
<p className="mt-5 max-w-lg text-sm sm:text-base text-white/80 leading-relaxed">{slide.subtitle}</p>
<LocalizedClientLink
href={slide.cta.href}
tabIndex={active ? 0 : -1}
className="mt-7 inline-flex h-11 items-center rounded-md bg-white px-6 text-sm text-foreground transition-colors hover:bg-white/90"
>
{slide.cta.label}
</LocalizedClientLink>
</div>
)
}