SentEditMenu.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Button, Dropdown, Menu } from "antd";
  2. import { useState } from "react";
  3. import { EditOutlined, CopyOutlined, MoreOutlined } from "@ant-design/icons";
  4. interface ISentEditMenu {
  5. children?: React.ReactNode;
  6. onModeChange?: Function;
  7. }
  8. const Widget = ({ children, onModeChange }: ISentEditMenu) => {
  9. const [isHover, setIsHover] = useState(false);
  10. const menu = (
  11. <Menu
  12. onClick={(e) => {
  13. console.log(e);
  14. }}
  15. items={[
  16. {
  17. key: "en",
  18. label: "时间线",
  19. },
  20. {
  21. key: "zh-Hans",
  22. label: "分享",
  23. },
  24. ]}
  25. />
  26. );
  27. return (
  28. <div
  29. onMouseEnter={() => {
  30. setIsHover(true);
  31. }}
  32. onMouseLeave={() => {
  33. setIsHover(false);
  34. }}
  35. >
  36. <div
  37. style={{
  38. marginTop: "-1.2em",
  39. right: "0",
  40. position: "absolute",
  41. display: isHover ? "block" : "none",
  42. }}
  43. >
  44. <Button
  45. icon={<EditOutlined />}
  46. size="small"
  47. onClick={() => {
  48. if (typeof onModeChange !== "undefined") {
  49. onModeChange("edit");
  50. }
  51. }}
  52. />
  53. <Button icon={<CopyOutlined />} size="small" />
  54. <Dropdown overlay={menu} placement="bottomRight">
  55. <Button icon={<MoreOutlined />} size="small" />
  56. </Dropdown>
  57. </div>
  58. {children}
  59. </div>
  60. );
  61. };
  62. export default Widget;