Skip to content

Marketing header

A header that is part of the page at the top, then shrinks into a frosted pill, with a phone menu that opens from it.

89 lines · React · Tailwind 4

Install

$ bunx shadcn@latest add @blocco/marketing-header

Code

blocks/free/marketing-header.tsx89 lines
import { useState } from "react";
import { buttonClass } from "@/registry/blocco/ui/button-class";
import { cn } from "@/registry/blocco/ui/cn";
import { SiteHeader, type SiteHeaderLink } from "@/registry/blocco/ui/site-header";

/** What "Product" opens. Each says in a few words why you would go there. */
const PRODUCT_LINKS = [
  { href: "#links", label: "Branded links", hint: "On your own domain" },
  { href: "#qr", label: "QR codes", hint: "Free, with your logo" },
  { href: "#analytics", label: "Analytics", hint: "Where clicks come from" },
  { href: "#api", label: "API", hint: "Create links from code" },
  { href: "#roadmap", label: "Roadmap", hint: "What we build next" },
  { href: "#changelog", label: "Changelog", hint: "What shipped, and when" },
];

const MAIN_LINKS = [
  { href: "#pricing", label: "Pricing", hint: "Free, then $9 a month" },
  { href: "#docs", label: "Docs", hint: "Guides and the API" },
  { href: "#blog", label: "Blog", hint: "Notes and guides" },
];

function Logo() {
  return (
    <span className="inline-flex items-center gap-[0.4em] font-bold tracking-tight">
      <svg viewBox="0 0 24 18" aria-hidden="true" className="h-[0.9em] w-auto">
        <circle cx="8" cy="9" r="7" fill="currentColor" />
        <circle cx="16" cy="9" r="7" className="fill-accent" opacity="0.9" />
      </svg>
      Acme
    </span>
  );
}

/** The header above a page tall enough to scroll, so the pill can be seen floating. */
export default function MarketingHeader() {
  const [current, setCurrent] = useState("");
  const mark = (links: Omit<SiteHeaderLink, "current">[]) =>
    links.map((l) => ({ ...l, current: l.href === current }));
  const big = "rounded-full py-3 text-base";
  return (
    <div id="top" className="min-h-[150vh] pt-2">
      <SiteHeader
        logo={<Logo />}
        logoHref="#top"
        menu={{ label: "Product", links: mark(PRODUCT_LINKS) }}
        links={mark(MAIN_LINKS)}
        onNavigate={(href, e) => {
          e.preventDefault();
          setCurrent(href === "#top" ? "" : href);
        }}
        actions={
          <>
            <a
              href="#login"
              className="hidden rounded-full px-3 py-2 whitespace-nowrap text-muted transition-colors hover:text-text sm:block"
            >
              Log in
            </a>
            <a
              href="#signup"
              className={cn(buttonClass({ variant: "primary" }), "rounded-full px-4")}
            >
              Sign up
            </a>
          </>
        }
        phoneActions={
          <>
            <a href="#login" className={cn(buttonClass({ variant: "outline" }), big)}>
              Log in
            </a>
            <a href="#signup" className={cn(buttonClass({ variant: "primary" }), big)}>
              Get started
            </a>
          </>
        }
      />
      <main className="mx-auto max-w-3xl px-6 pt-20 text-center">
        <h1 className="text-4xl font-bold tracking-tight text-balance sm:text-5xl">
          Links your team can find again.
        </h1>
        <p className="mx-auto mt-5 max-w-xl text-lg text-pretty text-muted">
          Scroll the page: the header shrinks into a pill and stays in reach.
        </p>
      </main>
    </div>
  );
}