Builder.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { useEffect, useState } from "react";
  2. import { Modal, Tabs } from "antd";
  3. import ArticleTpl from "./ArticleTpl";
  4. import VideoTpl from "./VideoTpl";
  5. import type { ArticleType } from "../../article/Article"
  6. interface IWidget {
  7. trigger?: React.ReactNode;
  8. open?: boolean;
  9. tpl?: ArticleType;
  10. articleId?: string;
  11. title?: string;
  12. onClose?: () => void;
  13. }
  14. const TplBuilderWidget = ({
  15. trigger,
  16. open = false,
  17. tpl,
  18. articleId,
  19. ___title,
  20. onClose,
  21. }: IWidget) => {
  22. const [isModalOpen, setIsModalOpen] = useState(open);
  23. useEffect(() => setIsModalOpen(open), [open]);
  24. useEffect(() => {}, [tpl]);
  25. const showModal = () => {
  26. setIsModalOpen(true);
  27. };
  28. const handleCancel = () => {
  29. if (onClose) {
  30. onClose();
  31. } else {
  32. setIsModalOpen(false);
  33. }
  34. };
  35. return (
  36. <>
  37. <span onClick={showModal}>{trigger}</span>
  38. <Modal
  39. style={{ top: 20 }}
  40. width={900}
  41. footer={false}
  42. title="template builder"
  43. open={isModalOpen}
  44. onCancel={handleCancel}
  45. >
  46. <Tabs
  47. tabPosition="left"
  48. defaultActiveKey="article"
  49. items={[
  50. {
  51. label: "article",
  52. key: "article",
  53. children: <ArticleTpl articleId={articleId} type={tpl} />,
  54. }, // 务必填写 key
  55. { label: "video", key: "video", children: <VideoTpl /> },
  56. ]}
  57. />
  58. </Modal>
  59. </>
  60. );
  61. };
  62. export default TplBuilderWidget;