UNPKG

@plteam/chat-ui

Version:

CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript

33 lines (32 loc) 1.32 kB
import * as React from 'react'; export const useMobileMessageActions = () => { const [_selectedValue, setSelectedValue] = React.useState(); const handleSelectMessage = (thread, message, element) => { setSelectedValue({ element, thread, message }); }; const handleCloseSelection = () => { setSelectedValue(undefined); }; const selectedValue = React.useMemo(() => { if (!_selectedValue || !_selectedValue.element.parentElement?.parentElement) return undefined; const bounds = _selectedValue.element.getBoundingClientRect(); const parent = _selectedValue.element.parentElement.parentElement; const parentBounds = parent.getBoundingClientRect(); const top = bounds.top - parentBounds.top + (parseInt(parent.style.paddingTop) || 0); const bottom = top + bounds.height; return { message: _selectedValue.message, thread: _selectedValue.thread, top, bottom, left: bounds.left - parentBounds.left, getBoundingClientRect: () => _selectedValue.element.getBoundingClientRect(), }; }, [_selectedValue]); return { selectedValue, handleSelectMessage, handleCloseSelection, }; };