| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import { ReactNode, useRef, useState } from "react";
- import { ArrowLeft, ArrowRight, ExternalLink } from "lucide-react";
-
- const campaigns = [
- { title: "Your snack-time manifesto", src: "", alt: "" },
- { title: "Your savoury snack experts", src: "/campaigns/snack-range.webp", alt: "ADUCKTIVE’s range of salted egg cornflakes, rolls and mushroom crisps. Your unique savoury snacks expert." },
- { title: "Find us at selected AEON stores", src: "/campaigns/aeon.webp", alt: "ADUCKTIVE campaign announcing availability at selected AEON stores, with the duck mascot and snack range. Open the full banner to read the listed locations." },
- { title: "Get your crunch at emart24", src: "/campaigns/emart24.webp", alt: "ADUCKTIVE original and spicy salted egg cornflakes mini packs. Get your salted egg snacks at emart24." },
- { title: "Bold flavours. Taste adventure.", src: "/campaigns/bold-flavours.jpg", alt: "ADUCKTIVE snack range: bold flavours, savoury snacks, taste adventure. Cornflakes, rolls and mushroom crisps pictured with their product information." },
- { title: "Snack happiness every day", src: "/campaigns/new-banner.webp", alt: "A family sharing ADUCKTIVE snacks together. Snack happiness every day." },
- { title: "Bold flavours at OH!SOME", src: "/campaigns/oh-some.jpg", alt: "ADUCKTIVE tempeh chips, mushroom crisps and cornflakes. Now available at OH!SOME." },
- { title: "Family pack. Dua pilihan, satu keceriaan.", src: "/campaigns/family-pack.jpg", alt: "ADUCKTIVE original and spicy salted egg cornflakes family packs. Open the full banner for promotional details." },
- { title: "Office snack fiesta with pandamart", src: "/campaigns/pandamart-fiesta.png", alt: "Lapar kat office? ADUCKTIVE snacks on pandamart. Open the full banner for promotional details." },
- { title: "More salted egg favourites at emart24", src: "/campaigns/emart-update.webp", alt: "ADUCKTIVE spicy and original salted egg cornflakes mini packs at emart24." },
- { title: "Find us at ST Rosyam Mart", src: "/campaigns/rosyam-mart.webp", alt: "ADUCKTIVE snacks now available at ST Rosyam Mart. Open the full banner to read the listed locations." },
- ];
-
- export function CampaignCarousel({ children }: { children: ReactNode }) {
- const [active, setActive] = useState(0);
- const touch = useRef<{ x: number; y: number } | null>(null);
- const move = (delta: number) => setActive(value => (value + delta + campaigns.length) % campaigns.length);
- return <section className="campaign-carousel" aria-label="ADUCKTIVE highlights" aria-roledescription="carousel">
- <div className="campaign-controls">
- <div className="campaign-caption"><span className="eyebrow">MORE REASONS TO CRUNCH</span><p aria-live="polite" aria-atomic="true">{active + 1} / {campaigns.length} · {campaigns[active].title}</p></div>
- <div className="campaign-navigation">
- <button type="button" aria-label="Previous banner" onClick={() => move(-1)}><ArrowLeft size={20}/></button>
- <div className="campaign-dots" aria-label="Choose a banner">{campaigns.map((campaign, index) => <button key={campaign.title} type="button" aria-label={`Show banner ${index + 1}: ${campaign.title}`} aria-current={index === active ? "true" : undefined} onClick={() => setActive(index)}><span/></button>)}</div>
- <button type="button" aria-label="Next banner" onClick={() => move(1)}><ArrowRight size={20}/></button>
- </div>
- </div>
- <div className="campaign-stage" tabIndex={0} aria-label="Banner viewer. Use left and right arrow keys to change banners."
- onKeyDown={event => { if (event.key === "ArrowRight" || event.key === "ArrowLeft") { event.preventDefault(); move(event.key === "ArrowRight" ? 1 : -1); } }}
- onTouchStart={event => { const point = event.touches[0]; touch.current = { x: point.clientX, y: point.clientY }; }}
- onTouchCancel={() => { touch.current = null; }}
- onTouchEnd={event => { if (!touch.current) return; const point = event.changedTouches[0]; const dx = point.clientX - touch.current.x; const dy = point.clientY - touch.current.y; touch.current = null; if (Math.abs(dx) > 55 && Math.abs(dx) > Math.abs(dy) * 1.5) move(dx < 0 ? 1 : -1); }}>
- <div className="campaign-slide campaign-original" role="group" aria-roledescription="slide" aria-label={`1 of ${campaigns.length}: Your snack-time manifesto`} hidden={active !== 0}>{children}<div className="campaign-original-footer">A little crunch. A lot of main character.</div></div>
- {campaigns.slice(1).map((campaign, index) => <div className="campaign-slide campaign-image-slide" role="group" aria-roledescription="slide" aria-label={`${index + 2} of ${campaigns.length}: ${campaign.title}`} key={campaign.src} hidden={active !== index + 1}>
- <img src={campaign.src} alt={campaign.alt} width={1920} height={1080} loading="lazy"/>
- <a className="campaign-full-image" href={campaign.src} target="_blank" rel="noreferrer">View full banner <ExternalLink size={14}/></a>
- </div>)}
- </div>
- </section>;
- }
|