import { Background, Flex, Padding, TouchableOpacity } from '@/@dble_layout'; import onScrollToNextRef from '@/libs/handler/onScrollToRef'; import { useUid } from '@/libs/hooks'; import { colors } from '@/libs/themes'; import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react'; interface Types extends React.TextareaHTMLAttributes { children?: never[]; onUpload: () => void; onFileUpload?: (fileName: string, fileUrl: string) => void; onImageUpload?: (fileName: string, fileUrl: string) => void; isFocus?: boolean; } export const ChatEditor = React.forwardRef((props, ref) => { const textareaRef = useRef(null); const editorRef = useRef(null); const fileInputRef = useRef(null); const imageInputRef = useRef(null); const [textareaHeight, setTextareaHeight] = useState(0); // rasize useEffect(() => { const handleRasie = () => { if (props.value && props.value !== '' && textareaRef && 'current' in textareaRef && textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = textareaRef.current.scrollHeight + 'px'; setTextareaHeight(textareaRef.current.scrollHeight); } else if (textareaRef.current) { textareaRef.current.style.height = 'auto'; setTextareaHeight(0); } }; handleRasie(); }, [props.value, textareaRef]); const handleUpload = useCallback(() => { props.onUpload?.(); fixedWindowScroll(); }, [props]); return ( fileInputRef.current?.click()}> { props.onFileUpload?.(fileName, fileUrl); }} /> imageInputRef.current?.click()}> { props.onImageUpload?.(fileName, fileUrl); }} />