{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "assistant-modal",
  "type": "registry:component",
  "title": "Assistant Modal",
  "description": "Floating chat bubble for support widgets and help desks, with a thread list and a resizable window.",
  "dependencies": [
    "@assistant-ui/react@^0.15.38",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://r.assistant-ui.com/thread.json",
    "https://r.assistant-ui.com/thread-list.json",
    "https://r.assistant-ui.com/tooltip-icon-button.json",
    "https://r.assistant-ui.com/elements-modal-size.json"
  ],
  "files": [
    {
      "type": "registry:component",
      "path": "components/assistant-ui/elements/assistant-modal.aui.tsx",
      "sourcePath": "packages/ui/src/components/react/assistant-ui/elements/assistant-modal.aui.radix.tsx",
      "content": "\"use client\";\n\nimport { BotIcon, ChevronDownIcon, HistoryIcon, PlusIcon } from \"lucide-react\";\n\nimport {\n  type ComponentPropsWithoutRef,\n  type FC,\n  forwardRef,\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n} from \"react\";\nimport {\n  AssistantModalPrimitive,\n  ThreadListPrimitive,\n  useAuiEvent,\n  useAuiState,\n} from \"@assistant-ui/react\";\n\nimport { Thread } from \"@/components/assistant-ui/elements/thread.aui\";\nimport {\n  ThreadListItems,\n  ThreadListRoot,\n  ThreadListSearch,\n} from \"@/components/assistant-ui/elements/thread-list.aui\";\nimport { TooltipIconButton } from \"@/components/assistant-ui/elements/tooltip-icon-button\";\nimport { type ModalView, useModalSize } from \"../utils/modal-size\";\n\nexport const AssistantModal: FC = () => {\n  const [view, setView] = useState<ModalView>(\"thread\");\n  const contentRef = useRef<HTMLDivElement>(null);\n  const titleId = useId();\n  const { size, reset, handleProps } = useModalSize(contentRef);\n  const thread = useMemo(() => <Thread />, []);\n\n  useAuiEvent(\"thread.runStart\", () => setView(\"thread\"));\n\n  return (\n    <AssistantModalPrimitive.Root\n      onOpenChange={(open) => {\n        if (open) setView(\"thread\");\n      }}\n    >\n      <AssistantModalPrimitive.Anchor className=\"aui-root aui-modal-anchor fixed end-4 bottom-4 size-11\">\n        <AssistantModalPrimitive.Trigger asChild>\n          <AssistantModalButton />\n        </AssistantModalPrimitive.Trigger>\n      </AssistantModalPrimitive.Anchor>\n      <AssistantModalPrimitive.Content\n        ref={contentRef}\n        sideOffset={16}\n        aria-labelledby={titleId}\n        style={size ?? undefined}\n        className=\"group/modal aui-root aui-modal-content bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:slide-out-to-bottom-2 [&[data-state=open]_.aui-thread-viewport-footer]:animate-in [&[data-state=open]_.aui-thread-viewport-footer]:fade-in-0 [&[data-state=open]_.aui-thread-viewport-footer]:slide-in-from-bottom-2 [&[data-state=open]_.aui-thread-viewport-footer]:fill-mode-backwards [&_.aui-thread-viewport-footer]:bg-popover ring-foreground/10 z-50 flex h-125 max-h-(--radix-popover-content-available-height) w-100 max-w-[calc(100vw-2rem)] origin-(--radix-popover-content-transform-origin) flex-col overflow-clip overscroll-contain rounded-xl p-0 antialiased shadow-[0_16px_48px_-24px_rgb(0_0_0/0.25)] ring-1 transition-none ease-[cubic-bezier(0.32,0.72,0,1)] outline-none data-[state=closed]:duration-200 data-[state=open]:duration-300 motion-reduce:animate-none dark:shadow-[0_16px_48px_-24px_rgb(0_0_0/0.6)] [&_.aui-thread-root]:bg-inherit motion-reduce:[&_.aui-thread-viewport-footer]:animate-none [&_[data-slot=aui\\_thread-viewport]]:[scrollbar-gutter:stable_both-edges] [&[data-state=open]_.aui-thread-viewport-footer]:delay-100 [&[data-state=open]_.aui-thread-viewport-footer]:duration-300 [&[data-state=open]_.aui-thread-viewport-footer]:ease-[cubic-bezier(0.32,0.72,0,1)]\"\n      >\n        <AssistantModalResizeHandle {...handleProps} onDoubleClick={reset} />\n        <AssistantModalHeader\n          titleId={titleId}\n          view={view}\n          onViewChange={setView}\n        />\n        <div className=\"aui-modal-body relative min-h-0 flex-1\">\n          <div\n            ref={(node) => {\n              if (node) node.inert = view === \"list\";\n            }}\n            className=\"aui-modal-thread h-full\"\n          >\n            {thread}\n          </div>\n          {view === \"list\" && (\n            <AssistantModalThreadList onSelect={() => setView(\"thread\")} />\n          )}\n        </div>\n      </AssistantModalPrimitive.Content>\n    </AssistantModalPrimitive.Root>\n  );\n};\n\nconst AssistantModalHeader: FC<{\n  titleId: string;\n  view: ModalView;\n  onViewChange: (view: ModalView) => void;\n}> = ({ titleId, view, onViewChange }) => {\n  const title = useAuiState((s) => s.threadListItem.title);\n  const hasThreads = useAuiState((s) => s.threads.threadIds.length > 0);\n  const titleRef = useRef<HTMLHeadingElement>(null);\n  const shownViewRef = useRef(view);\n\n  useEffect(() => {\n    if (shownViewRef.current === view) return;\n    shownViewRef.current = view;\n    const heading = titleRef.current;\n    const active = document.activeElement;\n    if (\n      active === document.body ||\n      active === heading?.closest(\"[role='dialog']\")\n    ) {\n      heading?.focus();\n    }\n  }, [view]);\n\n  return (\n    <div className=\"aui-modal-header border-foreground/10 flex h-11 shrink-0 items-center gap-2 border-b ps-3.5 pe-2\">\n      <h2\n        ref={titleRef}\n        id={titleId}\n        tabIndex={-1}\n        className=\"aui-modal-title min-w-0 flex-1 truncate text-[13px] font-medium outline-none\"\n      >\n        {view === \"list\" ? \"Threads\" : title || \"New Chat\"}\n      </h2>\n      <div className=\"flex shrink-0 items-center gap-0.5\">\n        <TooltipIconButton\n          tooltip=\"Threads\"\n          side=\"bottom\"\n          aria-pressed={view === \"list\"}\n          disabled={!hasThreads && view === \"thread\"}\n          className=\"aui-modal-threads text-muted-foreground hover:text-foreground aria-pressed:bg-muted aria-pressed:text-foreground size-7 rounded-md p-0\"\n          onClick={() => onViewChange(view === \"list\" ? \"thread\" : \"list\")}\n        >\n          <HistoryIcon className=\"size-3.5\" />\n        </TooltipIconButton>\n        <ThreadListPrimitive.New asChild>\n          <TooltipIconButton\n            tooltip=\"New Thread\"\n            side=\"bottom\"\n            className=\"aui-modal-new text-muted-foreground hover:text-foreground size-7 rounded-md p-0\"\n            onClick={() => onViewChange(\"thread\")}\n          >\n            <PlusIcon className=\"size-3.5\" />\n          </TooltipIconButton>\n        </ThreadListPrimitive.New>\n      </div>\n    </div>\n  );\n};\n\nconst AssistantModalThreadList: FC<{ onSelect: () => void }> = ({\n  onSelect,\n}) => {\n  const [search, setSearch] = useState(\"\");\n  const hasThreads = useAuiState((s) => s.threads.threadIds.length > 0);\n\n  return (\n    <ThreadListRoot\n      className=\"aui-modal-thread-list bg-popover absolute inset-0 overflow-y-auto p-2\"\n      onClick={(event) => {\n        const target = event.target as Element;\n        if (target.closest(\"[data-slot='aui_thread-list-item-trigger']\")) {\n          onSelect();\n        }\n      }}\n    >\n      {hasThreads && (\n        <ThreadListSearch value={search} onValueChange={setSearch} />\n      )}\n      <ThreadListItems searchQuery={hasThreads ? search : \"\"} />\n    </ThreadListRoot>\n  );\n};\n\nconst AssistantModalResizeHandle: FC<ComponentPropsWithoutRef<\"button\">> = (\n  props,\n) => {\n  return (\n    <button\n      type=\"button\"\n      aria-label=\"Resize Assistant\"\n      className=\"aui-modal-resize-handle group-hover/modal:border-foreground/15 hover:border-foreground/40 focus-visible:border-ring absolute start-0 top-0 z-10 size-6 cursor-nwse-resize touch-none rounded-ss-xl border-s-2 border-t-2 border-transparent transition-colors outline-none [clip-path:polygon(0_0,100%_0,100%_6px,6px_6px,6px_100%,0_100%)] motion-reduce:transition-none rtl:cursor-nesw-resize rtl:[clip-path:polygon(0_0,100%_0,100%_100%,calc(100%_-_6px)_100%,calc(100%_-_6px)_6px,0_6px)]\"\n      {...props}\n    />\n  );\n};\n\ntype AssistantModalButtonProps = { \"data-state\"?: \"open\" | \"closed\" };\n\nconst AssistantModalButton = forwardRef<\n  HTMLButtonElement,\n  AssistantModalButtonProps\n>(({ \"data-state\": state, ...rest }, ref) => {\n  const tooltip = state === \"open\" ? \"Close Assistant\" : \"Open Assistant\";\n\n  return (\n    <TooltipIconButton\n      variant=\"ghost\"\n      tooltip={tooltip}\n      side=\"left\"\n      {...rest}\n      className=\"aui-modal-button bg-background text-foreground border-border/60 hover:border-border hover:bg-background size-full rounded-full border transition-[border-color,scale] duration-150 ease-out active:scale-96 motion-reduce:transition-none\"\n      ref={ref}\n    >\n      <BotIcon\n        data-state={state}\n        className=\"aui-modal-button-closed-icon absolute size-5 transition-[scale,opacity,filter] duration-200 ease-[cubic-bezier(0.2,0,0,1)] data-[state=closed]:scale-100 data-[state=closed]:opacity-100 data-[state=closed]:blur-[0px] data-[state=open]:scale-25 data-[state=open]:opacity-0 data-[state=open]:blur-[4px] motion-reduce:transition-none\"\n      />\n\n      <ChevronDownIcon\n        data-state={state}\n        className=\"aui-modal-button-open-icon absolute size-5 transition-[scale,opacity,filter] duration-200 ease-[cubic-bezier(0.2,0,0,1)] data-[state=closed]:scale-25 data-[state=closed]:opacity-0 data-[state=closed]:blur-[4px] data-[state=open]:scale-100 data-[state=open]:opacity-100 data-[state=open]:blur-[0px] motion-reduce:transition-none\"\n      />\n      <span className=\"aui-sr-only sr-only\">{tooltip}</span>\n    </TooltipIconButton>\n  );\n});\n\nAssistantModalButton.displayName = \"AssistantModalButton\";\n"
    }
  ]
}