import { useEffect, useState } from "react";
import { Link, NavLink, Outlet, useLocation } from "react-router-dom";
import { company, navigation, phoneHref } from "../data";
import { Arrow, WhatsAppAction } from "./Primitives";
import "./Layout.css";
function Brand() {
return (
{company.shortName}
);
}
function Header() {
const [menuOpen, setMenuOpen] = useState(false);
const closeMenu = () => setMenuOpen(false);
return (
{
if (menuOpen && event.key === "Escape") {
closeMenu();
document.getElementById("menu-toggle")?.focus();
}
}}
>
{navigation.map(({ to, label }) => (
`site-nav__link${isActive ? " site-nav__link--active" : ""}`
}
>
{label}
))}
Text us on WhatsApp
);
}
function Footer() {
return (
);
}
export function ContactBanner({
title = (
<>
Developing your
next construction?
>
),
text = "Talk to us about fabric structure, yarn combinations, bulk requirements or new developments.",
}) {
return (
A conversation is where it begins
{title}
{text}
);
}
export default function Layout() {
const { pathname, hash, key } = useLocation();
useEffect(() => {
const title =
navigation.find(({ to }) => to === pathname)?.label ?? "Page not found";
document.title = `${title === "Home" ? "RRS" : `${title} - RRS`} | Radhe Radhe Synthetics`;
const target = hash
? document.getElementById(hash.slice(1))
: document.getElementById("main-content");
if (hash && target) target.scrollIntoView({ behavior: "instant" });
else window.scrollTo({ top: 0, behavior: "instant" });
target?.focus({ preventScroll: true });
}, [pathname, hash, key]);
useEffect(() => {
const sections = [...document.querySelectorAll("#main-content > section")];
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
if (reducedMotion || !("IntersectionObserver" in window)) {
sections.forEach((section) => section.classList.add("reveal--visible"));
return undefined;
}
sections.forEach((section) => section.classList.add("reveal"));
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
entry.target.classList.add("reveal--visible");
observer.unobserve(entry.target);
});
},
{ threshold: 0.08, rootMargin: "0px 0px -8% 0px" },
);
sections.forEach((section) => observer.observe(section));
return () => observer.disconnect();
}, [pathname, key]);
return (
);
}