From 802cde35019354ab3c4749ef1ae7ea71b404e31b Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Fri, 30 Jan 2026 16:28:36 +0100 Subject: [PATCH] feat: support customizing TTD welcome screen (#10719) * feat: support customizing TTD welcome screen * remove debug --- .../components/TTDDialog/Chat/Chat.scss | 4 ++-- .../TTDDialog/Chat/ChatInterface.tsx | 22 +++++++++---------- .../TTDDialog/Chat/TTDChatPanel.tsx | 8 +++---- .../components/TTDDialog/TTDDialog.tsx | 7 ++++++ .../TTDDialog/TTDWelcomeMessage.tsx | 11 ++++++++++ .../components/TTDDialog/TextToDiagram.tsx | 6 +++++ .../excalidraw/components/TTDDialog/types.ts | 5 +++++ 7 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 packages/excalidraw/components/TTDDialog/TTDWelcomeMessage.tsx diff --git a/packages/excalidraw/components/TTDDialog/Chat/Chat.scss b/packages/excalidraw/components/TTDDialog/Chat/Chat.scss index 01b5a96012..63671ed66e 100644 --- a/packages/excalidraw/components/TTDDialog/Chat/Chat.scss +++ b/packages/excalidraw/components/TTDDialog/Chat/Chat.scss @@ -48,14 +48,14 @@ $verticalBreakpoint: 861px; } } - &__empty-state { + &__welcome-screen { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 200px; - &-content { + &__welcome-message { text-align: center; h3 { diff --git a/packages/excalidraw/components/TTDDialog/Chat/ChatInterface.tsx b/packages/excalidraw/components/TTDDialog/Chat/ChatInterface.tsx index 312c49ac9c..1f0a302351 100644 --- a/packages/excalidraw/components/TTDDialog/Chat/ChatInterface.tsx +++ b/packages/excalidraw/components/TTDDialog/Chat/ChatInterface.tsx @@ -6,6 +6,8 @@ import { InlineIcon } from "../../InlineIcon"; import { t } from "../../../i18n"; +import { TTDWelcomeMessage } from "../TTDWelcomeMessage"; + import { ChatMessage } from "./ChatMessage"; import type { TChat, TTTDDialog } from "../types"; @@ -20,13 +22,13 @@ export const ChatInterface = ({ onGenerate, isGenerating, rateLimits, - placeholder, onAbort, onMermaidTabClick, onAiRepairClick, onDeleteMessage, onInsertMessage, onRetry, + renderWelcomeScreen, renderWarning, }: { chatId: string; @@ -41,17 +43,13 @@ export const ChatInterface = ({ } | null; onViewAsMermaid?: () => void; generatedResponse?: string | null; - placeholder: { - title: string; - description: string; - hint: string; - }; onAbort?: () => void; onMermaidTabClick?: (message: TChat.ChatMessage) => void; onAiRepairClick?: (message: TChat.ChatMessage) => void; onDeleteMessage?: (messageId: string) => void; onInsertMessage?: (message: TChat.ChatMessage) => void; onRetry?: (message: TChat.ChatMessage) => void; + renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen; renderWarning?: TTTDDialog.renderWarning; }) => { const messagesEndRef = useRef(null); @@ -113,12 +111,12 @@ export const ChatInterface = ({
{messages.length === 0 ? ( -
-
-

{placeholder.title}

-

{placeholder.description}

-

{placeholder.hint}

-
+
+ {renderWelcomeScreen ? ( + renderWelcomeScreen({ rateLimits: rateLimits ?? null }) + ) : ( + + )}
) : ( messages.map((message, index) => ( diff --git a/packages/excalidraw/components/TTDDialog/Chat/TTDChatPanel.tsx b/packages/excalidraw/components/TTDDialog/Chat/TTDChatPanel.tsx index a9e66df6e4..25aa30df88 100644 --- a/packages/excalidraw/components/TTDDialog/Chat/TTDChatPanel.tsx +++ b/packages/excalidraw/components/TTDDialog/Chat/TTDChatPanel.tsx @@ -40,6 +40,7 @@ export const TTDChatPanel = ({ onInsertMessage, onRetry, onViewAsMermaid, + renderWelcomeScreen, renderWarning, }: { chatId: string; @@ -68,6 +69,7 @@ export const TTDChatPanel = ({ onViewAsMermaid: () => void; + renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen; renderWarning?: TTTDDialog.renderWarning; }) => { const [rateLimits] = useAtom(rateLimitsAtom); @@ -151,11 +153,7 @@ export const TTDChatPanel = ({ onInsertMessage={onInsertMessage} onRetry={onRetry} rateLimits={rateLimits} - placeholder={{ - title: t("chat.placeholder.title"), - description: t("chat.placeholder.description"), - hint: t("chat.placeholder.hint"), - }} + renderWelcomeScreen={renderWelcomeScreen} renderWarning={renderWarning} /> diff --git a/packages/excalidraw/components/TTDDialog/TTDDialog.tsx b/packages/excalidraw/components/TTDDialog/TTDDialog.tsx index a77167613e..a16c0cc385 100644 --- a/packages/excalidraw/components/TTDDialog/TTDDialog.tsx +++ b/packages/excalidraw/components/TTDDialog/TTDDialog.tsx @@ -15,6 +15,8 @@ import { TTDDialogTab } from "./TTDDialogTab"; import "./TTDDialog.scss"; +import { TTDWelcomeMessage } from "./TTDWelcomeMessage"; + import type { MermaidToExcalidrawLibProps, TTDPersistenceAdapter, @@ -25,6 +27,7 @@ export const TTDDialog = ( props: | { onTextSubmit: TTTDDialog.onTextSubmit; + renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen; renderWarning?: TTTDDialog.renderWarning; persistenceAdapter: TTDPersistenceAdapter; } @@ -39,6 +42,8 @@ export const TTDDialog = ( return ; }; +TTDDialog.WelcomeMessage = TTDWelcomeMessage; + /** * Text to diagram (TTD) dialog */ @@ -54,6 +59,7 @@ const TTDDialogBase = withInternalFallback( onTextSubmit( props: TTTDDialog.OnTextSubmitProps, ): Promise; + renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen; renderWarning?: TTTDDialog.renderWarning; persistenceAdapter: TTDPersistenceAdapter; } @@ -110,6 +116,7 @@ const TTDDialogBase = withInternalFallback( diff --git a/packages/excalidraw/components/TTDDialog/TTDWelcomeMessage.tsx b/packages/excalidraw/components/TTDDialog/TTDWelcomeMessage.tsx new file mode 100644 index 0000000000..ae213a8b60 --- /dev/null +++ b/packages/excalidraw/components/TTDDialog/TTDWelcomeMessage.tsx @@ -0,0 +1,11 @@ +import { t } from "../../i18n"; + +export const TTDWelcomeMessage = () => { + return ( +
+

{t("chat.placeholder.title")}

+

{t("chat.placeholder.description")}

+

{t("chat.placeholder.hint")}

+
+ ); +}; diff --git a/packages/excalidraw/components/TTDDialog/TextToDiagram.tsx b/packages/excalidraw/components/TTDDialog/TextToDiagram.tsx index e93775a76b..da547602aa 100644 --- a/packages/excalidraw/components/TTDDialog/TextToDiagram.tsx +++ b/packages/excalidraw/components/TTDDialog/TextToDiagram.tsx @@ -35,6 +35,7 @@ import type { const TextToDiagramContent = ({ mermaidToExcalidrawLib, onTextSubmit, + renderWelcomeScreen, renderWarning, persistenceAdapter, }: { @@ -42,6 +43,7 @@ const TextToDiagramContent = ({ onTextSubmit: ( props: TTTDDialog.OnTextSubmitProps, ) => Promise; + renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen; renderWarning?: TTTDDialog.renderWarning; persistenceAdapter: TTDPersistenceAdapter; }) => { @@ -220,6 +222,7 @@ const TextToDiagramContent = ({ onRetry={handleRetry} onViewAsMermaid={onViewAsMermaid} renderWarning={renderWarning} + renderWelcomeScreen={renderWelcomeScreen} /> {showPreview && ( ; + renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen; renderWarning?: TTTDDialog.renderWarning; persistenceAdapter: TTDPersistenceAdapter; }) => { @@ -251,6 +256,7 @@ export const TextToDiagram = ({ diff --git a/packages/excalidraw/components/TTDDialog/types.ts b/packages/excalidraw/components/TTDDialog/types.ts index d3c8e3061d..7f79894b92 100644 --- a/packages/excalidraw/components/TTDDialog/types.ts +++ b/packages/excalidraw/components/TTDDialog/types.ts @@ -116,4 +116,9 @@ export namespace TTTDDialog { export type renderWarning = ( chatMessage: TChat.ChatMessage, ) => React.ReactNode | undefined; + + export type renderWelcomeScreen = (props: { + /** null if not rate limit data currently available */ + rateLimits: RateLimits | null; + }) => React.ReactNode | undefined; }