import { Img } from "./media";
import { useEffect, useRef, useState, ReactNode, FormEvent } from "react";
import {
ArrowUpRight,
ArrowRight,
Search,
Heart,
ShoppingBag,
UserRound,
Menu,
X,
Plus,
Minus,
Leaf,
MapPin,
Package,
MessageCircle,
Instagram,
Facebook,
Check,
ChevronLeft,
ChevronDown,
ChevronRight,
Quote,
Pause,
Play,
Mail,
} from "lucide-react";
import {
Product,
products,
money,
categories,
collections,
reviews,
social,
contact,
articles,
} from "./data";
import { useStore } from "./store";
import { Link, navigate } from "./router";
export function Button({
children,
href,
onClick,
secondary = false,
className = "",
type = "button",
disabled = false,
}: {
children: ReactNode;
href?: string;
onClick?: () => void;
secondary?: boolean;
className?: string;
type?: "button" | "submit";
disabled?: boolean;
}) {
const cls = `button ${secondary ? "secondary" : ""} ${className}`;
return href ? (
{children}
) : (
{children}
);
}
export function IconButton({
label,
children,
onClick,
className = "",
}: {
label: string;
children: ReactNode;
onClick: () => void;
className?: string;
}) {
return (
{children}
);
}
export function SectionHeading({
eyebrow,
title,
copy,
link,
label = "Explore all",
}: {
eyebrow?: string;
title: string;
copy?: string;
link?: string;
label?: string;
}) {
return (
{eyebrow &&
{eyebrow}
}
{title}
{copy &&
{copy}
}
{link && (
{label}
)}
);
}
export const nav = [
["Home", "/"],
["Shop", "/shop"],
["Collections", "/collections"],
["About", "/about"],
["Journal", "/journal"],
["Contact", "/contact"],
];
const shopLinks = [
{ label: "All snacks", href: "/shop", note: "Find your next favourite" },
{ label: "New arrivals", href: "/shop?new=1", note: "Fresh to the snack club" },
...categories.filter(category => category !== "All snacks").map(category => ({
label: category, href: "/shop?category=" + encodeURIComponent(category), note: "",
})),
];
function ShopDropdown({ path = "", mobile = false, onNavigate }: { path?: string; mobile?: boolean; onNavigate?: () => void }) {
const [open, setOpen] = useState(false);
const root = useRef(null);
const trigger = useRef(null);
const id = mobile ? "mobile-shop-links" : "desktop-shop-links";
useEffect(() => { setOpen(false); }, [path]);
useEffect(() => {
if (!open) return;
const outside = (event: PointerEvent) => {
if (!root.current?.contains(event.target as Node)) setOpen(false);
};
document.addEventListener("pointerdown", outside);
return () => document.removeEventListener("pointerdown", outside);
}, [open]);
return { if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setOpen(false); }}
onKeyDown={event => { if (event.key === "Escape" && open) { event.preventDefault(); event.stopPropagation(); setOpen(false); trigger.current?.focus(); } }}>
{mobile && Shop}
setOpen(value => !value)}>
{!mobile && "Shop"}
CHOOSE YOUR CRUNCH
{shopLinks.map(link =>
{ setOpen(false); onNavigate?.(); }}>
{link.label} {link.note && {link.note} }
)}
;
}
export function Header({ path }: { path: string }) {
const { setOverlay, count, wishlist } = useStore();
const [scrolled, setScrolled] = useState(false);
const [announcementPaused, setAnnouncementPaused] = useState(false);
useEffect(() => {
const f = () => setScrolled(scrollY > 20);
window.addEventListener("scroll", f, { passive: true });
return () => window.removeEventListener("scroll", f);
}, []);
return (
<>
{[0, 1].map(copy => (
GOOD SNACKS. GREAT MOMENTS.
MEET YOUR NEW FAVOURITE CRUNCH
MALAYSIAN MADE, SHARED WITH THE WORLD
))}
setAnnouncementPaused(paused => !paused)}>
{announcementPaused ? : }
>
);
}
export function ProductCard({ product: p }: { product: Product }) {
const { add, wishlist, toggleWish } = useStore();
return (
{p.images[1] && (
)}
{p.isNew ? (
JUST LANDED
) : p.regularPrice > p.price ? (
SPECIAL PRICE
) : (
{p.spicy ? "A LITTLE HEAT" : "THE ORIGINAL"}
)}
toggleWish(p.id)}
>
View product
{p.pack} {p.weight && `· ${p.weight}`}
{p.spicy ? "Spicy" : "Original"}
{p.name}
{p.category === "Cornflakes"
? "Golden crunch. Rich salted egg."
: p.category === "Mushroom crisps"
? "A satisfyingly different crunch."
: p.category === "Tempeh chips"
? "A new twist on snack time."
: "Made for the moments you share."}
{money(p.price)}
{p.regularPrice > p.price && {money(p.regularPrice)}}
add(p)}
>
{p.stock ? "Quick add" : "Sold out"}
);
}
export function ProductGrid({ items }: { items: Product[] }) {
return (
);
}
export function QuantitySelector({
value,
onChange,
max = 99,
label = "Quantity",
}: {
value: number;
onChange: (q: number) => void;
max?: number;
label?: string;
}) {
return (
onChange(value - 1)}
>
{value}
= max}
onClick={() => onChange(value + 1)}
>
);
}
export function Benefits() {
return (
{[
[MapPin, "Malaysian at heart", "Our story began in Subang Jaya."],
[
Leaf,
"Flavour comes first",
"Discover our signature salted egg snacks.",
],
[
Package,
"A pack for every moment",
"From a little treat to something to share.",
],
[
MessageCircle,
"Let’s talk snacks",
"Our team is just a message away.",
],
].map(([Icon, title, text]: any) => (
))}
);
}
export function CollectionGrid({ all = false }: { all?: boolean }) {
return (
{collections.slice(0, all ? 4 : 2).map((c, i) => (
THE {c.category.toUpperCase()} COLLECTION
{c.title}
{c.subtitle}
{c.label}
0{i + 1}
))}
);
}
export function Testimonials() {
const ref = useRef(null);
return (
Real words from the ADUCKTIVE community.
ref.current?.scrollBy({ left: -400, behavior: "smooth" })
}
>
ref.current?.scrollBy({ left: 400, behavior: "smooth" })
}
>
{reviews.map((r, i) => (
{r.message}
{r.name.charAt(0)}
{r.name}
From our customer community
))}
);
}
export function Newsletter() {
const [status, setStatus] = useState("");
function submit(e: FormEvent) {
e.preventDefault();
const data = new FormData(e.currentTarget);
const email = String(data.get("email"));
window.location.href = `mailto:${contact.email}?subject=${encodeURIComponent("ADUCKTIVE newsletter sign-up request")}&body=${encodeURIComponent(`Please add ${email} to the ADUCKTIVE newsletter. I agree to receive new product and brand updates.`)}`;
setStatus(
"Your email app will open with a sign-up request. Send it to ask our team to subscribe you.",
);
}
return (
A LITTLE SOMETHING IN YOUR INBOX
Your inbox. Extra crunchy.
New releases, tasty updates, and more reasons to snack.
);
}
export function Footer() {
const groups = [
[
"SHOP",
["All snacks", "/shop"],
["New arrivals", "/shop?new=1"],
["Featured favourites", "/shop?featured=1"],
["Collections", "/collections"],
],
[
"OUR WORLD",
["Our story", "/about"],
["Journal", "/journal"],
["Find us", "https://aducktive.com/find-us"],
["Contact", "/contact"],
],
[
"HERE TO HELP",
["FAQs", "/help/faq"],
["Shipping", "/help/shipping"],
["Returns", "/help/returns"],
["Privacy", "/help/privacy"],
["Terms & conditions", "/help/terms"],
],
];
return (
Bold flavours. Savoury snacks.
Taste adventures.
{groups.map(([title, ...links]) => (
{title}
{links.map(([label, href]) => (
{label}
))}
))}
SO DUCKIN’ GOOD.
© {new Date().getFullYear()} Aducktive Food Sdn. Bhd. 1384616-H. All
rights reserved.
Made for the joy of snacking. ↗
);
}
export function EmptyState({ title, copy }: { title: string; copy: string }) {
return (
{title}
{copy}
Explore the snacks
);
}
export function Modal({
title,
children,
onClose,
side = false,
}: {
title: string;
children: ReactNode;
onClose: () => void;
side?: boolean;
}) {
const ref = useRef(null);
const closeRef = useRef(onClose);
closeRef.current = onClose;
useEffect(() => {
const d = ref.current!;
const prev = document.activeElement as HTMLElement;
d.showModal();
d.querySelector("input")?.focus();
const original = document.body.style.overflow;
document.body.style.overflow = "hidden";
return () => {
d.close();
document.body.style.overflow = original;
prev?.focus();
};
}, []);
return (
{
if (e.key === "Escape") {
e.preventDefault();
e.stopPropagation();
closeRef.current();
}
}}
onCancel={(e) => {
e.preventDefault();
closeRef.current();
}}
onClick={(e) => {
if (e.target === ref.current) {
const r = ref.current.getBoundingClientRect();
if (
e.clientX < r.left ||
e.clientX > r.right ||
e.clientY < r.top ||
e.clientY > r.bottom
)
onClose();
}
}}
>
{title}
{children}
);
}
export function CartItems() {
const { cart, update } = useStore();
return (
{cart.map((line) => {
const p = products.find((p) => p.id === line.id)!;
return (
{p.name}
{p.pack} · {p.weight}
update(p.id, q)}
label={p.name}
/>
{money(p.price * line.quantity)}
update(p.id, 0)}
aria-label={"Remove " + p.name}
>
Remove
);
})}
);
}
export function Overlays() {
const { overlay, setOverlay, cart, subtotal, count, toast } = useStore();
return (
<>
{overlay === "menu" && (
setOverlay(null)} side>
{[
...nav,
["Wishlist", "/wishlist"],
["My account", "/account"],
].map(([title, path]) => title === "Shop" ? setOverlay(null)} /> : (
setOverlay(null)}>
{title}
))}
A little crunch. A lot of joy.
)}
{overlay === "search" && }
{overlay === "cart" && (
setOverlay(null)}
>
{cart.length ? (
<>
A little happiness, ready to go.
Subtotal
{money(subtotal)}
Shipping and any discounts are confirmed by the official
store.
setOverlay(null)}>
Review & checkout
setOverlay(null)}
>
View your bag
>
) : (
{
if ((e.target as HTMLElement).closest("a")) setOverlay(null);
}}
>
)}
)}
{toast && (
{toast}
)}
>
);
}
function SearchOverlay() {
const { setOverlay } = useStore();
const [q, setQ] = useState("");
const query = q.trim().toLowerCase();
const results = products.filter((p) =>
(p.name + " " + p.pack + " " + p.category).toLowerCase().includes(query),
);
const news = articles.filter((a) => a.title.toLowerCase().includes(query));
return (
setOverlay(null)}>
{!query && (
POPULAR SEARCHES
{["Salted egg", "Mushroom", "Tempeh", "Fun pack"].map((x) => (
setQ(x)}>
{x}
))}
)}
{query ? `${results.length} PRODUCT RESULTS` : "EXPLORE OUR SNACKS"}
{results.slice(0, 5).map((p) => (
setOverlay(null)}
>
{p.name}
{p.pack} · {p.weight}
{money(p.price)}
))}
{query &&
categories
.filter((c) => c.toLowerCase().includes(query))
.map((c) => (
setOverlay(null)}
>
Collection: {c}
))}
{query &&
news.slice(0, 3).map((a) => (
setOverlay(null)}
>
Journal: {a.title}
))}
{query && !results.length && !news.length && (
No matches yet. Try “cornflakes”, “mushroom” or “tempeh”.
)}
);
}
export function SocialGallery() {
const imgs = [
"/images/snack-23-2.webp",
"/images/snack-26-2.webp",
"/images/snack-22-3.webp",
"/images/snack-130-2.webp",
"/images/snack-25-2.webp",
"/images/snack-145-1.webp",
];
return (
{imgs.map((src, i) => (
))}
Follow us for the latest products, updates, and a little snack
inspiration.
);
}