diff --git a/.changeset/cool-pigs-wink.md b/.changeset/cool-pigs-wink.md new file mode 100644 index 0000000000..862d9d1c13 --- /dev/null +++ b/.changeset/cool-pigs-wink.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Add Input component diff --git a/packages/gitbook/src/components/AIChat/AIChat.tsx b/packages/gitbook/src/components/AIChat/AIChat.tsx index 8fe7dea6a5..38434c509e 100644 --- a/packages/gitbook/src/components/AIChat/AIChat.tsx +++ b/packages/gitbook/src/components/AIChat/AIChat.tsx @@ -201,7 +201,6 @@ export function AIChatBody(props: { const { chatController, chat, suggestions, greeting } = props; const { trademark } = useAI().config; - const [input, setInput] = React.useState(''); const language = useLanguage(); const now = useNow(60 * 60 * 1000); // Refresh every hour for greeting @@ -271,13 +270,10 @@ export function AIChatBody(props: { {chat.error ? : null} { - chatController.postMessage({ message: input }); - setInput(''); + onSubmit={(value) => { + chatController.postMessage({ message: value }); }} /> diff --git a/packages/gitbook/src/components/AIChat/AIChatInput.tsx b/packages/gitbook/src/components/AIChat/AIChatInput.tsx index edee25d8e3..ec751a4c9e 100644 --- a/packages/gitbook/src/components/AIChat/AIChatInput.tsx +++ b/packages/gitbook/src/components/AIChat/AIChatInput.tsx @@ -1,38 +1,26 @@ import { t, tString, useLanguage } from '@/intl/client'; -import { tcls } from '@/lib/tailwind'; import { Icon } from '@gitbook/icons'; import { useEffect, useRef } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import { useAIChatState } from '../AI/useAIChat'; -import { Button, HoverCard, HoverCardRoot, HoverCardTrigger } from '../primitives'; -import { KeyboardShortcut } from '../primitives/KeyboardShortcut'; +import { HoverCard, HoverCardRoot, HoverCardTrigger } from '../primitives'; +import { Input } from '../primitives/Input'; export function AIChatInput(props: { - value: string; disabled?: boolean; /** * When true, the input is disabled */ loading: boolean; - onChange: (value: string) => void; onSubmit: (value: string) => void; }) { - const { value, onChange, onSubmit, disabled, loading } = props; + const { onSubmit, disabled, loading } = props; const language = useLanguage(); const chat = useAIChatState(); const inputRef = useRef(null); - const handleInput = (event: React.ChangeEvent) => { - const textarea = event.currentTarget; - onChange(textarea.value); - - // Auto-resize - textarea.style.height = 'auto'; - textarea.style.height = `${textarea.scrollHeight}px`; - }; - useEffect(() => { if (chat.opened && !disabled && !loading) { // Add a small delay to ensure the input is rendered before focusing @@ -57,57 +45,33 @@ export function AIChatInput(props: { ); return ( -
-