import { useState } from "react"; import { Check, CircleAlert } from "lucide-react"; import { AttachmentTile } from "@/components/AttachmentTile"; import { CodeBlock } from "@/components/CodeBlock"; import { ImageLightbox } from "@/components/ImageLightbox"; import { ZoomableImage } from "@/components/ZoomableImage"; import { Button } from "@/components/ui/button"; import sampleVideo from "./fixtures/sample.webm"; import { ImageGallery } from "@/components/ImageGallery"; import { MarkdownText } from "@/components/MarkdownText"; import { MessageBubble } from "@/components/MessageBubble"; import { FileReferenceChip } from "@/components/FileReferenceChip"; import { ActivityStep } from "@/components/thread/activity/ActivityStep"; import { ReasoningRow } from "@/components/thread/activity/ReasoningRow"; import { ThinkingReasoningShell } from "@/components/thread/activity/ThinkingReasoningShell"; import { FileEditGroup, type FileEditSummary } from "@/components/thread/activity/FileEditRow"; import { GenericToolRun } from "@/components/thread/activity/GenericToolRun"; import { SettingsGroup, SettingsRow, SettingsSectionTitle } from "@/components/settings/shared/SettingsControls"; import { SettingsFeature } from "@/components/settings/shared/SettingsFeature"; import { Input } from "@/components/ui/input"; import { ToggleButton } from "@/components/ui/toggle-button"; import type { UIMessage } from "@/lib/types"; import { Sample, StatePicker, type ComponentExample } from "./example"; import { useGalleryTranslation } from "./i18n"; const markdown = `## A small result\n\nA reply can contain **emphasis**, a list, and inline math $a^2 + b^2 = c^2$.\n\n- Read the source\n- Reuse the existing component\n\n| Item | State |\n| --- | --- |\n| UI | Ready |\n\n\`\`\`python\nprint("Hello, Nanobot")\n\`\`\``; function MarkdownPreview() { const { t } = useGalleryTranslation(); const [state, setState] = useState<"complete" | "streaming">("complete"); return <> {state === "streaming" ? markdown.slice(0, 100) : markdown}; } function CodePreview() { const { t } = useGalleryTranslation(); const [mode, setMode] = useState<"code" | "terminal" | "viewport">("code"); return <> \n Save changes\n'} />; } function MessagePreview() { const { t } = useGalleryTranslation(); const [state, setState] = useState<"answer" | "thinking" | "streaming" | "sending" | "failed">("answer"); const user: UIMessage = { id: "gallery-user", role: "user", content: "Show me how this component works.", createdAt: Date.UTC(2026, 0, 1, 12), deliveryStatus: state === "sending" ? "sending" : state === "failed" ? "failed" : "accepted", deliveryErrorKind: state === "failed" ? "turn_rejected" : undefined, }; const assistant: UIMessage = { id: "gallery-assistant", role: "assistant", createdAt: user.createdAt + 1000, content: state === "thinking" ? "" : "Here is a **reusable message** with the same typography and actions as the chat.", isStreaming: state === "thinking" || state === "streaming", }; return <>
{state !== "sending" && state !== "failed" ? : null}
; } function ActivityPreview() { const { t } = useGalleryTranslation(); const [state, setState] = useState<"running" | "done" | "error">("running"); const [expanded, setExpanded] = useState(true); return <> setExpanded((value) => !value)}> ; } function FilesPreview() { const { t } = useGalleryTranslation(); const [state, setState] = useState<"done" | "editing" | "error">("done"); const [operation, setOperation] = useState<"create" | "edit" | "delete">("edit"); const [display, setDisplay] = useState<"summary" | "diff" | "collapsed_diff">("diff"); const [opened, setOpened] = useState(""); const diffs = { create: '@@ -0,0 +1 @@\n+export const greeting = "Hello, Nanobot";\n', edit: '@@ -1,2 +1,2 @@\n-export const greeting = "Hello";\n+export const greeting = "Hello, Nanobot";\n export const ready = true;\n', delete: '@@ -1 +0,0 @@\n-export const greeting = "Hello";\n', }; const edit: FileEditSummary = { key: "example-edit", path: "src/greeting.ts", added: operation === "delete" ? 0 : 1, deleted: operation === "create" ? 0 : 1, approximate: false, binary: false, status: state, pending: state === "editing", operation, error: state === "error" ? t("controls.files.error") : undefined, diff: { format: "unified", text: diffs[operation] }, }; return <>

{opened ? t("controls.files.selected", { path: opened }) : t("controls.files.hint")}

; } const mediaImages = ["#2563eb", "#0d9488", "#9333ea", "#ea580c", "#be123c", "#4f46e5"].map((color, index) => ({ number: index + 1, url: `data:image/svg+xml,${encodeURIComponent(`${index + 1}`)}`, })); function useMediaImages() { const { t } = useGalleryTranslation(); return mediaImages.map(({ number, url }) => ({ name: t("controls.media.study", { count: number }), url })); } function ImageGalleryPreview() { const { t } = useGalleryTranslation(); const images = useMediaImages(); return

{t("controls.imageGallery.hint")}

; } function ImageLightboxPreview() { const { t } = useGalleryTranslation(); const images = useMediaImages(); const [index, setIndex] = useState(null); return

{t("controls.imageLightbox.hint")}

{ if (!open) setIndex(null); }} />
; } function ZoomableImagePreview() { const { t } = useGalleryTranslation(); const images = useMediaImages(); return

{t("controls.zoomableImage.hint")}

; } function AttachmentTilePreview() { const { t } = useGalleryTranslation(); const images = useMediaImages(); return
{(["image", "video", "file"] as const).map((kind) => )}
; } function SettingsPreview() { const { t } = useGalleryTranslation(); const [enabled, setEnabled] = useState(false); return
{t("controls.settingsComposition.preferences")}
; } function FileReferencePreview() { const { t } = useGalleryTranslation(); const [selected, setSelected] = useState(""); return

{selected || t("controls.fileReference.select")}

; } const components = "webui/src/components/"; export const sharedExamples: ComponentExample[] = [ { title: "controls.markdown.title", files: ["MarkdownText", "MarkdownTextRenderer"], Preview: MarkdownPreview, description: "controls.markdown.description", options: "controls.markdown.options", code: '{content}' }, { title: "controls.code.title", files: ["CodeBlock", "ViewportCodeRows"], Preview: CodePreview, description: "controls.code.description", options: "controls.code.options", code: '' }, { title: "controls.math.title", files: ["DisplayMath"], Preview: () => {"$$\nE = mc^2\n$$"}, description: "controls.math.description", options: "controls.math.options", code: '{"$$\\nE = mc^2\\n$$"}' }, { title: "controls.message.title", files: ["MessageBubble"], Preview: MessagePreview, description: "controls.message.description", options: "controls.message.options", code: '' }, { title: "controls.activity.title", files: ["thread/activity/ActivityStep", "thread/activity/ReasoningRow", "thread/activity/ThinkingReasoningShell", "thread/activity/GenericToolRun"], Preview: ActivityPreview, description: "controls.activity.description", options: "controls.activity.options", code: '\n' }, { title: "controls.files.title", files: ["thread/activity/FileEditRow", "thread/activity/DiffPair", "thread/activity/DiffSyntaxHighlight"], Preview: FilesPreview, description: "controls.files.description", options: "controls.files.options", code: '' }, { title: "controls.imageGallery.title", files: ["ImageGallery"], Preview: ImageGalleryPreview, description: "controls.imageGallery.description", options: "controls.imageGallery.options", code: '\n' }, { title: "controls.imageLightbox.title", files: ["ImageLightbox"], Preview: ImageLightboxPreview, description: "controls.imageLightbox.description", options: "controls.imageLightbox.options", code: ' { if (!open) setIndex(null); }} />' }, { title: "controls.zoomableImage.title", files: ["ZoomableImage"], Preview: ZoomableImagePreview, description: "controls.zoomableImage.description", options: "controls.zoomableImage.options", code: '
\n \n
' }, { title: "controls.attachment.title", files: ["AttachmentTile"], Preview: AttachmentTilePreview, description: "controls.attachment.description", options: "controls.attachment.options", code: '\n\n' }, { title: "controls.fileReference.title", files: ["FileReferenceChip"], Preview: FileReferencePreview, description: "controls.fileReference.description", options: "controls.fileReference.options", code: '' }, { title: "controls.settingsComposition.title", files: ["settings/shared/SettingsControls", "settings/shared/SettingsFeature"], Preview: SettingsPreview, description: "controls.settingsComposition.description", options: "controls.settingsComposition.options", code: '' }, ].map((example) => ({ ...example, files: example.files.map((file) => `${components}${file}.tsx`) }));