import { A, useLocation } from "@solidjs/router"; import { createEffect, createSignal, For, on, onCleanup, Show } from "solid-js"; import Logo from "./Logo"; import { PixelClose, PixelMenu } from "./icons/pixel"; import { anchors, routes, site } from "~/config"; import { t } from "~/i18n"; /** * The site is one page, so the bar is a table of contents rather than a set of * routes: every label is an in-page anchor, and the band currently under the * header is the one marked as current. */ export default function Header() { const location = useLocation(); const [open, setOpen] = createSignal(false); const [active, setActive] = createSignal(null); /** * The bar carries four stops; the sheet carries every one. "Nasıl çalışır" * is the diagram page rather than the band of the same name — the band is a * summary, and anyone who clicks the label wants the long version. */ const primary = [ { href: anchors.products, label: t.nav.products }, { href: routes.how, label: t.nav.theory }, { href: anchors.audience, label: t.nav.audience }, { href: anchors.about, label: t.nav.about }, ]; const all = [ { href: anchors.problem, label: t.nav.problem }, ...primary, { href: anchors.platform, label: t.nav.platform }, { href: anchors.roles, label: t.nav.roles }, { href: anchors.trust, label: t.nav.trust }, { href: anchors.faq, label: t.nav.faq }, { href: routes.contact, label: t.nav.contact }, ]; /** Anchors carry a fragment; the two standing pages do not. */ const id = (href: string) => href.split("#")[1] ?? ""; /* A band is only current on the page it lives on: on the diagram or the form page, a stale "Ürünler" mark would say the click never left home. */ const isCurrent = (href: string) => href.includes("#") ? location.pathname === routes.home && active() === id(href) : location.pathname === href; /** * Which band is current. The observer's top margin is the header's own * height, so a section counts as "under the bar" rather than merely on * screen, and the bottom margin keeps a band that is only just visible from * taking the mark from the one filling the viewport. */ createEffect( on( () => location.pathname, pathname => { setActive(null); // The header outlives the page under it, so the bands are looked up // again on every page change: arriving home from the form page has to // find sections that did not exist when the header mounted. if (pathname !== routes.home || !("IntersectionObserver" in window)) return; const sections = all .filter(item => item.href.includes("#")) .map(item => document.getElementById(id(item.href))) .filter((node): node is HTMLElement => node !== null); const observer = new IntersectionObserver( entries => { const visible = entries .filter(entry => entry.isIntersecting) .sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top); if (visible.length > 0) setActive(visible[0]!.target.id); }, { rootMargin: "-72px 0px -55% 0px", threshold: 0 }, ); sections.forEach(section => observer.observe(section)); onCleanup(() => observer.disconnect()); }, ), ); return (
{t.nav.demo}
); }