From f89f1a9f7335e8c616dce095e0336c38fbb0e976 Mon Sep 17 00:00:00 2001 From: arvinxx Date: Sun, 22 Oct 2023 00:08:34 +0800 Subject: [PATCH] :fire: refactor: clean code --- src/ChatInputArea/Action.tsx | 64 ---- src/ChatInputArea/Desktop.tsx | 133 -------- src/ChatInputArea/demos/index.tsx | 31 -- src/ChatInputArea/index.md | 14 - src/ChatInputArea/index.tsx | 12 - src/ChatInputArea/style.mobile.ts | 19 -- src/ChatInputArea/style.ts | 56 ---- src/ChatInputArea/type.ts | 35 -- .../components/DraggablePanelBody.tsx | 18 - .../components/DraggablePanelContainer.tsx | 20 -- .../components/DraggablePanelFooter.tsx | 20 -- .../components/DraggablePanelHeader.tsx | 45 --- src/DraggablePanel/components/style.ts | 40 --- src/DraggablePanel/demos/Layout.tsx | 44 --- src/DraggablePanel/demos/index.tsx | 65 ---- src/DraggablePanel/index.md | 18 - src/DraggablePanel/index.tsx | 312 ------------------ src/DraggablePanel/style.ts | 276 ---------------- src/DraggablePanel/utils.ts | 18 - src/ProChat/demos/doc-mode.tsx | 4 +- src/index.ts | 18 - 21 files changed, 2 insertions(+), 1260 deletions(-) delete mode 100644 src/ChatInputArea/Action.tsx delete mode 100644 src/ChatInputArea/Desktop.tsx delete mode 100644 src/ChatInputArea/demos/index.tsx delete mode 100644 src/ChatInputArea/index.md delete mode 100644 src/ChatInputArea/index.tsx delete mode 100644 src/ChatInputArea/style.mobile.ts delete mode 100644 src/ChatInputArea/style.ts delete mode 100644 src/ChatInputArea/type.ts delete mode 100644 src/DraggablePanel/components/DraggablePanelBody.tsx delete mode 100644 src/DraggablePanel/components/DraggablePanelContainer.tsx delete mode 100644 src/DraggablePanel/components/DraggablePanelFooter.tsx delete mode 100644 src/DraggablePanel/components/DraggablePanelHeader.tsx delete mode 100644 src/DraggablePanel/components/style.ts delete mode 100644 src/DraggablePanel/demos/Layout.tsx delete mode 100644 src/DraggablePanel/demos/index.tsx delete mode 100644 src/DraggablePanel/index.md delete mode 100644 src/DraggablePanel/index.tsx delete mode 100644 src/DraggablePanel/style.ts delete mode 100644 src/DraggablePanel/utils.ts diff --git a/src/ChatInputArea/Action.tsx b/src/ChatInputArea/Action.tsx deleted file mode 100644 index a4eaf7a7..00000000 --- a/src/ChatInputArea/Action.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import { createStyles, useResponsive } from 'antd-style'; -import { Maximize2, Minimize2 } from 'lucide-react'; -import { ReactNode, memo, useCallback } from 'react'; - -import ActionIcon from '@/ActionIcon'; - -const useStyles = createStyles(({ css }) => { - return { - actionLeft: css` - display: flex; - flex: 1; - gap: 4px; - align-items: center; - justify-content: flex-start; - `, - actionsBar: css` - display: flex; - flex: none; - align-items: center; - justify-content: space-between; - - padding: 0 16px; - `, - actionsRight: css` - display: flex; - flex: 0; - gap: 4px; - align-items: center; - justify-content: flex-end; - `, - }; -}); - -export interface ActionProps { - /** - * @description Actions to be displayed in the input area - */ - actions?: ReactNode; - actionsRight?: ReactNode; - expand?: boolean; - onExpandChange?: (expand: boolean) => void; -} - -const Action = memo(({ actions, actionsRight, expand, onExpandChange }) => { - const { styles } = useStyles(); - const { mobile } = useResponsive(); - const handleExpandClick = useCallback(() => { - if (onExpandChange) onExpandChange(!expand); - }, [expand]); - - return ( -
-
{actions}
-
- {actionsRight} - {!mobile && ( - - )} -
-
- ); -}); - -export default Action; diff --git a/src/ChatInputArea/Desktop.tsx b/src/ChatInputArea/Desktop.tsx deleted file mode 100644 index 75d43b09..00000000 --- a/src/ChatInputArea/Desktop.tsx +++ /dev/null @@ -1,133 +0,0 @@ -import { Button, type InputRef } from 'antd'; -import { Loader2 } from 'lucide-react'; -import { CSSProperties, forwardRef, useCallback, useRef } from 'react'; -import useControlledState from 'use-merge-value'; - -import Icon from '@/Icon'; -import { TextArea, type TextAreaProps } from '@/components/Input'; - -import Action from './Action'; -import { useStyles } from './style'; -import type { ChatInputBase } from './type'; - -export type ChatInputAreaDesktop = ChatInputBase & - TextAreaProps & { - minHeight?: number; - textareaClassName?: string; - textareaId?: string; - textareaStyle?: CSSProperties; - }; - -const ChatInputArea = forwardRef( - ( - { - text, - textareaClassName, - style, - textareaStyle, - minHeight = 200, - className, - actions, - footer, - expand, - placeholder = 'Type something to chat...', - onExpandChange, - onSend, - defaultValue = '', - loading, - disabled, - onInputChange, - onPressEnter, - onCompositionStart, - onCompositionEnd, - onBlur, - onChange, - textareaId = 'lobe-chat-input-area', - actionsRight, - onStop, - value, - ...props - }, - ref, - ) => { - const [currentValue, setCurrentValue] = useControlledState(defaultValue, { - defaultValue, - onChange: onInputChange, - value, - }); - const { cx, styles } = useStyles(); - const isChineseInput = useRef(false); - - const handleSend = useCallback(() => { - if (loading && disabled) return; - if (onSend) onSend(currentValue); - setCurrentValue(''); - }, [disabled, currentValue]); - - return ( -
- -
-