front-hub/src/components/ChatMessage.tsx

81 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-11-25 18:52:46 +00:00
import { Box, Typography, useMediaQuery, useTheme } from "@mui/material";
2022-11-23 11:46:04 +00:00
interface Props {
2023-04-13 16:48:17 +00:00
unAuthenticated?: boolean;
2022-11-23 11:46:04 +00:00
isSelf: boolean;
text: string;
time: string;
}
2023-04-13 16:48:17 +00:00
export default function ChatMessage({ unAuthenticated = false, isSelf, text, time }: Props) {
2022-11-24 18:08:51 +00:00
const theme = useTheme();
2022-11-25 18:52:46 +00:00
const upMd = useMediaQuery(theme.breakpoints.up("md"));
2022-11-23 11:46:04 +00:00
2023-04-13 16:48:17 +00:00
const messageBackgroundColor = isSelf ? "white" : unAuthenticated ? "#EFF0F5" : theme.palette.grey2.main;
2022-11-23 11:46:04 +00:00
return (
<Box
sx={{
display: "flex",
alignSelf: isSelf ? "end" : "start",
gap: "9px",
pl: isSelf ? undefined : "8px",
pr: isSelf ? "8px" : undefined,
}}
>
<Typography
sx={{
alignSelf: "end",
fontWeight: 400,
fontSize: "14px",
lineHeight: "17px",
order: isSelf ? 1 : 2,
2022-11-24 19:22:30 +00:00
color: theme.palette.grey2.main,
2022-11-23 11:46:04 +00:00
mb: "-4px",
}}
>{time}</Typography>
<Box
sx={{
2023-04-13 16:48:17 +00:00
backgroundColor: messageBackgroundColor,
border: unAuthenticated ? `1px solid #E3E3E3` : `1px solid ${theme.palette.grey2.main}`,
2022-11-23 11:46:04 +00:00
order: isSelf ? 2 : 1,
2022-11-25 18:52:46 +00:00
p: upMd ? "18px" : "12px",
2022-11-23 11:46:04 +00:00
borderRadius: "8px",
maxWidth: "464px",
2023-04-13 16:48:17 +00:00
color: (isSelf || unAuthenticated) ? theme.palette.grey3.main : "white",
2022-11-23 11:46:04 +00:00
position: "relative",
}}
>
<svg
style={{
position: "absolute",
top: "-1px",
right: isSelf ? "-8px" : undefined,
left: isSelf ? undefined : "-8px",
transform: isSelf ? undefined : "scale(-1, 1)",
}}
xmlns="http://www.w3.org/2000/svg"
width="16"
height="8"
viewBox="0 0 16 8"
fill="none"
>
<path d="M0.5 0.5L15.5 0.500007
C10 0.500006 7.5 8 7.5 7.5H7.5H0.5V0.5Z"
2023-04-13 16:48:17 +00:00
fill={messageBackgroundColor}
stroke={unAuthenticated ? "#E3E3E3" : theme.palette.grey2.main}
2022-11-23 11:46:04 +00:00
/>
2023-04-13 16:48:17 +00:00
<rect y="1" width="8" height="8" fill={messageBackgroundColor} />
2022-11-23 11:46:04 +00:00
</svg>
2022-11-25 18:52:46 +00:00
<Typography
sx={{
fontWeight: 400,
fontSize: "16px",
lineHeight: "19px",
}}
>{text}</Typography>
2022-11-23 11:46:04 +00:00
</Box>
2022-11-25 18:52:46 +00:00
</Box >
2022-11-23 11:46:04 +00:00
);
}