1
1
import { Loader2 , MessageSquare , Send , Trash2 , X } from 'lucide-react' ;
2
- import React , { ChangeEvent , KeyboardEvent , useEffect , useRef , useState } from 'react' ;
2
+ import React , {
3
+ ChangeEvent ,
4
+ KeyboardEvent ,
5
+ useEffect ,
6
+ useRef ,
7
+ useState ,
8
+ } from 'react' ;
3
9
4
10
import { Alert , AlertDescription } from '@/components/ui/alert' ;
5
11
import {
@@ -19,6 +25,10 @@ import { Textarea } from '@/components/ui/textarea';
19
25
20
26
import { ChatMessage , ChatMessageType } from './chat-message' ;
21
27
28
+ type CustomElemProps = {
29
+ onSend : ( message : string ) => void ;
30
+ } ;
31
+
22
32
interface ChatLayoutProps {
23
33
isOpen : boolean ;
24
34
onClose : ( ) => void ;
@@ -28,9 +38,10 @@ interface ChatLayoutProps {
28
38
error : string | null ;
29
39
title : string ;
30
40
onClearHistory ?: ( ) => void ;
41
+ CustomPlaceHolderElem ?: React . FC < CustomElemProps > ;
31
42
}
32
43
33
- export const ChatLayout : React . FC < ChatLayoutProps > = ( {
44
+ export const ChatLayout = ( {
34
45
isOpen,
35
46
onClose,
36
47
messages,
@@ -39,7 +50,8 @@ export const ChatLayout: React.FC<ChatLayoutProps> = ({
39
50
error,
40
51
title,
41
52
onClearHistory,
42
- } ) => {
53
+ CustomPlaceHolderElem,
54
+ } : ChatLayoutProps ) => {
43
55
const [ input , setInput ] = useState < string > ( '' ) ;
44
56
const inputRef = useRef < HTMLTextAreaElement > ( null ) ;
45
57
const messagesEndRef = useRef < HTMLDivElement > ( null ) ;
@@ -132,8 +144,14 @@ export const ChatLayout: React.FC<ChatLayoutProps> = ({
132
144
< ScrollArea id = 'chat-messages' className = 'h-full flex-1 overflow-y-auto p-4' >
133
145
{ messages . length === 0 && (
134
146
< div className = 'flex h-full flex-col items-center justify-center text-gray-500' >
135
- < MessageSquare className = 'mb-4 size-12 opacity-50' />
136
- < p className = 'text-center' > No messages yet. Start a conversation!</ p >
147
+ { CustomPlaceHolderElem ? (
148
+ < CustomPlaceHolderElem onSend = { onSend } />
149
+ ) : (
150
+ < >
151
+ < MessageSquare className = 'mb-4 size-12 opacity-50' />
152
+ < p className = 'text-center' > No messages yet. Start a conversation!</ p >
153
+ </ >
154
+ ) }
137
155
</ div >
138
156
) }
139
157
{ messages . map ( ( msg , index ) => (
0 commit comments