From f478ddc2edad9ba7beebfae866c1b35911cebcf1 Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Tue, 16 Dec 2025 19:43:43 +0100 Subject: [PATCH] Create `` component (#3857) --- .changeset/cool-pigs-wink.md | 5 + .../gitbook/src/components/AIChat/AIChat.tsx | 8 +- .../src/components/AIChat/AIChatInput.tsx | 110 ++---- .../DocumentView/Integration/contentkit.css | 6 +- .../PageFeedback/PageFeedbackForm.tsx | 57 +--- .../src/components/Search/SearchInput.tsx | 117 +++---- .../components/hooks/useControlledState.tsx | 83 +++++ .../src/components/primitives/Input.tsx | 317 ++++++++++++++++++ .../primitives/KeyboardShortcut.tsx | 10 +- .../src/components/primitives/index.ts | 1 + 10 files changed, 510 insertions(+), 204 deletions(-) create mode 100644 .changeset/cool-pigs-wink.md create mode 100644 packages/gitbook/src/components/hooks/useControlledState.tsx create mode 100644 packages/gitbook/src/components/primitives/Input.tsx diff --git a/.changeset/cool-pigs-wink.md b/.changeset/cool-pigs-wink.md new file mode 100644 index 000000000..862d9d1c1 --- /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 8fe7dea6a..38434c509 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 edee25d8e..ec751a4c9 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 ( -
-