"use client"; import { Primitive } from "../../../utils/Primitive"; import { type ComponentRef, type ComponentPropsWithoutRef, type ReactNode, forwardRef, useCallback, } from "react"; import { composeEventHandlers } from "@radix-ui/primitive"; import { useTriggerPopoverScopeContext } from "./TriggerPopover"; import type { Unstable_TriggerCategory } from "@assistant-ui/core"; export namespace ComposerPrimitiveTriggerPopoverCategories { export type Element = ComponentRef; export type Props = Omit< ComponentPropsWithoutRef, "children" > & { children: (categories: readonly Unstable_TriggerCategory[]) => ReactNode; }; } /** * Renders the top-level category list via a render function. * Only renders when no category is active and search mode is off. */ export const ComposerPrimitiveTriggerPopoverCategories = forwardRef< ComposerPrimitiveTriggerPopoverCategories.Element, ComposerPrimitiveTriggerPopoverCategories.Props >(({ children, "aria-label": ariaLabel, ...props }, forwardedRef) => { const { categories, activeCategoryId, isSearchMode, open } = useTriggerPopoverScopeContext(); if (!open || activeCategoryId || isSearchMode) return null; return ( {children(categories)} ); }); ComposerPrimitiveTriggerPopoverCategories.displayName = "ComposerPrimitive.TriggerPopoverCategories"; export namespace ComposerPrimitiveTriggerPopoverCategoryItem { export type Element = ComponentRef; export type Props = ComponentPropsWithoutRef & { categoryId: string; }; } /** * A button that selects a category and triggers drill-down navigation. * Automatically receives `data-highlighted` when keyboard-navigated. */ export const ComposerPrimitiveTriggerPopoverCategoryItem = forwardRef< ComposerPrimitiveTriggerPopoverCategoryItem.Element, ComposerPrimitiveTriggerPopoverCategoryItem.Props >(({ categoryId, onClick, onMouseMove, ...props }, forwardedRef) => { const { selectCategory, highlightIndex, categories, highlightedIndex, activeCategoryId, isSearchMode, popoverId, } = useTriggerPopoverScopeContext(); const handleClick = useCallback(() => { selectCategory(categoryId); }, [selectCategory, categoryId]); const categoryIndex = categories.findIndex((c) => c.id === categoryId); const isHighlighted = !activeCategoryId && !isSearchMode && categoryIndex === highlightedIndex; const handleMouseMove = useCallback(() => { highlightIndex(categoryIndex); }, [highlightIndex, categoryIndex]); return ( ); }); ComposerPrimitiveTriggerPopoverCategoryItem.displayName = "ComposerPrimitive.TriggerPopoverCategoryItem";