ArticleCardMainMenu.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Tabs, Button, Popover } from "antd";
  2. import { MenuOutlined, PushpinOutlined } from "@ant-design/icons";
  3. import PaliTextToc from "./PaliTextToc";
  4. import Find from "./Find";
  5. import Nav from "./Nav";
  6. import { useIntl } from "react-intl";
  7. interface IWidget {
  8. type?: string;
  9. articleId?: string;
  10. }
  11. const ArticleCardMainMenuWidget = ({ articleId }: IWidget) => {
  12. const intl = useIntl();
  13. const id = articleId?.split("_");
  14. let tocWidget = <></>;
  15. if (id && id.length > 0) {
  16. const sentId = id[0].split("-");
  17. if (sentId.length > 1) {
  18. tocWidget = (
  19. <PaliTextToc book={parseInt(sentId[0])} para={parseInt(sentId[1])} />
  20. );
  21. }
  22. }
  23. const styleTabBody: React.CSSProperties = {
  24. width: 350,
  25. height: "calc(100vh - 200px)",
  26. overflowY: "scroll",
  27. };
  28. const mainMenuContent = (
  29. <Tabs
  30. size="small"
  31. defaultActiveKey="1"
  32. tabBarExtraContent={{
  33. right: <Button type="text" size="small" icon={<PushpinOutlined />} />,
  34. }}
  35. items={[
  36. {
  37. label: intl.formatMessage({
  38. id: "labels.table-of-content",
  39. }),
  40. key: "1",
  41. children: <div style={styleTabBody}>{tocWidget}</div>,
  42. },
  43. {
  44. label: `定位`,
  45. key: "2",
  46. children: (
  47. <div style={styleTabBody}>
  48. <Nav />
  49. </div>
  50. ),
  51. },
  52. {
  53. label: `查找`,
  54. key: "3",
  55. children: (
  56. <div style={styleTabBody}>
  57. <Find />
  58. </div>
  59. ),
  60. },
  61. ]}
  62. />
  63. );
  64. return (
  65. <Popover
  66. placement="bottomLeft"
  67. arrow={{ pointAtCenter: true }}
  68. content={mainMenuContent}
  69. trigger="click"
  70. >
  71. <Button size="small" icon={<MenuOutlined />} />
  72. </Popover>
  73. );
  74. };
  75. export default ArticleCardMainMenuWidget;