Composer.jsx 926 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from "react";
  2. import { useTranslation } from "react-i18next";
  3. import styled from "styled-components";
  4. const StyledComposer = styled.div`
  5. padding: 0.5em;
  6. flex: 0;
  7. & form {
  8. display: flex;
  9. }
  10. overflow: none;
  11. `;
  12. const Composer = ({ sendMessage }) => {
  13. const { t } = useTranslation();
  14. const [text, setText] = React.useState("");
  15. const onSubmit = (e) => {
  16. e.preventDefault();
  17. if (text) {
  18. setText("");
  19. sendMessage(text);
  20. }
  21. };
  22. const onChange = (e) => {
  23. setText(e.target.value);
  24. };
  25. return (
  26. <StyledComposer>
  27. <form onSubmit={(e) => onSubmit(e)}>
  28. <input
  29. onChange={(e) => onChange(e)}
  30. value={text}
  31. type="text"
  32. placeholder={t("Enter your message and press ENTER")}
  33. autoFocus={true}
  34. />
  35. <button>{t("Send")}</button>
  36. </form>
  37. </StyledComposer>
  38. );
  39. };
  40. export default Composer;