An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor(ui): introduce ProcessHeader and apply to Reasoning
Yoshiki Miuraed62f8dcf9b6
diff --git a/components/process-header.tsx b/components/process-header.tsxnew file mode 100644index 00000000..1b3980f4--- /dev/null+++ b/components/process-header.tsx@@ -0,0 +1,43 @@+'use client'++import { cn } from '@/lib/utils'++export type ProcessHeaderProps = {+ label: React.ReactNode+ meta?: React.ReactNode+ onInspect?: () => void+ isLoading?: boolean+ ariaExpanded?: boolean+ className?: string+}++export function ProcessHeader({+ label,+ meta,+ onInspect,+ isLoading,+ ariaExpanded,+ className+}: ProcessHeaderProps) {+ return (+ <button+ type="button"+ onClick={onInspect}+ aria-expanded={ariaExpanded}+ className={cn(+ 'flex items-center justify-between w-full min-w-0 text-left text-sm text-muted-foreground hover:text-foreground transition-colors cursor-pointer',+ isLoading && 'animate-pulse',+ className+ )}+ >+ <span className="min-w-0 max-w-full truncate">{label}</span>+ {meta ? (+ <span className="shrink-0 ml-2 text-xs text-muted-foreground flex items-center gap-1">+ {meta}+ </span>+ ) : null}+ </button>+ )}++export default ProcessHeader+diff --git a/components/reasoning-section.tsx b/components/reasoning-section.tsxindex 08482eef..d8f78b63 100644--- a/components/reasoning-section.tsx+++ b/components/reasoning-section.tsx@@ -8,6 +8,7 @@ import { useArtifact } from '@/components/artifact/artifact-context'import { CollapsibleMessage } from './collapsible-message'import { DefaultSkeleton } from './default-skeleton'import { MarkdownMessage } from './message'+import ProcessHeader from './process-header'interface ReasoningContent {reasoning: string@@ -67,17 +68,14 @@ export function ReasoningSection({: 'Thoughts'const reasoningHeader = (- <button- type="button"- onClick={() =>+ <ProcessHeader+ label={headerLabel}+ onInspect={() =>open({ type: 'reasoning', text: content.reasoning } as ReasoningPart)}- className={`inline-flex items-center gap-1 text-left text-sm text-muted-foreground hover:text-foreground transition-colors cursor-pointer min-w-0 max-w-full w-full ${!content.isDone ? 'animate-pulse' : ''}`}- aria-expanded={isOpen}- title="Open details"- >- <span className="whitespace-nowrap truncate min-w-0 max-w-full">{headerLabel}</span>- </button>+ isLoading={!content.isDone}+ ariaExpanded={isOpen}+ />)if (!content) return <DefaultSkeleton />