UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

46 lines (45 loc) 1.57 kB
"use client"; // src/primitives/message/MessageRoot.tsx import { Primitive } from "@radix-ui/react-primitive"; import { forwardRef, useCallback } from "react"; import { useAssistantApi, useAssistantState } from "../../context/index.js"; import { useManagedRef } from "../../utils/hooks/useManagedRef.js"; import { useComposedRefs } from "@radix-ui/react-compose-refs"; import { jsx } from "react/jsx-runtime"; var useIsHoveringRef = () => { const api = useAssistantApi(); const message = useAssistantState(() => api.message()); const callbackRef = useCallback( (el) => { const handleMouseEnter = () => { message.setIsHovering(true); }; const handleMouseLeave = () => { message.setIsHovering(false); }; el.addEventListener("mouseenter", handleMouseEnter); el.addEventListener("mouseleave", handleMouseLeave); if (el.matches(":hover")) message.setIsHovering(true); return () => { el.removeEventListener("mouseenter", handleMouseEnter); el.removeEventListener("mouseleave", handleMouseLeave); message.setIsHovering(false); }; }, [message] ); return useManagedRef(callbackRef); }; var MessagePrimitiveRoot = forwardRef((props, forwardRef2) => { const isHoveringRef = useIsHoveringRef(); const ref = useComposedRefs(forwardRef2, isHoveringRef); return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref }); }); MessagePrimitiveRoot.displayName = "MessagePrimitive.Root"; export { MessagePrimitiveRoot }; //# sourceMappingURL=MessageRoot.js.map