{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "page-header",
  "title": "Page Header",
  "description": "Primitives for page headers: a heading with a badge, media and description, actions that wrap, a row of key numbers, a back link, section tabs that put what doesn’t fit under More, and a more-actions menu.",
  "registryDependencies": [
    "button",
    "dropdown-menu",
    "https://www.dashboardblocks.com/r/radix/link.json",
    "https://www.dashboardblocks.com/r/radix/tag.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/page-header.tsx",
      "content": "'use client'\n\nimport { Link } from '@/registry/components/dashboardblocks/link'\nimport { renderTag, Tag } from '@/registry/components/dashboardblocks/tag'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Fragment,\n  isValidElement,\n  type ReactNode,\n  useEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuSeparator,\n  DropdownMenuTrigger,\n} from '@/components/ui/dropdown-menu'\n\nimport { cn } from '@/lib/utils'\n\nfunction PageHeader({\n  children,\n  className,\n}: {\n  children: ReactNode\n  className?: string\n}) {\n  return (\n    <header className={cn('@container/page-header flex flex-col gap-4', className)}>\n      {children}\n    </header>\n  )\n}\n\nfunction PageHeaderRow({\n  children,\n  className,\n}: {\n  children: ReactNode\n  className?: string\n}) {\n  return (\n    <div\n      className={cn(\n        'flex flex-col gap-4 @2xl/page-header:flex-row @2xl/page-header:items-start @2xl/page-header:justify-between',\n        className,\n      )}\n    >\n      {children}\n    </div>\n  )\n}\n\ninterface PageHeaderHeadingProps {\n  badge?: ReactNode\n  className?: string\n  description?: ReactNode\n  media?: ReactNode\n  title: ReactNode\n  wrap?: boolean\n}\n\nfunction PageHeaderHeading({\n  badge,\n  className,\n  description,\n  media,\n  title,\n  wrap = false,\n}: PageHeaderHeadingProps) {\n  return (\n    <div className={cn('flex min-w-0 items-start gap-3', className)}>\n      {media}\n      <div className='flex min-w-0 flex-col gap-0.5'>\n        <div className='flex min-w-0 flex-wrap items-center gap-2'>\n          <h1\n            className={cn(\n              'text-2xl font-semibold tracking-tight',\n              wrap ? 'break-words text-balance' : 'truncate',\n            )}\n          >\n            {title}\n          </h1>\n          {badge}\n        </div>\n        {description && (\n          <p className='text-muted-foreground text-sm text-pretty'>{description}</p>\n        )}\n      </div>\n    </div>\n  )\n}\n\nfunction PageHeaderActions({\n  children,\n  className,\n}: {\n  children: ReactNode\n  className?: string\n}) {\n  return (\n    <div className={cn('flex shrink-0 flex-wrap items-center gap-2', className)}>\n      {children}\n    </div>\n  )\n}\n\ninterface PageHeaderFact {\n  detail?: ReactNode\n  label: string\n  value: ReactNode\n}\n\nfunction PageHeaderFacts({\n  className,\n  items,\n}: {\n  className?: string\n  items: PageHeaderFact[]\n}) {\n  return (\n    <dl\n      className={cn(\n        'grid gap-x-6 gap-y-4 border-t pt-4 @2xl/page-header:flex @2xl/page-header:gap-x-12',\n        items.length === 3 ? 'grid-cols-3' : 'grid-cols-2',\n        className,\n      )}\n    >\n      {items.map((item) => (\n        <div key={item.label} className='flex min-w-0 flex-col gap-1'>\n          <dt className='text-muted-foreground text-sm'>{item.label}</dt>\n          <dd className='text-2xl font-light tracking-tight tabular-nums'>\n            {item.value}\n          </dd>\n          {item.detail && (\n            <dd className='text-muted-foreground text-xs text-pretty'>{item.detail}</dd>\n          )}\n        </div>\n      ))}\n    </dl>\n  )\n}\n\nfunction BackLink({\n  children,\n  className,\n  href,\n}: {\n  children: ReactNode\n  className?: string\n  href: string\n}) {\n  return (\n    <Link\n      href={href}\n      className={cn(\n        'text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 inline-flex w-fit items-center gap-1 rounded-md text-sm outline-none focus-visible:ring-[3px] [&_svg]:size-4 [&_svg]:shrink-0',\n        className,\n      )}\n    >\n      <IconPlaceholder\n        lucide='ChevronLeftIcon'\n        tabler='IconChevronLeft'\n        hugeicons='ArrowLeft01Icon'\n        phosphor='CaretLeftIcon'\n        remixicon='RiArrowLeftSLine'\n      />\n      {children}\n    </Link>\n  )\n}\n\ninterface PageTab {\n  badge?: ReactNode\n  href: string\n  /** Shown before the title. */\n  icon?: ReactNode\n  /** The link's id, for a page that moves focus to the tab, such as after it saved a view. */\n  id?: string\n  /** Shown after the title, such as a dot for a view with changes that aren't saved yet. */\n  indicator?: ReactNode\n  title: string\n}\n\nfunction PageTabs({\n  className,\n  items,\n  label = 'Sections',\n  pathname,\n}: {\n  className?: string\n  items: PageTab[]\n  label?: string\n  pathname: string\n}) {\n  return (\n    <nav aria-label={label} className={cn('border-b', className)}>\n      <TabLinks items={items} pathname={pathname} />\n    </nav>\n  )\n}\n\ninterface TabLinksProps {\n  className?: string\n  /** @default the tab whose href is the pathname */\n  isActive?: (href: string) => boolean\n  items: PageTab[]\n  pathname: string\n  /** `pill` fills the open tab, for a row of tabs in a bar. @default 'line' */\n  variant?: 'line' | 'pill'\n}\n\nconst tabBase =\n  'text-muted-foreground hover:text-foreground data-active:text-foreground aria-expanded:text-foreground focus-visible:ring-ring/50 flex shrink-0 items-center gap-1.5 text-sm font-medium whitespace-nowrap outline-none focus-visible:ring-[3px] focus-visible:ring-inset [&_svg]:size-4 [&_svg]:shrink-0'\n\nconst tabClasses = {\n  line: cn(\n    tabBase,\n    'data-active:border-foreground rounded-t-md border-b-2 border-transparent px-3 py-2.5',\n  ),\n  pill: cn(\n    tabBase,\n    'hover:bg-sidebar-accent/40 aria-expanded:bg-sidebar-accent/40 data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground h-8 rounded-md px-3 transition-colors',\n  ),\n}\n\n/** How many tabs More holds, in the tone of the most urgent tag among them, so a warning doesn't hide under More. */\nfunction hiddenCount(hidden: PageTab[]) {\n  const tones = hidden.map((item) =>\n    isValidElement<{ tone?: string }>(item.badge) ? item.badge.props.tone : undefined,\n  )\n  const tone = tones.includes('bad')\n    ? 'bad'\n    : tones.includes('warning')\n      ? 'warning'\n      : undefined\n  return tone ? <Tag tone={tone}>{formatNumber(hidden.length)}</Tag> : hidden.length\n}\n\nfunction TabLinks({\n  className,\n  isActive,\n  items,\n  pathname,\n  variant = 'line',\n}: TabLinksProps) {\n  const active = (href: string) => (isActive ? isActive(href) : href === pathname)\n  const activeHref = items.find((item) => active(item.href))?.href\n  const [rail, hiddenHrefs] = useHiddenRailItems<HTMLDivElement>(activeHref, items)\n  const hidden = items.filter((item) => hiddenHrefs.includes(item.href))\n\n  return (\n    <div\n      ref={rail}\n      className={cn(\n        'relative flex min-w-0 gap-1 overflow-hidden',\n        variant === 'line' && '-mb-px',\n        className,\n      )}\n    >\n      {items.map((item) => (\n        <Link\n          key={item.href}\n          id={item.id}\n          href={item.href}\n          aria-current={item.href === pathname ? 'page' : undefined}\n          data-active={active(item.href) || undefined}\n          data-rail='item'\n          data-rail-id={item.href}\n          className={cn(\n            tabClasses[variant],\n            hiddenHrefs.includes(item.href) && 'invisible absolute',\n          )}\n        >\n          {item.icon}\n          {item.title}\n          {item.indicator}\n          {item.badge !== undefined && renderTag(item.badge)}\n        </Link>\n      ))}\n      {hidden.length > 0 && (\n        <div\n          data-rail='more'\n          className='text-muted-foreground flex shrink-0 items-center'\n        >\n          <ActionsMenu\n            count={hiddenCount(hidden)}\n            items={hidden.map((item) => ({\n              badge: item.badge,\n              href: item.href,\n              icon: item.icon,\n              label: item.title,\n            }))}\n            triggerClassName={tabClasses[variant]}\n          >\n            More\n          </ActionsMenu>\n        </div>\n      )}\n    </div>\n  )\n}\n\nconst RAIL_MORE_WIDTH = 96\n\n/**\n * The ids of a rail's items that don't fit beside its More menu, keeping the\n * active one shown. Each item has `data-rail='item'` and a `data-rail-id`;\n * what always shows has `data-rail='fixed'`, and the menu `data-rail='more'`.\n */\nfunction getHiddenRailItems(rail: HTMLElement, activeId: string | undefined) {\n  const gap = Number.parseFloat(getComputedStyle(rail).columnGap) || 0\n  const parts = (kind: string) => [\n    ...rail.querySelectorAll<HTMLElement>(`:scope > [data-rail='${kind}']`),\n  ]\n  const items = parts('item').map((item) => ({\n    id: item.dataset.railId ?? '',\n    width: item.offsetWidth,\n  }))\n  const fixed = parts('fixed').reduce((sum, item) => sum + item.offsetWidth + gap, 0)\n  const ordered = [\n    ...items.filter((item) => item.id === activeId),\n    ...items.filter((item) => item.id !== activeId),\n  ]\n  const hiddenIn = (room: number) => {\n    let used = fixed\n    const shown = new Set<string>()\n    for (const item of ordered) {\n      if (used + item.width > room) break\n      used += item.width + gap\n      shown.add(item.id)\n    }\n    return items.filter((item) => !shown.has(item.id)).map((item) => item.id)\n  }\n  if (hiddenIn(rail.clientWidth).length === 0) return []\n  const more = parts('more')[0]?.offsetWidth ?? RAIL_MORE_WIDTH\n  return hiddenIn(rail.clientWidth - more - gap)\n}\n\n/** Measures the rail on every resize and when `items` change; see `getHiddenRailItems`. */\nfunction useHiddenRailItems<T extends HTMLElement>(\n  activeId: string | undefined,\n  items: unknown,\n) {\n  const rail = useRef<T>(null)\n  const [hidden, setHidden] = useState<string[]>([])\n  useEffect(() => {\n    const element = rail.current\n    if (!element) return\n    const observer = new ResizeObserver(() => {\n      const next = getHiddenRailItems(element, activeId)\n      setHidden((current) => (current.join('\\n') === next.join('\\n') ? current : next))\n    })\n    observer.observe(element)\n    return () => observer.disconnect()\n  }, [activeId, items, hidden.length > 0])\n  return [rail, hidden] as const\n}\n\ninterface ActionsMenuItem {\n  /** Shown after the label, such as a count. */\n  badge?: ReactNode\n  /** Makes the item a link. */\n  href?: string\n  icon?: ReactNode\n  label: string\n  onSelect?: () => void\n  variant?: 'default' | 'destructive'\n}\n\nfunction ActionsMenu({\n  children,\n  className,\n  count,\n  disabled = false,\n  icon,\n  id,\n  items,\n  label = 'More actions',\n  size = 'icon',\n  triggerClassName,\n  variant = 'outline',\n}: {\n  /** A text trigger, such as \"More\", in place of the icon button. */\n  children?: ReactNode\n  /** Classes for the trigger, such as showing it only while its row is hovered. */\n  className?: string\n  /** Shown as a tag after a text trigger, such as how many items the menu holds: a number, or a `Tag` with a tone. */\n  count?: ReactNode\n  disabled?: boolean\n  /** The icon button's icon, such as a chevron for the menu half of a split button. @default an ellipsis */\n  icon?: ReactNode\n  /** The trigger's id, for a page that moves focus back to it, such as after a dialog the menu opened. */\n  id?: string\n  items: ActionsMenuItem[]\n  /** Names the icon button. @default 'More actions' */\n  label?: string\n  /** The icon button's size. @default 'icon' */\n  size?: 'icon' | 'icon-sm' | 'icon-xs'\n  /** Draws a text trigger as plain markup with these classes, such as a tab's, in place of a ghost button. */\n  triggerClassName?: string\n  /** The icon button's variant: the one beside it when it is the menu half of a split button, `ghost` in a row. @default 'outline' */\n  variant?: 'default' | 'ghost' | 'outline' | 'secondary'\n}) {\n  const firstDestructive = items.findIndex((item) => item.variant === 'destructive')\n  const text = (\n    <>\n      {children}\n      {count !== undefined && <> {renderTag(count)}</>}\n      <IconPlaceholder\n        lucide='ChevronDownIcon'\n        tabler='IconChevronDown'\n        hugeicons='ArrowDown01Icon'\n        phosphor='CaretDownIcon'\n        remixicon='RiArrowDownSLine'\n        className='-ms-0.5 transition-transform duration-200 ease-out in-aria-expanded:rotate-180 motion-reduce:transition-none'\n      />\n    </>\n  )\n  return (\n    <DropdownMenu modal={false}>\n      {children && triggerClassName ? (\n        <DropdownMenuTrigger id={id} disabled={disabled} className={triggerClassName}>\n          {text}\n        </DropdownMenuTrigger>\n      ) : children ? (\n        <DropdownMenuTrigger id={id} disabled={disabled} asChild>\n          <Button variant='ghost' size='sm' className={className}>\n            {text}\n          </Button>\n        </DropdownMenuTrigger>\n      ) : (\n        <DropdownMenuTrigger id={id} disabled={disabled} asChild>\n          <Button variant={variant} size={size} aria-label={label} className={className}>\n            {icon ?? (\n              <IconPlaceholder\n                lucide='EllipsisIcon'\n                tabler='IconDots'\n                hugeicons='MoreHorizontalCircle01Icon'\n                phosphor='DotsThreeIcon'\n                remixicon='RiMoreLine'\n              />\n            )}\n          </Button>\n        </DropdownMenuTrigger>\n      )}\n      <DropdownMenuContent align='end' className='w-auto min-w-44'>\n        {items.map((item, index) => (\n          <Fragment key={item.label}>\n            {index === firstDestructive && index > 0 && <DropdownMenuSeparator />}\n            {item.href ? (\n              <DropdownMenuItem variant={item.variant} onClick={item.onSelect} asChild>\n                <Link href={item.href}>\n                  <ActionsMenuItemContent item={item} />\n                </Link>\n              </DropdownMenuItem>\n            ) : (\n              <DropdownMenuItem variant={item.variant} onClick={item.onSelect}>\n                <ActionsMenuItemContent item={item} />\n              </DropdownMenuItem>\n            )}\n          </Fragment>\n        ))}\n      </DropdownMenuContent>\n    </DropdownMenu>\n  )\n}\n\nfunction ActionsMenuItemContent({ item }: { item: ActionsMenuItem }) {\n  return (\n    <>\n      {item.icon}\n      {item.label}\n      {item.badge !== undefined && (\n        <span className='ms-auto flex ps-4'>{renderTag(item.badge)}</span>\n      )}\n    </>\n  )\n}\n\nexport {\n  ActionsMenu,\n  BackLink,\n  PageHeader,\n  PageHeaderActions,\n  PageHeaderFacts,\n  PageHeaderHeading,\n  PageHeaderRow,\n  PageTabs,\n  TabLinks,\n  getHiddenRailItems,\n  useHiddenRailItems,\n}\n\nexport type {\n  ActionsMenuItem,\n  PageHeaderFact,\n  PageHeaderHeadingProps,\n  PageTab,\n  TabLinksProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/page-header.tsx"
    }
  ],
  "type": "registry:component"
}
