index.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import Avatar from "@material-ui/core/Avatar";
  3. import ListItemText from '@mui/material/ListItemText';
  4. import { firstLetter, slicedWord, timeStamp } from '../../../../../../helpers'
  5. const useStyles = makeStyles({
  6. container: {
  7. display: "flex",
  8. justifyContent: "flex-end",
  9. width:'auto',
  10. maxWidth: '80%',
  11. },
  12. messageVertical: {
  13. position:'relative',
  14. display: 'flex',
  15. alignContent: 'center',
  16. alignItems: 'flex-end',
  17. marginBottom: "10px",
  18. },
  19. message: {
  20. position: "relative",
  21. marginRight: 5,
  22. padding: "10px",
  23. paddingBottom:18,
  24. backgroundColor: "#deffa9",
  25. wordBreak:'break-word',
  26. textAlign: "left",
  27. font: "400 .9em 'Open Sans', sans-serif",
  28. border: "1px solid #d5ff91",
  29. borderRadius: "10px",
  30. "&:after": {
  31. content: "''",
  32. position: "absolute",
  33. width: "0",
  34. height: "0",
  35. borderBottom: "15px solid #deffa9",
  36. borderLeft: "15px solid transparent",
  37. borderRight: "15px solid transparent",
  38. bottom: "0",
  39. right: "-15px"
  40. },
  41. "&:before": {
  42. content: "''",
  43. position: "absolute",
  44. width: "0",
  45. height: "0",
  46. borderBottom: "17px solid #deffa9",
  47. borderLeft: "16px solid transparent",
  48. borderRight: "16px solid transparent",
  49. bottom: "-1px",
  50. right: "-17px"
  51. }
  52. },
  53. messageTime: {
  54. position: "absolute",
  55. fontSize: ".65em",
  56. fontWeight:600,
  57. marginTop: "10px",
  58. bottom: "12px",
  59. left: 10,
  60. color: '#4d4c4c',
  61. },
  62. });
  63. interface IMessageRight {
  64. message:string,
  65. avatarUrl:string,
  66. name:string,
  67. lastName:string,
  68. updatedAt:string,
  69. color:string
  70. }
  71. const MessageRight = ({message,avatarUrl,name,lastName,updatedAt,color}:IMessageRight) => {
  72. const classes = useStyles();
  73. return (
  74. <div className={classes.container}>
  75. <div className={classes.messageVertical}>
  76. <ListItemText className={classes.message}
  77. primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
  78. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  79. primaryTypographyProps={{color: "#42aee0"}}
  80. secondary={message}
  81. secondaryTypographyProps={{ color: "#0e0d0d" }} />
  82. <div className={classes.messageTime}>{timeStamp(updatedAt)}</div>
  83. <Avatar
  84. alt='avatar'
  85. src={avatarUrl ? `http://localhost:3000/${avatarUrl}` : undefined}
  86. style={{ background: color, width: 40, height: 40, marginBottom: 13 }}>
  87. {!avatarUrl && `${firstLetter(name)}${firstLetter(lastName)}`}</Avatar>
  88. </div>
  89. </div>
  90. )};
  91. export default MessageRight