forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilot-chat-buttons.ts
More file actions
307 lines (277 loc) · 7.52 KB
/
Copy pathcopilot-chat-buttons.ts
File metadata and controls
307 lines (277 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import {
Component,
input,
output,
ChangeDetectionStrategy,
signal,
computed,
ViewEncapsulation,
} from "@angular/core";
import { CommonModule } from "@angular/common";
import {
LucideAngularModule,
ArrowUp,
Mic,
X,
Check,
Plus,
} from "lucide-angular";
import { injectChatLabels } from "../../chat-config";
import { CopilotTooltip } from "../../directives/tooltip";
import { cn } from "../../utils";
// Base button classes matching React's button variants
const buttonBase = cn(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium",
"transition-all disabled:pointer-events-none disabled:opacity-50",
"shrink-0 outline-none",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
);
const chatInputToolbarPrimary = cn(
"cursor-pointer",
// Background and text
"bg-black text-white",
// Dark mode
"dark:bg-white dark:text-black dark:focus-visible:outline-white",
// Shape and sizing
"rounded-full h-9 w-9",
// Interactions
"transition-colors",
// Focus states
"focus:outline-none",
// Hover states
"hover:opacity-70 disabled:hover:opacity-100",
// Disabled states
"disabled:cursor-not-allowed disabled:bg-[#00000014] disabled:text-[rgb(13,13,13)]",
"dark:disabled:bg-[#454545] dark:disabled:text-white",
);
const chatInputToolbarSecondary = cn(
"cursor-pointer",
// Background and text
"bg-transparent text-[#444444]",
// Dark mode
"dark:text-white dark:border-[#404040]",
// Shape and sizing
"rounded-full h-9 w-9",
// Interactions
"transition-colors",
// Focus states
"focus:outline-none",
// Hover states
"hover:bg-[#f8f8f8] hover:text-[#333333]",
"dark:hover:bg-[#404040] dark:hover:text-[#FFFFFF]",
// Disabled states
"disabled:cursor-not-allowed disabled:opacity-50",
"disabled:hover:bg-transparent disabled:hover:text-[#444444]",
"dark:disabled:hover:bg-transparent dark:disabled:hover:text-[#CCCCCC]",
);
@Component({
standalone: true,
selector: "copilot-chat-send-button",
imports: [CommonModule, LucideAngularModule],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: `
<div class="mr-[10px]">
<button
type="button"
[disabled]="disabled()"
[class]="buttonClass"
(click)="onClick()"
>
<lucide-angular [img]="ArrowUpIcon" [size]="18"></lucide-angular>
</button>
</div>
`,
styles: [``],
})
export class CopilotChatSendButton {
disabled = input(false);
clicked = output<void>();
readonly ArrowUpIcon = ArrowUp;
buttonClass = cn(buttonBase, chatInputToolbarPrimary);
onClick(): void {
if (!this.disabled) {
this.clicked.emit();
}
}
}
@Component({
standalone: true,
selector: "copilot-chat-start-transcribe-button",
imports: [CommonModule, LucideAngularModule, CopilotTooltip],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: `
<button
type="button"
[disabled]="disabled()"
[class]="buttonClass"
[copilotTooltip]="label"
tooltipPosition="below"
(click)="onClick()"
>
<lucide-angular [img]="MicIcon" [size]="18"></lucide-angular>
</button>
`,
styles: [``],
})
export class CopilotChatStartTranscribeButton {
disabled = input(false);
clicked = output<void>();
readonly labels = injectChatLabels();
readonly MicIcon = Mic;
buttonClass = cn(buttonBase, chatInputToolbarSecondary, "mr-2");
get label(): string {
return this.labels.chatInputToolbarStartTranscribeButtonLabel;
}
onClick(): void {
if (!this.disabled()) {
this.clicked.emit();
}
}
}
@Component({
standalone: true,
selector: "copilot-chat-cancel-transcribe-button",
imports: [CommonModule, LucideAngularModule, CopilotTooltip],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: `
<button
type="button"
[disabled]="disabled()"
[class]="buttonClass"
[copilotTooltip]="label"
tooltipPosition="below"
(click)="onClick()"
>
<lucide-angular [img]="XIcon" [size]="18"></lucide-angular>
</button>
`,
styles: [``],
})
export class CopilotChatCancelTranscribeButton {
disabled = input(false);
clicked = output<void>();
readonly labels = injectChatLabels();
readonly XIcon = X;
buttonClass = cn(buttonBase, chatInputToolbarSecondary, "mr-2");
get label(): string {
return this.labels.chatInputToolbarCancelTranscribeButtonLabel;
}
onClick(): void {
if (!this.disabled()) {
this.clicked.emit();
}
}
}
@Component({
standalone: true,
selector: "copilot-chat-finish-transcribe-button",
imports: [CommonModule, LucideAngularModule, CopilotTooltip],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: `
<button
type="button"
[disabled]="disabled()"
[class]="buttonClass"
[copilotTooltip]="label"
tooltipPosition="below"
(click)="onClick()"
>
<lucide-angular [img]="CheckIcon" [size]="18"></lucide-angular>
</button>
`,
styles: [``],
})
export class CopilotChatFinishTranscribeButton {
disabled = input(false);
clicked = output<void>();
readonly labels = injectChatLabels();
readonly CheckIcon = Check;
buttonClass = cn(buttonBase, chatInputToolbarSecondary, "mr-[10px]");
get label(): string {
return this.labels.chatInputToolbarFinishTranscribeButtonLabel;
}
onClick(): void {
if (!this.disabled()) {
this.clicked.emit();
}
}
}
@Component({
standalone: true,
selector: "copilot-chat-add-file-button",
imports: [CommonModule, LucideAngularModule, CopilotTooltip],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: `
<button
type="button"
[disabled]="disabled()"
[class]="buttonClass"
[copilotTooltip]="label"
tooltipPosition="below"
(click)="onClick()"
>
<lucide-angular [img]="PlusIcon" [size]="20"></lucide-angular>
</button>
`,
styles: [``],
})
export class CopilotChatAddFileButton {
disabled = input(false);
clicked = output<void>();
readonly labels = injectChatLabels();
readonly PlusIcon = Plus;
buttonClass = cn(buttonBase, chatInputToolbarSecondary, "ml-2");
get label(): string {
return this.labels.chatInputToolbarAddButtonLabel;
}
onClick(): void {
if (!this.disabled()) {
this.clicked.emit();
}
}
}
// Base toolbar button component that other buttons can use
@Component({
standalone: true,
selector: "copilot-chat-toolbar-button",
imports: [CommonModule, CopilotTooltip],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: `
<button
type="button"
[disabled]="disabled()"
[class]="computedClass()"
[copilotTooltip]="title()"
tooltipPosition="below"
(click)="onClick()"
>
<ng-content></ng-content>
</button>
`,
styles: [``],
})
export class CopilotChatToolbarButton {
disabled = signal(false);
variant = signal<"primary" | "secondary">("secondary");
customClass = signal("");
title = signal("");
clicked = output<void>();
computedClass = computed(() => {
const variantClass =
this.variant() === "primary"
? chatInputToolbarPrimary
: chatInputToolbarSecondary;
return cn(buttonBase, variantClass, this.customClass());
});
onClick(): void {
if (!this.disabled()) {
this.clicked.emit();
}
}
}