File tree Expand file tree Collapse file tree 4 files changed +65
-3
lines changed
components/StyledMarkdownPreview Expand file tree Collapse file tree 4 files changed +65
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { ChevronDownIcon } from "@heroicons/react/24/outline" ;
2
+ import { useState } from "react" ;
3
+
4
+ interface CollapsibleContainerProps {
5
+ children : React . ReactNode ;
6
+ maxHeight ?: string ;
7
+ className ?: string ;
8
+ collapsible ?: boolean ;
9
+ }
10
+
11
+ export function CollapsibleContainer ( {
12
+ children,
13
+ maxHeight = "max-h-40" ,
14
+ className = "" ,
15
+ collapsible = false ,
16
+ } : CollapsibleContainerProps ) {
17
+ const [ isExpanded , setIsExpanded ] = useState ( false ) ;
18
+
19
+ // If not collapsible, just render children without any collapsible behavior
20
+ if ( ! collapsible ) {
21
+ return < div className = { className } > { children } </ div > ;
22
+ }
23
+
24
+ return (
25
+ < div className = { `relative ${ className } ` } >
26
+ < div className = { `overflow-hidden ${ isExpanded ? "" : maxHeight } ` } >
27
+ { children }
28
+ </ div >
29
+
30
+ { ! isExpanded && (
31
+ < div className = "from-editor absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t to-transparent" >
32
+ < div
33
+ onClick = { ( ) => setIsExpanded ( true ) }
34
+ className = "group flex h-full cursor-pointer items-end justify-center pb-2"
35
+ >
36
+ < span title = "Expand to show full content" >
37
+ < ChevronDownIcon className = "text-lightgray group-hover:text-foreground h-4 w-4" />
38
+ </ span >
39
+ </ div >
40
+ </ div >
41
+ ) }
42
+
43
+ { isExpanded && (
44
+ < div
45
+ onClick = { ( ) => setIsExpanded ( false ) }
46
+ className = "group mt-2 flex cursor-pointer justify-center"
47
+ >
48
+ < span title = "Collapse to compact view" >
49
+ < ChevronDownIcon className = "text-lightgray group-hover:text-foreground h-4 w-4 rotate-180" />
50
+ </ span >
51
+ </ div >
52
+ ) }
53
+ </ div >
54
+ ) ;
55
+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { getFontSize } from "../../../util";
13
13
import Spinner from "../../gui/Spinner" ;
14
14
import { isTerminalCodeBlock } from "../utils" ;
15
15
import { ApplyActions } from "./ApplyActions" ;
16
+ import { CollapsibleContainer } from "./CollapsibleContainer" ;
16
17
import { CopyButton } from "./CopyButton" ;
17
18
import { CreateFileButton } from "./CreateFileButton" ;
18
19
import { FileInfo } from "./FileInfo" ;
@@ -32,6 +33,7 @@ export interface StepContainerPreToolbarProps {
32
33
children : any ;
33
34
expanded ?: boolean ;
34
35
disableManualApply ?: boolean ;
36
+ collapsible ?: boolean ;
35
37
}
36
38
37
39
export function StepContainerPreToolbar ( {
@@ -47,6 +49,7 @@ export function StepContainerPreToolbar({
47
49
children,
48
50
expanded,
49
51
disableManualApply,
52
+ collapsible,
50
53
} : StepContainerPreToolbarProps ) {
51
54
const ideMessenger = useContext ( IdeMessengerContext ) ;
52
55
const history = useAppSelector ( ( state ) => state . session . history ) ;
@@ -298,9 +301,10 @@ export function StepContainerPreToolbar({
298
301
{ renderActionButtons ( ) }
299
302
</ div >
300
303
</ div >
301
-
302
304
{ isExpanded && (
303
- < div className = "overflow-hidden overflow-y-auto" > { children } </ div >
305
+ < CollapsibleContainer collapsible = { collapsible } >
306
+ { children }
307
+ </ CollapsibleContainer >
304
308
) }
305
309
</ div >
306
310
) ;
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ interface StyledMarkdownPreviewProps {
127
127
disableManualApply ?: boolean ;
128
128
toolCallId ?: string ;
129
129
expandCodeblocks ?: boolean ;
130
+ collapsible ?: boolean ;
130
131
}
131
132
132
133
const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-" ;
@@ -305,6 +306,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
305
306
forceToolCallId = { props . toolCallId }
306
307
expanded = { props . expandCodeblocks }
307
308
disableManualApply = { props . disableManualApply }
309
+ collapsible = { props . collapsible }
308
310
>
309
311
< SyntaxHighlightedPre { ...preProps } />
310
312
</ StepContainerPreToolbar >
Original file line number Diff line number Diff line change @@ -18,12 +18,13 @@ export function EditFile(props: EditToolCallProps) {
18
18
19
19
return (
20
20
< StyledMarkdownPreview
21
- expandCodeblocks = { props . expandCodeblocks ?? false }
21
+ expandCodeblocks = { false }
22
22
isRenderingInStepContainer
23
23
disableManualApply
24
24
source = { src }
25
25
toolCallId = { props . toolCallId }
26
26
itemIndex = { props . historyIndex }
27
+ collapsible = { true }
27
28
/>
28
29
) ;
29
30
}
You can’t perform that action at this time.
0 commit comments