From 2498c238b29a7873a6d0a94cb4a8e67ffcf456f4 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Fri, 26 Jul 2024 16:54:25 +0800 Subject: [PATCH] file-uploader --- .../components/base/action-button/index.css | 2 +- .../base/chat/chat/chat-input-area/hooks.ts | 36 +++++++++++++ .../base/chat/chat/chat-input-area/index.tsx | 51 +++++++++++++++++++ .../file-list/file-list-flex/index.tsx | 9 ++++ .../file-list/file-list-full-width/index.tsx | 9 ++++ .../base/file-uploader/file-list/hooks.ts | 0 .../base/file-uploader/file-list/index.tsx | 0 .../file-uploader-in-chat-input/index.tsx | 51 +++++++++++++++++++ .../components/base/file-uploader/index.ts | 1 + 9 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 web/app/components/base/chat/chat/chat-input-area/hooks.ts create mode 100644 web/app/components/base/chat/chat/chat-input-area/index.tsx create mode 100644 web/app/components/base/file-uploader/file-list/file-list-flex/index.tsx create mode 100644 web/app/components/base/file-uploader/file-list/file-list-full-width/index.tsx create mode 100644 web/app/components/base/file-uploader/file-list/hooks.ts create mode 100644 web/app/components/base/file-uploader/file-list/index.tsx diff --git a/web/app/components/base/action-button/index.css b/web/app/components/base/action-button/index.css index b87dbc8d4a..5ed29742db 100644 --- a/web/app/components/base/action-button/index.css +++ b/web/app/components/base/action-button/index.css @@ -16,7 +16,7 @@ } .action-btn-l { - @apply p-1.5 w-[34px] h-[34px] rounded-lg + @apply p-1.5 w-8 h-8 rounded-lg } /* m is for the regular button */ diff --git a/web/app/components/base/chat/chat/chat-input-area/hooks.ts b/web/app/components/base/chat/chat/chat-input-area/hooks.ts new file mode 100644 index 0000000000..3559cb8799 --- /dev/null +++ b/web/app/components/base/chat/chat/chat-input-area/hooks.ts @@ -0,0 +1,36 @@ +import { + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from 'react' +import type { TextAreaRef } from 'rc-textarea' + +export const useTextAreaHeight = () => { + const textareaRef = useRef(null) + const [height, setHeight] = useState(0) + + const handleComputeHeight = () => { + const textareaElement = textareaRef.current?.resizableTextArea.textArea + if (textareaElement) { + const { height } = textareaElement.getBoundingClientRect() + + setHeight(height) + } + } + + useEffect(() => { + handleComputeHeight() + }, []) + + const handleTextareaResize = useCallback(() => { + handleComputeHeight() + }, []) + + return { + textareaRef, + handleTextareaResize, + isMultipleLine: useMemo(() => height > 32, [height]), + } +} diff --git a/web/app/components/base/chat/chat/chat-input-area/index.tsx b/web/app/components/base/chat/chat/chat-input-area/index.tsx new file mode 100644 index 0000000000..be49248cb6 --- /dev/null +++ b/web/app/components/base/chat/chat/chat-input-area/index.tsx @@ -0,0 +1,51 @@ +import { + memo, +} from 'react' +import Textarea from 'rc-textarea' +import { RiSendPlane2Fill } from '@remixicon/react' +import { useTextAreaHeight } from './hooks' +import Button from '@/app/components/base/button' +import { FileUploaderInChatInput } from '@/app/components/base/file-uploader' +import cn from '@/utils/classnames' + +const ChatInputArea = () => { + const { + textareaRef, + handleTextareaResize, + isMultipleLine, + } = useTextAreaHeight() + + return ( +
+