Skip to content

Commit 935fa01

Browse files
committed
feat: Use Collapsible component for Thinking Block UI
1 parent 0ec3689 commit 935fa01

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed
Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<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';
46
import { Card } from '$lib/components/ui/card';
57
import { MarkdownContent } from '$lib/components/app';
6-
import { slide } from 'svelte/transition';
78
89
interface Props {
910
reasoningContent: string | null;
@@ -16,40 +17,42 @@
1617
1718
let isExpanded = $state(true);
1819
19-
// Auto-collapse when reasoning finishes and regular content starts
20+
// Auto-collapse when regular content starts (even while streaming)
2021
$effect(() => {
21-
if (!isStreaming && hasRegularContent && reasoningContent) {
22+
if (hasRegularContent && reasoningContent) {
2223
isExpanded = false;
2324
}
2425
});
2526
</script>
2627

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>
4749

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>
5255
</div>
53-
</div>
54-
{/if}
55-
</Card>
56+
</Collapsible.Content>
57+
</Card>
58+
</Collapsible.Root>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts">
2+
import { Collapsible as CollapsiblePrimitive } from "bits-ui";
3+
4+
let { ref = $bindable(null), ...restProps }: CollapsiblePrimitive.ContentProps = $props();
5+
</script>
6+
7+
<CollapsiblePrimitive.Content bind:ref data-slot="collapsible-content" {...restProps} />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts">
2+
import { Collapsible as CollapsiblePrimitive } from "bits-ui";
3+
4+
let { ref = $bindable(null), ...restProps }: CollapsiblePrimitive.TriggerProps = $props();
5+
</script>
6+
7+
<CollapsiblePrimitive.Trigger bind:ref data-slot="collapsible-trigger" {...restProps} />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script lang="ts">
2+
import { Collapsible as CollapsiblePrimitive } from "bits-ui";
3+
4+
let {
5+
ref = $bindable(null),
6+
open = $bindable(false),
7+
...restProps
8+
}: CollapsiblePrimitive.RootProps = $props();
9+
</script>
10+
11+
<CollapsiblePrimitive.Root bind:ref bind:open data-slot="collapsible" {...restProps} />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Root from "./collapsible.svelte";
2+
import Trigger from "./collapsible-trigger.svelte";
3+
import Content from "./collapsible-content.svelte";
4+
5+
export {
6+
Root,
7+
Content,
8+
Trigger,
9+
//
10+
Root as Collapsible,
11+
Content as CollapsibleContent,
12+
Trigger as CollapsibleTrigger,
13+
};

0 commit comments

Comments
 (0)