@@ -7,10 +7,31 @@ import PublishNew from "./icons/publish-new.svg";
7
7
import QuickStop from "./icons/quick-stop.svg" ;
8
8
import type { Backend } from "./utils" ;
9
9
10
+ export interface SenderButtonProps extends React . ComponentProps < "button" > {
11
+ /**
12
+ * Icon to display in the button.
13
+ *
14
+ * Defaults to a send icon when `isSending` is false,
15
+ * and a stop icon when `isSending` is true. The icon
16
+ * will be overridden if provided.
17
+ */
18
+ icon ?: React . ReactNode ;
19
+ /**
20
+ * Whether runtime is currently sending a message.
21
+ *
22
+ * If true, the button will display a stop icon
23
+ * instead of the send icon.
24
+ *
25
+ * @default false
26
+ */
27
+ isSending ?: boolean ;
28
+ }
10
29
export function SenderButton ( {
11
30
className,
31
+ icon,
32
+ isSending = false ,
12
33
...props
13
- } : React . ComponentProps < "button" > ) {
34
+ } : SenderButtonProps ) {
14
35
return (
15
36
< button
16
37
type = "button"
@@ -22,15 +43,48 @@ export function SenderButton({
22
43
) ,
23
44
) }
24
45
{ ...props }
25
- />
46
+ >
47
+ { icon ?? (
48
+ < img
49
+ className = "filter brightness-0 invert"
50
+ src = { isSending ? QuickStop : PublishNew }
51
+ alt = { isSending ? "icon-quick-stop" : "icon-publish-new" }
52
+ />
53
+ ) }
54
+ </ button >
26
55
) ;
27
56
}
28
57
58
+ /**
59
+ * Props for the message sender component.
60
+ * @extends React.ComponentProps<"div">
61
+ */
29
62
export interface SenderProps extends React . ComponentProps < "div" > {
63
+ /**
64
+ * Initial message to display in the input field.
65
+ * @default ""
66
+ */
30
67
initialMessage ?: string ;
68
+ /**
69
+ * Placeholder text for the input field.
70
+ * @default "Type your message here..."
71
+ */
31
72
placeholder ?: string ;
73
+ /**
74
+ * Function to handle input changes.
75
+ */
32
76
input : Backend [ "input" ] ;
77
+ /**
78
+ * Function to handle message changes.
79
+ * @param message - The new message.
80
+ */
33
81
onMessageChange ?: ( message : string ) => void ;
82
+ /**
83
+ * Function to handle the send action.
84
+ * This function is called when the send button is clicked.
85
+ * It receives an AbortController that can be used to abort the request.
86
+ * @param controller - The AbortController to abort the request.
87
+ */
34
88
onSend ?: ( controller : AbortController ) => void ;
35
89
}
36
90
export function Sender ( {
@@ -111,21 +165,7 @@ export function Sender({
111
165
< div className = "flex items-center gap-2" >
112
166
< span className = "text-sm text-gray-500" > { message . length } / 500</ span >
113
167
</ div >
114
- < SenderButton onClick = { handleSend } >
115
- { isSending ? (
116
- < img
117
- className = "filter brightness-0 invert"
118
- src = { QuickStop }
119
- alt = "icon-quick-stop"
120
- />
121
- ) : (
122
- < img
123
- className = "filter brightness-0 invert"
124
- src = { PublishNew }
125
- alt = "icon-publish-new"
126
- />
127
- ) }
128
- </ SenderButton >
168
+ < SenderButton onClick = { handleSend } isSending = { isSending } />
129
169
</ div >
130
170
</ div >
131
171
) ;
0 commit comments