{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "site-header-island",
  "title": "Site header island",
  "description": "A marketing site’s header that floats: once the page scrolls, the logo, the menus and the actions draw in together and a bar forms around them, held off the top. On a phone the menus open in a sheet.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/badge.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/site-header-parts.json",
    "https://kinoui.com/r/skeleton.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/site-header-island/site-header-island.tsx",
      "content": "'use client'\n\nimport { withoutTransition } from '@/registry/lib/resize'\nimport {\n  SiteHeaderNav,\n  siteHeaderActionsClassName,\n  siteHeaderColumnClassName,\n  siteHeaderMenuClassName,\n  siteHeaderNavClassName,\n  SiteHeaderPhoneMenu,\n  type SiteHeaderProps,\n  useHeaderFit,\n  useHeaderScroll,\n} from '@/registry/lib/site-header-parts'\nimport { type RefObject, useEffect, useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A marketing site's header that floats. Over the top of the page its logo,\n * menus and actions sit on the page's own edges, the menus centred; once the\n * page scrolls they draw in together and a floating bar forms around them, held off\n * the top, so the page reads past it on both sides. On a phone the menus\n * open in a sheet from the side.\n *\n *   <SiteHeaderIsland\n *     logo={<a href='/' aria-label='Kino, home'><Logo /></a>}\n *     items={[{ label: 'Product', links: [...] }, { label: 'Pricing', href: '/pricing' }]}\n *     actions={<a href='/signup' className={buttonVariants()}>Get started</a>}\n *   />\n */\nfunction SiteHeaderIsland({\n  logo,\n  items,\n  actions,\n  label = 'Main',\n  className,\n  ...props\n}: SiteHeaderProps) {\n  const header = useRef<HTMLElement>(null)\n  const row = useRef<HTMLDivElement>(null)\n  useHeaderScroll(header, { draws: true })\n  useHeaderFit(header)\n  useIslandLayout(row)\n  // Each part draws in, towards the middle whichever way the text reads.\n  const drawIn =\n    'transition-[translate] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none'\n  return (\n    <header\n      ref={header}\n      data-slot='site-header'\n      className={cn(\n        // Only its parts take the pointer, so the page beside the drawn-in bar can be used.\n        '@container/site-header group/header pointer-events-none sticky top-0 z-40 w-full min-w-0 pt-2',\n        className,\n      )}\n      {...props}\n    >\n      <div className={siteHeaderColumnClassName}>\n        <div\n          ref={row}\n          className='relative isolate grid h-14 grid-cols-[1fr_auto_1fr] items-center gap-6 [--site-header-inset:0px] [--site-header-nav-shift:0px]'\n        >\n          {/*\n           * The bar, as wide as the row and a margin past it: clipped in to\n           * the drawn-in parts while the page is scrolled, so it forms around\n           * them on the compositor, with nothing laid out again.\n           */}\n          <div\n            aria-hidden\n            className='bg-background/80 ring-foreground/12 pointer-events-none absolute -inset-x-3 inset-y-0 -z-10 rounded-[calc(var(--control-radius)+--spacing(3))] opacity-0 shadow-lg shadow-black/8 ring-1 backdrop-blur-lg transition-[opacity,clip-path] duration-(--motion-layout-duration) ease-[var(--motion-layout-fade-easing),var(--motion-layout-easing)] [clip-path:inset(0_0_round_calc(var(--control-radius)+--spacing(3)))] group-data-scrolled/header:opacity-100 group-data-drawn/header:[clip-path:inset(0_var(--site-header-inset)_round_calc(var(--control-radius)+--spacing(3)))] group-has-[[aria-haspopup][aria-expanded=true]]/header:opacity-100 motion-reduce:transition-[opacity] dark:shadow-black/40 forced-colors:bg-[Canvas]'\n          />\n          <div\n            data-site-header-part='start'\n            className={cn(\n              'pointer-events-auto flex min-w-0 items-center justify-self-start',\n              drawIn,\n              'group-data-drawn/header:translate-x-(--site-header-inset) rtl:group-data-drawn/header:-translate-x-(--site-header-inset)',\n            )}\n          >\n            {logo}\n          </div>\n          <div\n            data-site-header-part='nav'\n            className={cn(\n              'pointer-events-auto min-w-0',\n              drawIn,\n              'group-data-drawn/header:translate-x-(--site-header-nav-shift) rtl:group-data-drawn/header:-translate-x-(--site-header-nav-shift)',\n            )}\n          >\n            <SiteHeaderNav\n              items={items}\n              label={label}\n              className={siteHeaderNavClassName}\n            />\n          </div>\n          <div\n            data-site-header-part='end'\n            className={cn(\n              'pointer-events-auto flex items-center gap-2 justify-self-end',\n              drawIn,\n              'group-data-drawn/header:-translate-x-(--site-header-inset) rtl:group-data-drawn/header:translate-x-(--site-header-inset)',\n            )}\n          >\n            {actions ? (\n              <div data-site-header-part='actions' className={siteHeaderActionsClassName}>\n                {actions}\n              </div>\n            ) : null}\n            <div className={siteHeaderMenuClassName}>\n              <SiteHeaderPhoneMenu\n                logo={logo}\n                items={items}\n                actions={actions}\n                label={label}\n              />\n            </div>\n          </div>\n        </div>\n      </div>\n    </header>\n  )\n}\n\n/**\n * Measures where each part of the row draws in to, as the variables\n * `--site-header-inset` (each end, and the bar's clip) and\n * `--site-header-nav-shift`, again whenever any part changes size.\n */\nfunction useIslandLayout(ref: RefObject<HTMLDivElement | null>) {\n  useEffect(() => {\n    const row = ref.current\n    if (!row) return\n    const part = (name: string) =>\n      row.querySelector<HTMLElement>(`:scope > [data-site-header-part=${name}]`)\n    const start = part('start')\n    const nav = part('nav')\n    const end = part('end')\n    if (!start || !nav || !end) return\n    const measure = () => {\n      // Where the menus start at rest, from the row's start edge whichever way the text reads.\n      const rtl = getComputedStyle(row).direction === 'rtl'\n      const navAt = rtl\n        ? row.clientWidth - nav.offsetLeft - nav.offsetWidth\n        : nav.offsetLeft\n      const layout = islandLayout({\n        row: row.clientWidth,\n        start: start.offsetWidth,\n        nav: nav.offsetWidth,\n        navAt,\n        end: end.offsetWidth,\n        gap: Number.parseFloat(getComputedStyle(row).columnGap) || 0,\n      })\n      row.style.setProperty('--site-header-inset', `${layout.inset}px`)\n      row.style.setProperty('--site-header-nav-shift', `${layout.navShift}px`)\n    }\n    // The first places them where the page already is, with nothing moving.\n    withoutTransition(row, measure, { subtree: true })\n    const observer = new ResizeObserver(measure)\n    for (const each of [row, start, nav, end]) observer.observe(each)\n    return () => observer.disconnect()\n  }, [ref])\n}\n\n/**\n * Where a row's parts sit once drawn in: side by side, a `gap` apart, as one\n * group centred in the row. `inset` is how far each end moves in from its\n * edge, and `navShift` how far the menus move from where they rest, `navAt`\n * from the row's start, towards the end, so they sit beside the start. Never drawn out past the edges,\n * where the row has no room to spare, and not at all without the menus,\n * on a phone. Widths in pixels, towards the end\n * whichever way the text reads.\n */\nfunction islandLayout({\n  row,\n  start,\n  nav,\n  navAt,\n  end,\n  gap,\n}: {\n  row: number\n  start: number\n  nav: number\n  navAt: number\n  end: number\n  gap: number\n}): { inset: number; navShift: number } {\n  // On a phone the menus are in the menu: the ends stay put and the bar spans the row.\n  if (nav === 0) return { inset: 0, navShift: 0 }\n  // A part with nothing in it, such as no actions, takes no gap.\n  const parts = [start, nav, end].filter((width) => width > 0)\n  const group = start + nav + end + gap * (parts.length - 1)\n  const inset = Math.max(0, Math.floor((row - group) / 2))\n  // The menus' start once drawn in, less where they rest.\n  const navShift = inset + start + gap - navAt\n  return { inset, navShift: inset === 0 ? 0 : Math.round(navShift) }\n}\n\nexport { islandLayout, SiteHeaderIsland }\n",
      "type": "registry:component",
      "target": "@components/kino/site-header-island/site-header-island.tsx"
    }
  ],
  "type": "registry:block"
}