// Generated with util/create-component.js import React, { useCallback, useRef, useState } from "react"; import NsImage from "../shared/ns-image"; import { Close } from "../UI/Icon"; import Text from "../UI/Text"; import { CommentInputProps } from "./CommentInput.types"; const CommentInput: React.FC = (props) => { const { onSubmitContent, nickNameForReply, isFixedBottom = false, profileImage, profileImageWrapper, } = props; const [content, setContent] = useState(""); const [isReplying, setIsReplying] = useState( nickNameForReply ? true : false ); const [formHeight, setFormHeight] = useState(0); const textareaRef = useRef(null); const formRef = useRef(null); const handleResizeHeight = useCallback(() => { if ( textareaRef === null || textareaRef.current === null || formRef === null || formRef.current === null ) return; textareaRef.current.style.height = "4.5rem"; textareaRef.current.style.height = textareaRef.current.scrollHeight + "px"; formRef.current.style.height = textareaRef.current.scrollHeight + 2 + "px"; setFormHeight(textareaRef.current.scrollHeight + 2); }, [content]); const submitContent = () => { if (content === "") return; onSubmitContent(content); setContent(""); if ( textareaRef === null || textareaRef.current === null || formRef === null || formRef.current === null ) return; textareaRef.current.style.height = "4.5rem"; formRef.current.style.height = "4.7rem"; setIsReplying(false); }; return ( <> {isReplying && nickNameForReply && ( )}
{ e.preventDefault(); submitContent(); }} ref={formRef} >
); }; export default CommentInput; const TargetBox = (props: { formHeight: number; isFixedBottom: boolean; nickNameForReply: string; onCloseTarget: (props: boolean) => void; }) => { const { formHeight, isFixedBottom, nickNameForReply, onCloseTarget } = props; const basicFormHeight = formHeight >= 37 ? 22 : 68; const targetBottom = (formHeight + basicFormHeight) / 10; return (
40 ? 42.5 : targetBottom}rem` }} >
{nickNameForReply} 님에게 답글을 남기는 중
); };