|
1 | 1 | <script lang="ts"> |
2 | | - import { ChevronDown, Brain } from '@lucide/svelte'; |
3 | | - import { Button } from '$lib/components/ui/button'; |
| 2 | + import { Brain } from '@lucide/svelte'; |
| 3 | + import ChevronsUpDownIcon from '@lucide/svelte/icons/chevrons-up-down'; |
| 4 | + import * as Collapsible from '$lib/components/ui/collapsible/index.js'; |
| 5 | + import { buttonVariants } from '$lib/components/ui/button/index.js'; |
4 | 6 | import { Card } from '$lib/components/ui/card'; |
5 | 7 | import { MarkdownContent } from '$lib/components/app'; |
6 | | - import { slide } from 'svelte/transition'; |
7 | 8 |
|
8 | 9 | interface Props { |
9 | 10 | reasoningContent: string | null; |
|
16 | 17 |
|
17 | 18 | let isExpanded = $state(true); |
18 | 19 |
|
19 | | - // Auto-collapse when reasoning finishes and regular content starts |
| 20 | + // Auto-collapse when regular content starts (even while streaming) |
20 | 21 | $effect(() => { |
21 | | - if (!isStreaming && hasRegularContent && reasoningContent) { |
| 22 | + if (hasRegularContent && reasoningContent) { |
22 | 23 | isExpanded = false; |
23 | 24 | } |
24 | 25 | }); |
25 | 26 | </script> |
26 | 27 |
|
27 | | -<Card class="border-muted bg-muted/30 mb-6 gap-0 py-0 {className}"> |
28 | | - <Button |
29 | | - variant="ghost" |
30 | | - class="h-auto w-full justify-between p-3 font-normal" |
31 | | - onclick={() => (isExpanded = !isExpanded)} |
32 | | - > |
33 | | - <div class="text-muted-foreground flex items-center gap-2"> |
34 | | - <Brain class="h-4 w-4" /> |
35 | | - |
36 | | - <span class="text-sm"> |
37 | | - {isStreaming ? 'Reasoning...' : 'Reasoning'} |
38 | | - </span> |
39 | | - </div> |
40 | | - |
41 | | - <ChevronDown |
42 | | - class="text-muted-foreground h-4 w-4 transition-transform duration-200 {isExpanded |
43 | | - ? 'rotate-180' |
44 | | - : ''}" |
45 | | - /> |
46 | | - </Button> |
| 28 | +<Collapsible.Root bind:open={isExpanded} class="mb-6 {className}"> |
| 29 | + <Card class="border-muted bg-muted/30 gap-0 py-0"> |
| 30 | + <Collapsible.Trigger class="cursor-pointer flex items-center justify-between p-3"> |
| 31 | + <div class="text-muted-foreground flex items-center gap-2"> |
| 32 | + <Brain class="h-4 w-4" /> |
| 33 | + <span class="text-sm font-medium"> |
| 34 | + {isStreaming ? 'Reasoning...' : 'Reasoning'} |
| 35 | + </span> |
| 36 | + </div> |
| 37 | + |
| 38 | + <div |
| 39 | + class={buttonVariants({ |
| 40 | + variant: "ghost", |
| 41 | + size: "sm", |
| 42 | + class: "h-6 w-6 p-0 text-muted-foreground hover:text-foreground" |
| 43 | + })} |
| 44 | + > |
| 45 | + <ChevronsUpDownIcon class="h-4 w-4" /> |
| 46 | + <span class="sr-only">Toggle reasoning content</span> |
| 47 | + </div> |
| 48 | + </Collapsible.Trigger> |
47 | 49 |
|
48 | | - {#if isExpanded} |
49 | | - <div class="border-muted border-t px-3 pb-3" transition:slide={{ duration: 200 }}> |
50 | | - <div class="pt-3"> |
51 | | - <MarkdownContent content={reasoningContent || ''} class="text-xs leading-relaxed" /> |
| 50 | + <Collapsible.Content> |
| 51 | + <div class="border-muted border-t px-3 pb-3"> |
| 52 | + <div class="pt-3"> |
| 53 | + <MarkdownContent content={reasoningContent || ''} class="text-xs leading-relaxed" /> |
| 54 | + </div> |
52 | 55 | </div> |
53 | | - </div> |
54 | | - {/if} |
55 | | -</Card> |
| 56 | + </Collapsible.Content> |
| 57 | + </Card> |
| 58 | +</Collapsible.Root> |
0 commit comments