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