akhaliq HF Staff commited on
Commit
70ecf69
·
verified ·
1 Parent(s): 9399156

Upload components/ChatInput.jsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/ChatInput.jsx +63 -0
components/ChatInput.jsx ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react'
2
+
3
+ export default function ChatInput({ onSendMessage, disabled }) {
4
+ const [message, setMessage] = useState('')
5
+
6
+ const handleSubmit = (e) => {
7
+ e.preventDefault()
8
+ if (message.trim() && !disabled) {
9
+ onSendMessage(message)
10
+ setMessage('')
11
+ }
12
+ }
13
+
14
+ const handleKeyDown = (e) => {
15
+ if (e.key === 'Enter' && !e.shiftKey) {
16
+ e.preventDefault()
17
+ handleSubmit(e)
18
+ }
19
+ }
20
+
21
+ return (
22
+ <div className="bg-white dark:bg-gray-800 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-700 p-4 mt-4">
23
+ <form onSubmit={handleSubmit} className="flex items-end space-x-3">
24
+ <div className="flex-1">
25
+ <textarea
26
+ value={message}
27
+ onChange={(e) => setMessage(e.target.value)}
28
+ onKeyDown={handleKeyDown}
29
+ placeholder="Type your message..."
30
+ disabled={disabled}
31
+ rows={1}
32
+ className="w-full resize-none bg-transparent border-0 focus:outline-none text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-gray-500 text-sm md:text-base disabled:opacity-50"
33
+ />
34
+ </div>
35
+
36
+ <button
37
+ type="submit"
38
+ disabled={disabled || !message.trim()}
39
+ className="flex-shrink-0 bg-gradient-to-br from-primary-500 to-primary-600 hover:from-primary-600 hover:to-primary-700 text-white rounded-xl p-3 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed shadow-md hover:shadow-lg transform hover:scale-105 active:scale-95"
40
+ aria-label="Send message"
41
+ >
42
+ <svg
43
+ className="w-5 h-5"
44
+ fill="none"
45
+ stroke="currentColor"
46
+ viewBox="0 0 24 24"
47
+ >
48
+ <path
49
+ strokeLinecap="round"
50
+ strokeLinejoin="round"
51
+ strokeWidth={2}
52
+ d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"
53
+ />
54
+ </svg>
55
+ </button>
56
+ </form>
57
+
58
+ <p className="text-xs text-gray-400 dark:text-gray-500 mt-2">
59
+ Press Enter to send, Shift + Enter for new line
60
+ </p>
61
+ </div>
62
+ )
63
+ }