User.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Avatar, Popover, Space, Typography } from "antd";
  2. import { getAvatarColor } from "./Studio";
  3. const { Text } = Typography;
  4. interface IWidget {
  5. id?: string;
  6. nickName?: string;
  7. userName?: string;
  8. avatar?: string;
  9. showAvatar?: boolean;
  10. showName?: boolean;
  11. showUserName?: boolean;
  12. hidePopover?: boolean;
  13. }
  14. const UserWidget = ({
  15. nickName,
  16. userName,
  17. avatar,
  18. showAvatar = true,
  19. showName = true,
  20. showUserName = false,
  21. hidePopover = false,
  22. }: IWidget) => {
  23. const inner = (
  24. <Space>
  25. {showAvatar ? (
  26. <Avatar
  27. size={"small"}
  28. src={avatar}
  29. style={
  30. avatar ? undefined : { backgroundColor: getAvatarColor(nickName) }
  31. }
  32. >
  33. {nickName?.slice(0, 2)}
  34. </Avatar>
  35. ) : undefined}
  36. {showName ? <Text>{nickName}</Text> : undefined}
  37. {showName && showUserName ? <Text>@</Text> : undefined}
  38. {showUserName ? <Text>{userName}</Text> : undefined}
  39. </Space>
  40. );
  41. return hidePopover ? (
  42. inner
  43. ) : (
  44. <Popover
  45. content={
  46. <div>
  47. <div>
  48. <Avatar
  49. size="large"
  50. src={avatar}
  51. style={
  52. avatar
  53. ? undefined
  54. : { backgroundColor: getAvatarColor(nickName) }
  55. }
  56. >
  57. {nickName?.slice(0, 2)}
  58. </Avatar>
  59. </div>
  60. <Text>{`${nickName}@${userName}`}</Text>
  61. </div>
  62. }
  63. >
  64. {inner}
  65. </Popover>
  66. );
  67. };
  68. export default UserWidget;