1- import React from "react" ;
1+ import React , { useState } from "react" ;
22import propTypes from "prop-types" ;
3+ import SendRoundedIcon from '@material-ui/icons/SendRounded' ;
4+ import { IconButton , Input , Grid } from '@material-ui/core' ;
35
6+ import { makeStyles } from '@material-ui/core/styles'
47
8+ const useStyles = makeStyles ( theme => ( {
9+ root : {
10+ width : '100%' ,
11+ } ,
12+ input : {
13+ '&::placeholder' : {
14+ textOverflow : 'ellipsis !important' ,
15+ color : "black" ,
16+ opacity : 1 ,
17+ } ,
18+ } ,
19+ backDropRoot : {
20+ backgroundColor : 'inherit' ,
21+ } ,
22+ footer : {
23+ position : 'fixed' ,
24+ height : `${ theme . spacing ( 6 ) } ` ,
25+ bottom : 8 ,
26+ left : 0 ,
27+ width : '100%' ,
28+ zIndex : 1 ,
29+ } , inputContainer :{
30+ width : "90%" ,
31+ backgroundColor :theme . palette . primary . light ,
32+ padding : "8px auto" ,
33+ margin : "auto" ,
34+ borderRadius : "25px"
35+ } ,
536
6- const AddMessage = ( props ) => {
7- let input ;
37+ textArea : {
38+ paddingLeft : '15px' ,
39+ textAlign : 'left' ,
40+ } ,
41+ messageBoxIcon : {
42+ marginTop : '.35rem' ,
43+ marginRight : '.7rem' ,
44+ } ,
45+ sendIcon : {
46+ color : '#ffffff' ,
47+ } ,
48+ InputFieldContainer : {
49+ paddingRight : '15px' ,
50+ display : "flex" ,
51+ } ,
52+ } ) ) ;
53+
54+
855
56+ const AddMessage = ( props ) => {
57+ let classes = useStyles ( ) ;
58+ let [ userInput , changeName ] = useState ( "" ) ;
59+ let handleInputChange = ( e ) => {
60+ changeName ( e . target . value ) ;
61+ }
962 return (
10- < section id = "new-message" >
11- < input onKeyPress = { ( e ) => {
12- if ( e . key === "Enter" ) {
13- props . dispatch ( input . value , "Me" ) ;
14- input . value = ""
15- }
16- } } type = "text" ref = { ( node ) => { input = node } } />
17- </ section >
63+ < div className = { classes . footer } >
64+ < form onSubmit = { event => {
65+ event . preventDefault ( ) ;
66+ props . addMessage ( userInput , "out_going" ) ;
67+ changeName ( "" )
68+ } } >
69+ < Grid className = { classes . inputContainer } container spacing = { 1 } >
70+ < Grid
71+ className = { classes . InputFieldContainer }
72+ item
73+ xs = { 10 }
74+ sm = { 11 }
75+ md = { 11 }
76+ >
77+ < Input
78+ classes = { {
79+ input : classes . input ,
80+ } }
81+ fullWidth
82+ disableUnderline
83+ className = { classes . textArea }
84+ type = "text"
85+ placeholder = "Type your message.."
86+ value = { userInput }
87+ onChange = { handleInputChange }
88+ autoFocus
89+ { ...props }
90+ />
91+ </ Grid >
92+ < Grid item xs = { 2 } sm = { 1 } md = { 1 } >
93+ < IconButton
94+ className = { classes . messageBoxIcon }
95+ type = "submit"
96+ >
97+ < SendRoundedIcon className = { classes . sendIcon } fontSize = "small" />
98+ </ IconButton >
99+ </ Grid >
100+ </ Grid >
101+ </ form >
102+
103+ </ div >
104+
18105 )
19106}
20107
21- AddMessage . propTypes = {
22- dispatch : propTypes . func . isRequired
23- }
24108
25- export default AddMessage ;
109+
110+ export default AddMessage ;
0 commit comments