@@ -8,6 +8,12 @@ import { SendIcon } from "./icons/SendIcon";
88import { Settings } from "./Settings" ;
99import { useMicrophone } from "../context/Microphone" ;
1010import { useNowPlaying } from "react-nowplaying" ;
11+ import { useSubmit } from "../lib/hooks/useSubmit" ;
12+
13+ // Better to use library, a lot of complexity is involved
14+ // in building the resizable input
15+ import TextareaAutosize from 'react-textarea-autosize' ;
16+
1117
1218export const Controls = ( {
1319 input,
@@ -21,6 +27,7 @@ export const Controls = ({
2127 messages : Message [ ] ;
2228} ) => {
2329 const { startMicrophone, stopMicrophone, microphoneOpen } = useMicrophone ( ) ;
30+ const { formRef, onKeyDown } = useSubmit ( )
2431
2532 useEffect ( ( ) => {
2633 startMicrophone ( ) ;
@@ -46,21 +53,23 @@ export const Controls = ({
4653 ( e : any ) => {
4754 handleSubmit ( e ) ;
4855 stopAudio ( ) ;
56+ e . target . value = '' ;
57+ handleInputChange ( e )
4958 } ,
5059 // eslint-disable-next-line react-hooks/exhaustive-deps
5160 [ stopAudio , handleSubmit ]
5261 ) ;
5362
5463 return (
55- < form onSubmit = { submitter } >
64+ < form onSubmit = { submitter } ref = { formRef } >
5665 < div className = "relative" >
5766 < div className = "absolute w-full -top-[4.5rem] py-4 flex justify-between" >
5867 < Settings />
5968 < Download messages = { messages } />
6069 </ div >
6170 < div className = "flex bg-[#101014] rounded-full" >
6271 < span
63- className = { `rounded-s-full ps-0.5 py-0.5 ${
72+ className = { `rounded-tl-[2rem] rounded-bl-[2rem] ps-0.5 py-0.5 ${
6473 microphoneOpen
6574 ? "bg-gradient-to-r bg-gradient to-[#13EF93]/50 from-red-500"
6675 : "bg-gradient-to-r bg-gradient to-[#13EF93]/50 from-[#149AFB]/80"
@@ -70,18 +79,18 @@ export const Controls = ({
7079 < a
7180 href = "#"
7281 onClick = { ( e : any ) => microphoneToggle ( e ) }
73- className = { `w- 20 sm:w-24 py-4 px-2 sm:px-8 rounded-s-full font-bold bg-[#101014] text-light-900 text-sm sm:text-base flex items-center justify-center group` }
82+ className = { `rounded-tl-[2rem] rounded-bl-[2rem] w-16 md:w- 20 sm:w-24 py-2 md:py- 4 px-2 h-full sm:px-8 font-bold bg-[#101014] text-light-900 text-sm sm:text-base flex items-center justify-center group` }
7483 >
7584 { microphoneOpen && (
7685 < div className = "w-auto items-center justify-center hidden sm:flex absolute shrink-0" >
7786 < MicrophoneIcon
7887 micOpen = { microphoneOpen }
79- className = "h-6 animate-ping-short"
88+ className = "h-5 md:h- 6 animate-ping-short"
8089 />
8190 </ div >
8291 ) }
8392 < div className = "w-auto flex items-center justify-center shrink-0" >
84- < MicrophoneIcon micOpen = { microphoneOpen } className = "h-6" />
93+ < MicrophoneIcon micOpen = { microphoneOpen } className = "h-5 md:h- 6" />
8594 </ div >
8695 { /* <span>
8796 {microphoneOpen ? (
@@ -94,24 +103,30 @@ export const Controls = ({
94103 </ Tooltip >
95104 </ span >
96105
97- < span className = "flex-grow bg-[#13EF93]/50 py-0.5" >
98- < input
99- type = "text"
100- className = "py-4 sm:px-4 w-full h-full bg-[#101014] text-light-900 border-0 text-sm sm:text-base outline-none focus:ring-0"
101- placeholder = "Type a message to send..."
102- value = { input }
103- onChange = { handleInputChange }
104- />
105- </ span >
106+ < div className = "flex-grow bg-[#13EF93]/50 py-0.5 inline" >
107+ < div className = " bg-[#101014] h-full" >
108+ < TextareaAutosize
109+ onKeyDown = { onKeyDown }
110+ rows = { 1 }
111+ spellCheck = { false }
112+ autoCorrect = "off"
113+ className = "py-2 md:py-4 -mb-[0.4rem] min-h-10 overflow-hidden sm:px-4 w-full resize-none bg-[#101014] text-light-900 border-0 text-sm sm:text-base outline-none focus:ring-0"
114+ placeholder = "Send a message"
115+ value = { input }
116+ onChange = { handleInputChange }
117+ />
118+ </ div >
106119
107- < span className = "rounded-e-full bg-gradient-to-l to-[#13EF93]/50 from-[#149AFB]/80 pe-0.5 py-0.5" >
120+ </ div >
121+
122+ < div className = "inline h-auto rounded-tr-[2rem] rounded-br-[2rem] bg-gradient-to-l to-[#13EF93]/50 from-[#149AFB]/80 pe-0.5 py-0.5" >
108123 < Tooltip showArrow content = "Send a message." >
109- < button className = "w-20 sm :w-24 py-4 px-2 sm:px-8 rounded-e-full font-bold bg-[#101014] text-light-900 text-sm sm:text-base flex items-center justify-center" >
124+ < button type = "submit" className = "w-16 md :w-24 h-full py-2 md:py- 4 px-2 rounded-tr-[2rem] rounded-br-[2rem] font-bold bg-[#101014] text-light-900 text-sm sm:text-base flex items-center justify-center" >
110125 { /* <span>Send text</span> */ }
111- < SendIcon className = "h-6 w-6" />
126+ < SendIcon className = "w-5 md: w-6" />
112127 </ button >
113128 </ Tooltip >
114- </ span >
129+ </ div >
115130 </ div >
116131 </ div >
117132 </ form >
0 commit comments