{
  "name": "channel-header",
  "type": "registry:ui",
  "framework": "react",
  "title": "Channel Header",
  "description": "The bar above the message list, with the channel name, topic and channel actions.",
  "files": [
    {
      "path": "ui/channel-header.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface ChannelHeaderProps extends React.HTMLAttributes<HTMLElement> {\n  /**\n   * The element to render. `div` by default, because a `header` outside\n   * `main`, `article`, `aside`, `nav` or `section` is a second banner\n   * landmark. Pass `header` when the bar sits inside one of those.\n   */\n  as?: React.ElementType\n}\n\n/* The bar above the message list: channel name, topic, and channel actions. */\nconst ChannelHeader = React.forwardRef<HTMLElement, ChannelHeaderProps>(\n  ({ as: Tag = \"div\", className, ...props }, ref) => (\n    <Tag\n      ref={ref}\n      className={cn(\n        \"flex min-h-12 items-center justify-between gap-3 border-b border-newt-border bg-newt-bg-surface ps-4 pe-3 text-newt-text-primary\",\n        className\n      )}\n      {...props}\n    />\n  )\n)\nChannelHeader.displayName = \"ChannelHeader\"\n\nconst ChannelHeaderInfo = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\"flex min-w-0 items-center gap-2\", className)}\n    {...props}\n  />\n))\nChannelHeaderInfo.displayName = \"ChannelHeaderInfo\"\n\nconst ChannelHeaderIcon = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, children = \"#\", ...props }, ref) => (\n  <span\n    ref={ref}\n    aria-hidden=\"true\"\n    className={cn(\n      \"shrink-0 text-xl font-bold leading-none text-newt-text-muted\",\n      className\n    )}\n    {...props}\n  >\n    {children}\n  </span>\n))\nChannelHeaderIcon.displayName = \"ChannelHeaderIcon\"\n\nconst ChannelHeaderName = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, ...props }, ref) => (\n  <span\n    ref={ref}\n    className={cn(\n      \"min-w-0 truncate text-base font-semibold text-newt-text-primary\",\n      className\n    )}\n    {...props}\n  />\n))\nChannelHeaderName.displayName = \"ChannelHeaderName\"\n\n/* Round dot that sets the topic apart from the channel name. */\nconst ChannelHeaderDivider = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, ...props }, ref) => (\n  <span\n    ref={ref}\n    aria-hidden=\"true\"\n    className={cn(\n      \"h-1 w-1 shrink-0 rounded-full bg-newt-text-muted opacity-70\",\n      className\n    )}\n    {...props}\n  />\n))\nChannelHeaderDivider.displayName = \"ChannelHeaderDivider\"\n\n/*\n * The shrink factor is what makes the topic give way before the name: the\n * name only starts to truncate once the topic has no width left.\n */\nconst ChannelHeaderTopic = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, ...props }, ref) => (\n  <span\n    ref={ref}\n    className={cn(\n      \"min-w-0 shrink-[99999] truncate text-[13px] font-medium text-newt-text-muted\",\n      className\n    )}\n    {...props}\n  />\n))\nChannelHeaderTopic.displayName = \"ChannelHeaderTopic\"\n\nconst ChannelHeaderToolbar = React.forwardRef<\n  HTMLDivElement,\n  React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\"flex shrink-0 items-center gap-4\", className)}\n    {...props}\n  />\n))\nChannelHeaderToolbar.displayName = \"ChannelHeaderToolbar\"\n\n/* What every control of the header adds to its resting look. */\nconst interactiveClassName =\n  \"cursor-pointer transition-colors duration-fast ease-newt focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50\"\n\ninterface ChannelHeaderControlProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n  /**\n   * The element or component to render. Defaults to `button`, or to `a` when\n   * `href` is set; pass a router link component to keep client navigation.\n   * `span` renders the decorative form: hidden from assistive technology, out\n   * of the tab order, with no pointer and no hover.\n   * Its event handlers do not run.\n   */\n  as?: React.ElementType\n  /** Render a link to this URL. */\n  href?: string\n  /**\n   * Turns the control off. A link loses its URL, which takes it out of the\n   * tab order, and says so with `aria-disabled`.\n   */\n  disabled?: boolean\n  /** Link target, with `href`. */\n  target?: React.AnchorHTMLAttributes<HTMLAnchorElement>[\"target\"]\n  /** Link relationship, with `href`. */\n  rel?: string\n}\n\n/* The element a control renders, and whether it is the decorative form. */\nfunction resolveControl(\n  as: React.ElementType | undefined,\n  href: string | undefined\n) {\n  const Tag: React.ElementType = as ?? (href === undefined ? \"button\" : \"a\")\n  return { Tag, isButton: Tag === \"button\", decorative: Tag === \"span\" }\n}\n\n/*\n * The `span` form runs nothing: it drops every event handler, so a click\n * cannot start an action that the keyboard and assistive technology miss.\n */\nfunction withoutHandlers(\n  props: React.HTMLAttributes<HTMLElement>\n): React.HTMLAttributes<HTMLElement> {\n  return Object.fromEntries(\n    Object.entries(props).filter(([name]) => !/^on[A-Z]/.test(name))\n  )\n}\n\nexport interface ChannelHeaderActionProps extends ChannelHeaderControlProps {\n  /**\n   * Makes the action a toggle and keeps it lit up while `true`. A button\n   * reports the value as `aria-pressed`; leave it unset for a plain action.\n   */\n  active?: boolean\n}\n\nconst ChannelHeaderAction = React.forwardRef<\n  HTMLElement,\n  ChannelHeaderActionProps\n>(\n  (\n    { as, href, disabled, className, active, type = \"button\", ...props },\n    ref\n  ) => {\n    const { Tag, isButton, decorative } = resolveControl(as, href)\n    return (\n      <Tag\n        ref={ref}\n        type={isButton ? type : undefined}\n        href={decorative || disabled ? undefined : href}\n        disabled={isButton ? disabled : undefined}\n        aria-disabled={!isButton && !decorative && disabled ? true : undefined}\n        aria-hidden={decorative ? true : undefined}\n        aria-pressed={isButton ? active : undefined}\n        data-state={active ? \"active\" : \"inactive\"}\n        className={cn(\n          \"inline-flex h-6 w-6 shrink-0 items-center justify-center border-0 bg-transparent p-0 text-newt-text-muted data-[state=active]:text-newt-text-primary\",\n          !decorative && [interactiveClassName, \"hover:text-newt-text-primary\"],\n          className\n        )}\n        {...(decorative ? withoutHandlers(props) : props)}\n      />\n    )\n  }\n)\nChannelHeaderAction.displayName = \"ChannelHeaderAction\"\n\nconst SearchIcon = ({ className }: { className: string }) => (\n  <svg\n    viewBox=\"0 0 16 16\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeWidth=\"1.75\"\n    strokeLinecap=\"round\"\n    aria-hidden=\"true\"\n    className={cn(\"shrink-0\", className)}\n  >\n    <circle cx=\"7\" cy=\"7\" r=\"4.5\" />\n    <path d=\"M10.5 10.5 14 14\" />\n  </svg>\n)\n\nexport interface ChannelHeaderSearchProps extends ChannelHeaderControlProps {\n  /** The text shown when the control has no children. */\n  placeholder?: string\n  /**\n   * Icon-only form for the narrow header. The text stays in the control for\n   * assistive technology, so it is still the accessible name.\n   */\n  compact?: boolean\n}\n\n/* Its text is its accessible name: what a user sees is what they can say. */\nconst ChannelHeaderSearch = React.forwardRef<\n  HTMLElement,\n  ChannelHeaderSearchProps\n>(\n  (\n    {\n      as,\n      href,\n      disabled,\n      className,\n      placeholder = \"Search\",\n      compact = false,\n      type = \"button\",\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const { Tag, isButton, decorative } = resolveControl(as, href)\n    return (\n      <Tag\n        ref={ref}\n        type={isButton ? type : undefined}\n        href={decorative || disabled ? undefined : href}\n        disabled={isButton ? disabled : undefined}\n        aria-disabled={!isButton && !decorative && disabled ? true : undefined}\n        aria-hidden={decorative ? true : undefined}\n        className={cn(\n          \"flex shrink-0 items-center text-newt-text-muted no-underline\",\n          compact\n            ? \"h-6 w-6 justify-center border-0 bg-transparent p-0\"\n            : \"h-7 w-60 justify-between gap-3 rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-input px-2\",\n          !decorative && [\n            interactiveClassName,\n            compact\n              ? \"hover:text-newt-text-primary\"\n              : \"hover:border-newt-text-muted\",\n          ],\n          className\n        )}\n        {...(decorative ? withoutHandlers(props) : props)}\n      >\n        <span\n          className={\n            compact\n              ? \"sr-only\"\n              : \"min-w-0 flex-1 truncate text-start text-sm font-medium leading-none\"\n          }\n        >\n          {children ?? placeholder}\n        </span>\n        <SearchIcon className={compact ? \"h-5 w-5\" : \"h-4 w-4\"} />\n      </Tag>\n    )\n  }\n)\nChannelHeaderSearch.displayName = \"ChannelHeaderSearch\"\n\nexport interface ChannelHeaderBackProps extends ChannelHeaderControlProps {\n  /** The unread count drawn beside the arrow. Leave it unset for no badge. */\n  badge?: React.ReactNode\n}\n\n/*\n * The control that leaves the channel in the narrow header. It has no text,\n * so it needs an `aria-label`; put the unread count in that label too,\n * because the label replaces the badge for assistive technology.\n */\nconst ChannelHeaderBack = React.forwardRef<HTMLElement, ChannelHeaderBackProps>(\n  (\n    {\n      as,\n      href,\n      disabled,\n      className,\n      badge,\n      type = \"button\",\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const { Tag, isButton, decorative } = resolveControl(as, href)\n    return (\n      <Tag\n        ref={ref}\n        type={isButton ? type : undefined}\n        href={decorative || disabled ? undefined : href}\n        disabled={isButton ? disabled : undefined}\n        aria-disabled={!isButton && !decorative && disabled ? true : undefined}\n        aria-hidden={decorative ? true : undefined}\n        className={cn(\n          \"inline-flex h-6 min-w-6 shrink-0 items-center justify-center gap-1 border-0 bg-transparent p-0 text-newt-text-muted no-underline\",\n          !decorative && [interactiveClassName, \"hover:text-newt-text-primary\"],\n          className\n        )}\n        {...(decorative ? withoutHandlers(props) : props)}\n      >\n        {children ?? (\n          <svg\n            viewBox=\"0 0 20 20\"\n            fill=\"currentColor\"\n            aria-hidden=\"true\"\n            className=\"h-5 w-5 shrink-0 rtl:-scale-x-100\"\n          >\n            <path d=\"M8.7 3.3 2 10l6.7 6.7 1.4-1.4L5.8 11H18V9H5.8l4.3-4.3-1.4-1.4Z\" />\n          </svg>\n        )}\n        {badge == null || badge === false ? null : (\n          <span className=\"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-newt-dnd px-1 text-[11px] font-bold leading-none text-newt-on-accent\">\n            {badge}\n          </span>\n        )}\n      </Tag>\n    )\n  }\n)\nChannelHeaderBack.displayName = \"ChannelHeaderBack\"\n\n/*\n * The channel name as a control, for the narrow header where a press on the\n * title opens the channel details. Put `ChannelHeaderIcon` and\n * `ChannelHeaderName` inside it: the name is its accessible name. `span`\n * renders it as plain text, still readable by assistive technology. Its\n * event handlers do not run.\n */\nconst ChannelHeaderTitle = React.forwardRef<\n  HTMLElement,\n  ChannelHeaderControlProps\n>(\n  (\n    { as, href, disabled, className, type = \"button\", children, ...props },\n    ref\n  ) => {\n    const { Tag, isButton, decorative: plain } = resolveControl(as, href)\n    return (\n      <Tag\n        ref={ref}\n        type={isButton ? type : undefined}\n        href={plain || disabled ? undefined : href}\n        disabled={isButton ? disabled : undefined}\n        aria-disabled={!isButton && !plain && disabled ? true : undefined}\n        className={cn(\n          \"inline-flex min-w-0 items-center gap-2 rounded-[var(--newt-radius-sm)] border-0 bg-transparent px-1.5 py-1 text-start text-newt-text-primary no-underline\",\n          !plain && [interactiveClassName, \"hover:bg-newt-bg-hover\"],\n          className\n        )}\n        {...(plain ? withoutHandlers(props) : props)}\n      >\n        {children}\n        {plain ? null : (\n          <svg\n            viewBox=\"0 0 16 16\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"1.75\"\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            aria-hidden=\"true\"\n            className=\"h-4 w-4 shrink-0 text-newt-text-muted rtl:-scale-x-100\"\n          >\n            <path d=\"m6 3.5 4.5 4.5L6 12.5\" />\n          </svg>\n        )}\n      </Tag>\n    )\n  }\n)\nChannelHeaderTitle.displayName = \"ChannelHeaderTitle\"\n\n/* Compact \"N Online\" readout used by the narrow layout of the header. */\nconst ChannelHeaderOnline = React.forwardRef<\n  HTMLSpanElement,\n  React.ComponentProps<\"span\">\n>(({ className, children, ...props }, ref) => (\n  <span\n    ref={ref}\n    className={cn(\n      \"inline-flex shrink-0 items-center gap-1.5 text-xs text-newt-text-muted\",\n      className\n    )}\n    {...props}\n  >\n    <span\n      aria-hidden=\"true\"\n      className=\"h-2 w-2 shrink-0 rounded-full bg-newt-online\"\n    />\n    {children}\n  </span>\n))\nChannelHeaderOnline.displayName = \"ChannelHeaderOnline\"\n\nexport {\n  ChannelHeader,\n  ChannelHeaderInfo,\n  ChannelHeaderIcon,\n  ChannelHeaderName,\n  ChannelHeaderDivider,\n  ChannelHeaderTopic,\n  ChannelHeaderToolbar,\n  ChannelHeaderAction,\n  ChannelHeaderSearch,\n  ChannelHeaderBack,\n  ChannelHeaderTitle,\n  ChannelHeaderOnline,\n}\n",
      "type": "registry:ui"
    }
  ]
}