From bb8cf3d2800101df75426d5ddfde923d3b23ce5d Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Wed, 7 May 2025 15:13:13 +0200 Subject: [PATCH] ui: fix types --- .../app/components/Kai/components/ChatMsg.tsx | 2 +- .../{CopyButton.js => CopyButton.tsx} | 18 +++++++++++++++--- .../ui/CopyButton/{index.js => index.ts} | 0 3 files changed, 16 insertions(+), 4 deletions(-) rename frontend/app/components/ui/CopyButton/{CopyButton.js => CopyButton.tsx} (80%) rename frontend/app/components/ui/CopyButton/{index.js => index.ts} (100%) diff --git a/frontend/app/components/Kai/components/ChatMsg.tsx b/frontend/app/components/Kai/components/ChatMsg.tsx index cd5289a35..db9e249cc 100644 --- a/frontend/app/components/Kai/components/ChatMsg.tsx +++ b/frontend/app/components/Kai/components/ChatMsg.tsx @@ -102,7 +102,7 @@ export function ChatMsg({ onFeedback('dislike', messageId)}> - bodyRef.current?.innerHTML} isIcon format={'text/html'} /> + bodyRef.current?.innerHTML} content={text} isIcon format={'text/html'} /> diff --git a/frontend/app/components/ui/CopyButton/CopyButton.js b/frontend/app/components/ui/CopyButton/CopyButton.tsx similarity index 80% rename from frontend/app/components/ui/CopyButton/CopyButton.js rename to frontend/app/components/ui/CopyButton/CopyButton.tsx index 52652ae2f..f82375914 100644 --- a/frontend/app/components/ui/CopyButton/CopyButton.js +++ b/frontend/app/components/ui/CopyButton/CopyButton.tsx @@ -3,15 +3,27 @@ import copy from 'copy-to-clipboard'; import { Button, Tooltip } from 'antd'; import { ClipboardCopy, ClipboardCheck } from 'lucide-react'; +interface Props { + content: string; + getHtml?: () => any; + variant?: 'text' | 'primary' | 'ghost' | 'link' | 'default'; + className?: string; + btnText?: string; + size?: 'small' | 'middle' | 'large'; + isIcon?: boolean; + format?: string; +} + function CopyButton({ content, + getHtml, variant = 'text', className = 'capitalize mt-2 font-medium text-neutral-400', btnText = 'copy', size = 'small', isIcon = false, format = 'text/plain', -}) { +}: Props) { const [copied, setCopied] = useState(false); const reset = () => { @@ -21,8 +33,8 @@ function CopyButton({ } const copyHandler = () => { setCopied(true); - const contentIsGetter = typeof content === 'function' - const textContent = contentIsGetter ? content() : content; + const contentIsGetter = !!getHtml + const textContent = contentIsGetter ? getHtml() : content; const isHttps = window.location.protocol === 'https:'; if (!isHttps) { copy(textContent); diff --git a/frontend/app/components/ui/CopyButton/index.js b/frontend/app/components/ui/CopyButton/index.ts similarity index 100% rename from frontend/app/components/ui/CopyButton/index.js rename to frontend/app/components/ui/CopyButton/index.ts