react-garden
Version:
React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.
76 lines (66 loc) • 2.28 kB
JavaScript
// ** React Imports
import { useState } from 'react'
// ** MUI Imports
import Button from '@mui/material/Button'
import { styled } from '@mui/material/styles'
import TextField from '@mui/material/TextField'
import IconButton from '@mui/material/IconButton'
import Box from '@mui/material/Box'
// ** Icons Imports
import Microphone from 'mdi-material-ui/Microphone'
import Attachment from 'mdi-material-ui/Attachment'
// ** Styled Components
const ChatFormWrapper = styled(Box)(({ theme }) => ({
display: 'flex',
alignItems: 'center',
boxShadow: theme.shadows[1],
padding: theme.spacing(1.25, 4),
justifyContent: 'space-between',
borderRadius: theme.shape.borderRadius,
backgroundColor: theme.palette.background.paper
}))
const Form = styled('form')(({ theme }) => ({
padding: theme.spacing(0, 5, 5)
}))
const SendMsgForm = props => {
// ** Props
const { store, dispatch, sendMsg } = props
// ** State
const [msg, setMsg] = useState('')
const handleSendMsg = e => {
e.preventDefault()
if (store && store.selectedChat && msg.trim().length) {
dispatch(sendMsg({ ...store.selectedChat, message: msg }))
}
setMsg('')
}
return (
<Form onSubmit={handleSendMsg}>
<ChatFormWrapper>
<Box sx={{ flexGrow: 1, display: 'flex', alignItems: 'center' }}>
<TextField
fullWidth
value={msg}
size='small'
placeholder='Type your message here…'
onChange={e => setMsg(e.target.value)}
sx={{ '& .MuiOutlinedInput-input': { pl: 0 }, '& fieldset': { border: '0 !important' } }}
/>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<IconButton size='small' sx={{ color: 'text.primary' }}>
<Microphone sx={{ fontSize: '1.375rem' }} />
</IconButton>
<IconButton size='small' component='label' htmlFor='upload-img' sx={{ mr: 4, color: 'text.primary' }}>
<Attachment sx={{ fontSize: '1.375rem' }} />
<input hidden type='file' id='upload-img' />
</IconButton>
<Button type='submit' variant='contained'>
Send
</Button>
</Box>
</ChatFormWrapper>
</Form>
)
}
export default SendMsgForm