1
1
import { cn } from '@/lib/utils' ;
2
- import { ChevronDown , ChevronUp } from 'lucide-react' ;
3
- import { PropsWithChildren , useMemo , useState } from 'react' ;
2
+ import { PropsWithChildren , useMemo } from 'react' ;
4
3
5
4
import type { IStep } from '@chainlit/react-client' ;
6
5
6
+ import {
7
+ Accordion ,
8
+ AccordionContent ,
9
+ AccordionItem ,
10
+ AccordionTrigger
11
+ } from '@/components/ui/accordion' ;
7
12
import { Translator } from 'components/i18n' ;
8
13
9
14
interface Props {
@@ -16,52 +21,71 @@ export default function Step({
16
21
children,
17
22
isRunning
18
23
} : PropsWithChildren < Props > ) {
19
- const [ open , setOpen ] = useState ( false ) ;
20
24
const using = useMemo ( ( ) => {
21
25
return isRunning && step . start && ! step . end && ! step . isError ;
22
26
} , [ step , isRunning ] ) ;
23
27
24
28
const hasContent = step . input || step . output || step . steps ?. length ;
25
29
const isError = step . isError ;
26
-
27
30
const stepName = step . name ;
28
31
29
- return (
30
- < div className = "flex flex-col flex-grow w-0" >
31
- < p
32
- className = { cn (
33
- 'flex items-center gap-1 group/step' ,
34
- isError && 'text-red-500' ,
35
- hasContent && 'cursor-pointer' ,
36
- ! using && 'text-muted-foreground hover:text-foreground' ,
37
- using && 'loading-shimmer'
38
- ) }
39
- onClick = { ( ) => setOpen ( ! open ) }
40
- id = { `step-${ stepName } ` }
41
- >
42
- { using ? (
43
- < >
44
- < Translator path = "chat.messages.status.using" /> { stepName }
45
- </ >
46
- ) : (
47
- < >
48
- < Translator path = "chat.messages.status.used" /> { stepName }
49
- </ >
50
- ) }
51
- { hasContent ? (
52
- open ? (
53
- < ChevronUp className = "invisible group-hover/step:visible !size-4" />
32
+ // If there's no content, just render the status without accordion
33
+ if ( ! hasContent ) {
34
+ return (
35
+ < div className = "flex flex-col flex-grow w-0" >
36
+ < p
37
+ className = { cn (
38
+ 'flex items-center gap-1 font-medium' ,
39
+ isError && 'text-red-500' ,
40
+ ! using && 'text-muted-foreground' ,
41
+ using && 'loading-shimmer'
42
+ ) }
43
+ id = { `step-${ stepName } ` }
44
+ >
45
+ { using ? (
46
+ < >
47
+ < Translator path = "chat.messages.status.using" /> { stepName }
48
+ </ >
54
49
) : (
55
- < ChevronDown className = "invisible group-hover/step:visible !size-4" />
56
- )
57
- ) : null }
58
- < / p >
50
+ < >
51
+ < Translator path = "chat.messages.status.used" /> { stepName }
52
+ </ >
53
+ ) }
54
+ </p >
55
+ < / div >
56
+ );
57
+ }
59
58
60
- { open && (
61
- < div className = "flex-grow mt-4 ml-2 pl-4 border-l-2 border-primary" >
62
- { children }
63
- </ div >
64
- ) }
59
+ return (
60
+ < div className = "flex flex-col flex-grow w-0" >
61
+ < Accordion type = "single" collapsible className = "w-full" >
62
+ < AccordionItem value = { step . id } className = "border-none" >
63
+ < AccordionTrigger
64
+ className = { cn (
65
+ 'flex items-center gap-1 justify-start transition-none p-0 hover:no-underline' ,
66
+ isError && 'text-red-500' ,
67
+ ! using && 'text-muted-foreground hover:text-foreground' ,
68
+ using && 'loading-shimmer'
69
+ ) }
70
+ id = { `step-${ stepName } ` }
71
+ >
72
+ { using ? (
73
+ < >
74
+ < Translator path = "chat.messages.status.using" /> { stepName }
75
+ </ >
76
+ ) : (
77
+ < >
78
+ < Translator path = "chat.messages.status.used" /> { stepName }
79
+ </ >
80
+ ) }
81
+ </AccordionTrigger >
82
+ < AccordionContent >
83
+ < div className = "flex-grow mt-4 ml-1 pl-4 border-l-2 border-primary" >
84
+ { children }
85
+ </ div >
86
+ </ AccordionContent >
87
+ < / A c c o r d i o n I t e m >
88
+ </Accordion >
65
89
< / d i v >
66
90
) ;
67
91
}
0 commit comments