Skip to content

Commit 54a84e5

Browse files
feat: add clear button to additional context input with tests
1 parent 6275223 commit 54a84e5

File tree

2 files changed

+84
-39
lines changed

2 files changed

+84
-39
lines changed

src/lib/components/AdditionalContext.svelte

Lines changed: 73 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,76 @@
22
// biome-ignore lint/style/useConst: Svelte 5 $props() pattern
33
let { additionalContext = $bindable(''), expanded = $bindable(false) } = $props()
44
</script>
5-
6-
<details class="context-details" bind:open={expanded}>
7-
<summary>add more context</summary>
8-
<textarea
9-
class="context-input"
10-
rows="4"
11-
bind:value={additionalContext}
12-
placeholder="anything else we should know about?"
13-
></textarea>
14-
</details>
15-
16-
<style>
17-
details.context-details {
18-
text-align: left;
19-
border: 1px solid var(--light);
20-
background-color: var(--white);
21-
border-radius: var(--border-radius);
22-
padding: 1rem;
23-
margin-bottom: 1rem;
24-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
25-
}
26-
27-
details summary {
28-
cursor: pointer;
29-
font-weight: 500;
30-
}
31-
32-
textarea.context-input {
33-
font-family: var(--label-font);
34-
width: 100%;
35-
margin-top: 0.75rem;
36-
padding: 0.75rem;
37-
border: 1px solid var(--light);
38-
border-radius: var(--border-radius);
39-
resize: vertical;
40-
min-height: 80px;
41-
color: var(--primary-dark);
42-
}
43-
</style>
5+
6+
<details class="context-details" bind:open={expanded}>
7+
<summary>add more context</summary>
8+
<textarea
9+
class="context-input"
10+
rows="4"
11+
bind:value={additionalContext}
12+
placeholder="anything else we should know about?"
13+
></textarea>
14+
{#if additionalContext.trim() !== ''}
15+
<div class="button-container">
16+
<button
17+
type="button"
18+
class="clear-button"
19+
onclick={() => {
20+
additionalContext = ''
21+
}}
22+
>
23+
clear
24+
</button>
25+
</div>
26+
{/if}
27+
</details>
28+
29+
<style>
30+
details.context-details {
31+
text-align: left;
32+
border: 1px solid var(--light);
33+
background-color: var(--white);
34+
border-radius: var(--border-radius);
35+
padding: 1rem;
36+
margin-bottom: 1rem;
37+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
38+
}
39+
40+
details summary {
41+
cursor: pointer;
42+
font-weight: 500;
43+
}
44+
45+
textarea.context-input {
46+
font-family: var(--label-font);
47+
width: 100%;
48+
margin-top: 0.75rem;
49+
padding: 0.75rem;
50+
border: 1px solid var(--light);
51+
border-radius: var(--border-radius);
52+
resize: vertical;
53+
min-height: 80px;
54+
color: var(--primary-dark);
55+
}
56+
57+
.clear-button {
58+
border: none;
59+
background-color: var(--light);
60+
color: var(--primary-dark);
61+
border-radius: var(--border-radius);
62+
padding: 0.25rem 0.75rem;
63+
cursor: pointer;
64+
}
65+
66+
.clear-button:hover {
67+
background-color: var(--primary-dark);
68+
color: var(--white);
69+
}
70+
71+
.button-container {
72+
display: flex;
73+
justify-content: flex-end;
74+
margin-top: 0.5rem;
75+
}
76+
</style>
77+

tests/lib/components/AdditionalContext.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class AdditionalContextModel {
66
expanded: boolean
77
changeContext: (newContext: string) => void
88
toggleExpanded: () => void
9+
clearContext: () => void
910

1011
constructor(initialContext = '', initialExpanded = false) {
1112
this.additionalContext = initialContext
@@ -15,6 +16,10 @@ class AdditionalContextModel {
1516
this.additionalContext = newContext
1617
}
1718

19+
this.clearContext = () => {
20+
this.additionalContext = ''
21+
}
22+
1823
this.toggleExpanded = () => {
1924
this.expanded = !this.expanded
2025
}
@@ -50,4 +55,10 @@ describe('AdditionalContext Component', () => {
5055
component.toggleExpanded()
5156
expect(component.expanded).toBe(false)
5257
})
58+
59+
it('should clear additionalContext', () => {
60+
const component = new AdditionalContextModel('hey')
61+
component.clearContext()
62+
expect(component.additionalContext).toBe('')
63+
})
5364
})

0 commit comments

Comments
 (0)