{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"navbar-with-centered-links-and-mobile-menu","type":"registry:block","title":"Navbar with Centered Links, CTA Button and Mobile Menu","description":"Navbar over a photo hero: logo left, links in the true centre, a booking button and a glass mobile menu with a photo per page. Free React and HTML to copy.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/navbar-with-centered-links-and-mobile-menu.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport type { KeyboardEvent } from \"react\";\nimport { AnimatePresence, motion, useInView, useReducedMotion } from \"framer-motion\";\n\n/** One entry per page link. Each link brings its own photograph, headline and facts to the hero. */\nconst links = [\n  {\n    label: \"Day trips\",\n    img: \"https://images.unsplash.com/photo-1501785888041-af3ef285b470?auto=format&fit=crop&w=1600&q=80\",\n    thumb: \"https://images.unsplash.com/photo-1501785888041-af3ef285b470?auto=format&fit=crop&w=200&q=80\",\n    alt: \"A wooden rowing boat crossing a turquoise mountain lake below pale limestone cliffs\",\n    headline: [\"Row out before\", \"the wind does.\"],\n    copy: \"Larch rowing boats by the hour or the day, from the old jetty on the north shore. No engines on this water since 1971.\",\n    facts: [[\"First boat\", \"06:30\"], [\"Water\", \"11 °C\"], [\"Per hour\", \"$28\"]],\n  },\n  {\n    label: \"Boathouse\",\n    img: \"https://images.unsplash.com/photo-1470770841072-f978cf4d019e?auto=format&fit=crop&w=1600&q=80\",\n    thumb: \"https://images.unsplash.com/photo-1470770841072-f978cf4d019e?auto=format&fit=crop&w=200&q=80\",\n    alt: \"A timber boathouse on stilts over a green lake with cloud on the mountains behind\",\n    headline: [\"On stilts\", \"since 1934.\"],\n    copy: \"Nineteen boats sleep under one shingle roof. Come by after four and watch Ilse oil the oars for the morning.\",\n    facts: [[\"Boats\", \"19\"], [\"Open\", \"Apr to Oct\"], [\"Varnished\", \"Each March\"]],\n  },\n  {\n    label: \"Routes\",\n    img: \"https://images.unsplash.com/photo-1465056836041-7f43ac27dcb5?auto=format&fit=crop&w=1600&q=80\",\n    thumb: \"https://images.unsplash.com/photo-1465056836041-7f43ac27dcb5?auto=format&fit=crop&w=200&q=80\",\n    alt: \"A long still lake at sunset with a snow covered mountain range on the far shore\",\n    headline: [\"Eleven kilometres\", \"of quiet water.\"],\n    copy: \"Three marked routes, from a forty minute loop of the reed beds to the full length of the lake with lunch at the far hut.\",\n    facts: [[\"Short loop\", \"40 min\"], [\"Far hut\", \"3 h 10\"], [\"Buoys\", \"Each 500 m\"]],\n  },\n  {\n    label: \"Journal\",\n    img: \"https://images.unsplash.com/photo-1493246507139-91e8fad9978e?auto=format&fit=crop&w=1600&q=80\",\n    thumb: \"https://images.unsplash.com/photo-1493246507139-91e8fad9978e?auto=format&fit=crop&w=200&q=80\",\n    alt: \"Mountain peaks lit orange by sunrise and mirrored in a calm blue lake\",\n    headline: [\"Notes from\", \"the far shore.\"],\n    copy: \"What the lake did this week, written at the bench by the slipway. Ice out dates, first swifts, the morning the fog stayed.\",\n    facts: [[\"Latest\", \"First frost\"], [\"Written by\", \"Ilse Brandt\"], [\"Entries\", \"212\"]],\n  },\n];\n\nconst brand = \"Tarnside Boats\";\nconst CYCLE_MS = 3600; // how long the preview rests on each link until someone touches the menu\nconst SPRING = { type: \"spring\", stiffness: 380, damping: 34 } as const;\nconst ring = \"focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-black/40\";\n\nfunction BoatMark() {\n  return (\n    <svg viewBox=\"0 0 28 28\" className=\"h-7 w-7\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M3 17c3 4 7 6 11 6s8-2 11-6Z\" />\n      <path d=\"M14 17V4\" />\n      <path d=\"M14 5c3 1 5 4 6 8h-6\" />\n    </svg>\n  );\n}\n\nexport default function NavbarWithCenteredLinksAndMobileMenu() {\n  const reduce = useReducedMotion();\n  const root = useRef<HTMLElement>(null);\n  const menuButton = useRef<HTMLButtonElement>(null);\n  const inView = useInView(root, { amount: 0.3 });\n  // The page being viewed, the link being previewed (hover or focus) and whether the preview still plays by itself.\n  const [current, setCurrent] = useState(0);\n  const [peek, setPeek] = useState<number | null>(null);\n  const [demo, setDemo] = useState(true);\n  // Starts open so a phone preview shows the menu. Set to false on a real site.\n  const [open, setOpen] = useState(true);\n\n  const shown = peek ?? current;\n  const page = links[shown];\n  const playing = demo && !reduce && inView;\n\n  useEffect(() => {\n    if (!playing) return;\n    const id = window.setInterval(() => setCurrent((c) => (c + 1) % links.length), CYCLE_MS);\n    return () => window.clearInterval(id);\n  }, [playing]);\n\n  const choose = (i: number) => {\n    setDemo(false);\n    setCurrent(i);\n    setPeek(null);\n  };\n  const preview = (i: number | null) => {\n    if (i !== null) setDemo(false);\n    setPeek(i);\n  };\n  const onMenuKey = (e: KeyboardEvent<HTMLDivElement>) => {\n    if (e.key !== \"Escape\") return;\n    setOpen(false);\n    menuButton.current?.focus();\n  };\n\n  return (\n    <section ref={root} className=\"relative isolate overflow-hidden bg-[#0b1d24] text-white\">\n      <style>{`\n        @keyframes navbar-with-centered-links-and-mobile-menu-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }\n        @keyframes navbar-with-centered-links-and-mobile-menu-drift { from { transform: scale(1.04) translate3d(0, 0, 0); } to { transform: scale(1.12) translate3d(-1%, -1%, 0); } }\n        .navbar-with-centered-links-and-mobile-menu-fill { transform-origin: left; animation: navbar-with-centered-links-and-mobile-menu-fill ${CYCLE_MS}ms linear both; }\n        .navbar-with-centered-links-and-mobile-menu-drift { animation: navbar-with-centered-links-and-mobile-menu-drift 14s ease-out both; }\n        @media (prefers-reduced-motion: reduce) {\n          .navbar-with-centered-links-and-mobile-menu-fill, .navbar-with-centered-links-and-mobile-menu-drift { animation: none; }\n        }\n      `}</style>\n\n      {/* Every link's photograph is stacked here; only the shown one is opaque. */}\n      <div className=\"absolute inset-0 -z-10\">\n        {links.map((l, i) => (\n          <motion.div key={l.label} className=\"absolute inset-0\" initial={false} animate={{ opacity: i === shown ? 1 : 0 }} transition={reduce ? { duration: 0 } : { duration: 0.6, ease: [0.22, 1, 0.36, 1] }}>\n            <img\n              key={i === shown ? \"on\" : \"off\"}\n              src={l.img}\n              alt={i === shown ? l.alt : \"\"}\n              width={1600}\n              height={1067}\n              loading=\"lazy\"\n              className={`h-full w-full object-cover ${i === shown ? \"navbar-with-centered-links-and-mobile-menu-drift\" : \"scale-105\"}`}\n            />\n          </motion.div>\n        ))}\n        <div className=\"absolute inset-x-0 top-0 h-44 bg-gradient-to-b from-[#06141a]/80 via-[#06141a]/35 to-transparent\" aria-hidden=\"true\" />\n        <div className=\"absolute inset-x-0 bottom-0 h-[70%] bg-gradient-to-t from-[#06141a]/90 via-[#06141a]/45 to-transparent\" aria-hidden=\"true\" />\n      </div>\n\n      <div className=\"relative mx-auto flex min-h-[680px] max-w-7xl flex-col px-5 sm:px-8 lg:min-h-[700px]\">\n        {/* The bar: three columns, so the links sit in the true centre whatever the two sides weigh. */}\n        <header className=\"relative z-20 grid h-20 grid-cols-[1fr_auto] items-center border-b border-white/20 md:grid-cols-[1fr_auto_1fr]\">\n          <a href=\"#\" className={`flex w-fit items-center gap-2.5 rounded-full text-[15px] font-semibold tracking-tight ${ring}`}>\n            <BoatMark />\n            {brand}\n          </a>\n\n          <nav aria-label=\"Main\" className=\"hidden md:block\" onPointerLeave={() => setPeek(null)}>\n            <ul className=\"flex items-center\">\n              {links.map((l, i) => (\n                <li key={l.label}>\n                  <a\n                    href=\"#\"\n                    aria-current={i === current ? \"page\" : undefined}\n                    onClick={(e) => {\n                      e.preventDefault();\n                      choose(i);\n                    }}\n                    onPointerEnter={(e) => e.pointerType === \"mouse\" && preview(i)}\n                    onFocus={() => preview(i)}\n                    onBlur={() => setPeek(null)}\n                    className={`relative flex h-20 items-center px-5 text-sm font-medium transition-colors duration-300 ${ring} ${i === shown ? \"text-white\" : \"text-white/80 hover:text-white\"}`}\n                  >\n                    {l.label}\n                    {i === shown && (\n                      <motion.span layoutId=\"navbar-with-centered-links-and-mobile-menu-marker\" transition={reduce ? { duration: 0 } : SPRING} className=\"absolute inset-x-5 -bottom-px h-[3px] overflow-hidden rounded-full bg-white/40\" aria-hidden=\"true\">\n                        {/* While the preview plays, the marker doubles as the timer for the next link. */}\n                        <span key={shown} className={`block h-full w-full rounded-full bg-[#ffd9a0] ${playing ? \"navbar-with-centered-links-and-mobile-menu-fill\" : \"\"}`} />\n                      </motion.span>\n                    )}\n                  </a>\n                </li>\n              ))}\n            </ul>\n          </nav>\n\n          <div className=\"flex items-center justify-end gap-1\">\n            <a href=\"#\" className={`hidden h-10 items-center rounded-full px-4 text-sm font-medium text-white transition-opacity hover:opacity-80 md:inline-flex ${ring}`}>\n              Sign in\n            </a>\n            <a href=\"#\" className={`hidden h-10 items-center gap-2 rounded-full bg-[#fff4e2] pl-4 pr-1.5 text-sm font-semibold text-[#0b1d24] shadow-lg shadow-black/25 transition-transform hover:-translate-y-0.5 md:inline-flex ${ring}`}>\n              Book a boat\n              <span className=\"flex h-7 w-7 items-center justify-center rounded-full bg-[#0b1d24] text-[#fff4e2]\">\n                <svg viewBox=\"0 0 20 20\" className=\"h-3.5 w-3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M4 10h12M11 5l5 5-5 5\" /></svg>\n              </span>\n            </a>\n            <button\n              ref={menuButton}\n              type=\"button\"\n              aria-expanded={open}\n              aria-controls=\"navbar-with-centered-links-and-mobile-menu-panel\"\n              aria-label={open ? \"Close menu\" : \"Open menu\"}\n              onClick={() => setOpen(!open)}\n              className={`relative flex h-11 w-11 items-center justify-center rounded-full border border-white/30 bg-white/10 backdrop-blur-md md:hidden ${ring}`}\n            >\n              <span aria-hidden=\"true\" className={`absolute h-0.5 w-5 rounded-full bg-white transition-transform duration-300 motion-reduce:transition-none ${open ? \"rotate-45\" : \"-translate-y-[5px]\"}`} />\n              <span aria-hidden=\"true\" className={`absolute h-0.5 w-5 rounded-full bg-white transition-transform duration-300 motion-reduce:transition-none ${open ? \"-rotate-45\" : \"translate-y-[5px]\"}`} />\n            </button>\n          </div>\n        </header>\n\n        {/* Phone menu: a sheet of dark glass that drops from the bar, one photo row per link. */}\n        <AnimatePresence initial={false}>\n          {open && (\n            <motion.div\n              id=\"navbar-with-centered-links-and-mobile-menu-panel\"\n              onKeyDown={onMenuKey}\n              initial={reduce ? { opacity: 0 } : { opacity: 0, y: -14, scale: 0.98 }}\n              animate={{ opacity: 1, y: 0, scale: 1 }}\n              exit={reduce ? { opacity: 0 } : { opacity: 0, y: -10, scale: 0.98, transition: { duration: 0.16 } }}\n              transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 320, damping: 30 }}\n              className=\"absolute inset-x-3 top-[88px] z-30 origin-top rounded-[28px] border border-white/20 bg-[#06141a]/75 p-2 shadow-[0_30px_60px_-20px_rgba(0,0,0,0.7),inset_0_1px_0_rgba(255,255,255,0.18)] backdrop-blur-2xl md:hidden\"\n            >\n              <nav aria-label=\"Mobile\">\n                <ul>\n                  {links.map((l, i) => (\n                    <li key={l.label}>\n                      <a\n                        href=\"#\"\n                        aria-current={i === current ? \"page\" : undefined}\n                        onClick={(e) => {\n                          e.preventDefault();\n                          choose(i);\n                        }}\n                        className={`flex items-center gap-3 rounded-[20px] p-2 pr-4 transition-colors ${ring} ${i === current ? \"bg-white/15\" : \"hover:bg-white/10\"}`}\n                      >\n                        <img src={l.thumb} alt=\"\" width={56} height={56} loading=\"lazy\" className=\"h-14 w-14 flex-none rounded-2xl object-cover\" />\n                        <span className=\"min-w-0 flex-1\">\n                          <span className=\"block text-lg font-medium tracking-tight\">{l.label}</span>\n                          <span className=\"block truncate text-[13px] text-white/80\">{l.headline.join(\" \")}</span>\n                        </span>\n                        <span className={`h-2 w-2 flex-none rounded-full ${i === current ? \"bg-[#ffd9a0]\" : \"bg-white/25\"}`} aria-hidden=\"true\" />\n                      </a>\n                    </li>\n                  ))}\n                </ul>\n              </nav>\n              <div className=\"mt-2 grid grid-cols-2 gap-2 border-t border-white/15 p-2 pt-3\">\n                <a href=\"#\" className={`flex h-12 items-center justify-center rounded-full border border-white/30 text-sm font-semibold ${ring}`}>Sign in</a>\n                <a href=\"#\" className={`flex h-12 items-center justify-center rounded-full bg-[#fff4e2] text-sm font-semibold text-[#0b1d24] ${ring}`}>Book a boat</a>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n\n        {/* The slice of page under the bar. It follows whichever link is shown. */}\n        <div className=\"mt-auto grid items-end gap-8 pb-8 pt-40 sm:pb-12 lg:grid-cols-[1fr_auto] lg:gap-16\">\n          <div aria-live=\"polite\">\n            <AnimatePresence mode=\"wait\" initial={false}>\n              <motion.div\n                key={shown}\n                initial={reduce ? { opacity: 0 } : { opacity: 0, y: 18, filter: \"blur(6px)\" }}\n                animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n                exit={reduce ? { opacity: 0 } : { opacity: 0, y: -10, transition: { duration: 0.12 } }}\n                transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 260, damping: 28 }}\n              >\n                <p className=\"flex items-center gap-3 text-[11px] font-semibold uppercase tracking-[0.3em] text-[#ffd9a0]\">\n                  <span className=\"tabular-nums\">0{shown + 1} / 0{links.length}</span>\n                  <span className=\"h-px w-10 bg-[#ffd9a0]/70\" aria-hidden=\"true\" />\n                  {page.label}\n                </p>\n                <h1 className=\"mt-5 text-[clamp(2.6rem,7.4vw,6.4rem)] font-light leading-[0.94] tracking-[-0.045em]\">\n                  {page.headline.map((line) => (\n                    <span key={line} className=\"block\">{line}</span>\n                  ))}\n                </h1>\n                <p className=\"mt-6 max-w-md text-[15px] leading-relaxed text-white/90 sm:text-base\">{page.copy}</p>\n              </motion.div>\n            </AnimatePresence>\n          </div>\n\n          <dl className=\"grid grid-cols-3 overflow-hidden rounded-3xl border border-white/25 bg-gradient-to-br from-white/20 to-white/5 shadow-[0_24px_60px_-24px_rgba(0,0,0,0.7),inset_0_1px_0_rgba(255,255,255,0.3)] backdrop-blur-xl lg:w-[420px]\">\n            {page.facts.map(([label, value], i) => (\n              <div key={`${shown}-${label}`} className={`min-w-0 px-4 py-4 sm:px-5 ${i > 0 ? \"border-l border-white/15\" : \"\"}`}>\n                <dt className=\"truncate text-[11px] font-medium uppercase tracking-[0.16em] text-white/80\">{label}</dt>\n                <dd className=\"mt-2 truncate text-base font-medium tabular-nums tracking-tight sm:text-lg\">{value}</dd>\n              </div>\n            ))}\n          </dl>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
