import { FC, MouseEvent, useEffect, useState } from 'react'; import { ArrowContainer, Popover } from 'react-tiny-popover'; import { Flex, Grid, NitroCardContentView } from '../../../../common'; interface ChatInputStyleSelectorViewProps { chatStyleId: number; chatStyleIds: number[]; selectChatStyleId: (styleId: number) => void; } export const ChatInputStyleSelectorView: FC = props => { const { chatStyleId = 0, chatStyleIds = null, selectChatStyleId = null } = props; const [ target, setTarget ] = useState<(EventTarget & HTMLElement)>(null); const [ selectorVisible, setSelectorVisible ] = useState(false); const selectStyle = (styleId: number) => { selectChatStyleId(styleId); setSelectorVisible(false); }; const toggleSelector = (event: MouseEvent) => { let visible = false; setSelectorVisible(prevValue => { visible = !prevValue; return visible; }); if(visible) setTarget((event.target as (EventTarget & HTMLElement))); }; useEffect(() => { if(selectorVisible) return; setTarget(null); }, [ selectorVisible ]); return ( <> ( { chatStyleIds && (chatStyleIds.length > 0) && chatStyleIds.map((styleId) => { return ( selectStyle(styleId) }>
 
); }) }
) } isOpen={ selectorVisible } positions={ [ 'top' ] } >
); };