Skip to content

Commit 4583d21

Browse files
committed
fix(chat): wrap tool card body in collapsible panel
- render tool card content through `Collapsible` instead of a raw conditional - preserve body layout while toggling open state
1 parent b05fad8 commit 4583d21

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

apps/web/src/components/chat/_shared/ToolCard.tsx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";
22
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
3+
import { Collapsible, CollapsiblePanel } from "~/components/ui/collapsible";
34
import { cn } from "~/lib/utils";
45
import { ApprovalBadge } from "./ApprovalBadge";
56
import { StatusBadge, type ToolStatusKind } from "./StatusBadge";
@@ -151,29 +152,33 @@ export function ToolCard(props: ToolCardProps) {
151152
/>
152153
)}
153154
</HeaderRow>
154-
{anyBody && isOpen && (
155-
<div className={cn("overflow-hidden border-t border-border/20", bodyClassName)}>
156-
{showPreview && bodyAvailable && (
157-
<div className="relative">
158-
<div
159-
ref={previewRef}
160-
className="overflow-hidden"
161-
style={{ maxHeight: `${bodyMaxPreviewPx}px` }}
162-
>
163-
{body}
164-
</div>
165-
{showFullCtaVisible && <ShowFullButton onClick={expandFully} />}
166-
</div>
167-
)}
168-
{showExpanded && (
169-
<>
170-
{expandedBodyAvailable ? expandedBody : body}
171-
{bodyAvailable && (
172-
<HideButton onClick={() => setState(bodyAvailable ? "preview" : "collapsed")} />
155+
{anyBody && (
156+
<Collapsible open={isOpen}>
157+
<CollapsiblePanel>
158+
<div className={cn("border-t border-border/20", bodyClassName)}>
159+
{showPreview && bodyAvailable && (
160+
<div className="relative">
161+
<div
162+
ref={previewRef}
163+
className="overflow-hidden"
164+
style={{ maxHeight: `${bodyMaxPreviewPx}px` }}
165+
>
166+
{body}
167+
</div>
168+
{showFullCtaVisible && <ShowFullButton onClick={expandFully} />}
169+
</div>
170+
)}
171+
{showExpanded && (
172+
<>
173+
{expandedBodyAvailable ? expandedBody : body}
174+
{bodyAvailable && (
175+
<HideButton onClick={() => setState(bodyAvailable ? "preview" : "collapsed")} />
176+
)}
177+
</>
173178
)}
174-
</>
175-
)}
176-
</div>
179+
</div>
180+
</CollapsiblePanel>
181+
</Collapsible>
177182
)}
178183
</div>
179184
);

0 commit comments

Comments
 (0)