| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { useEffect, useState } from "react";
- import { Modal, Tabs } from "antd";
- import ArticleTpl from "./ArticleTpl";
- import VideoTpl from "./VideoTpl";
- import type { ArticleType } from "../../article/Article"
- interface IWidget {
- trigger?: React.ReactNode;
- open?: boolean;
- tpl?: ArticleType;
- articleId?: string;
- title?: string;
- onClose?: () => void;
- }
- const TplBuilderWidget = ({
- trigger,
- open = false,
- tpl,
- articleId,
- ___title,
- onClose,
- }: IWidget) => {
- const [isModalOpen, setIsModalOpen] = useState(open);
- useEffect(() => setIsModalOpen(open), [open]);
- useEffect(() => {}, [tpl]);
- const showModal = () => {
- setIsModalOpen(true);
- };
- const handleCancel = () => {
- if (onClose) {
- onClose();
- } else {
- setIsModalOpen(false);
- }
- };
- return (
- <>
- <span onClick={showModal}>{trigger}</span>
- <Modal
- style={{ top: 20 }}
- width={900}
- footer={false}
- title="template builder"
- open={isModalOpen}
- onCancel={handleCancel}
- >
- <Tabs
- tabPosition="left"
- defaultActiveKey="article"
- items={[
- {
- label: "article",
- key: "article",
- children: <ArticleTpl articleId={articleId} type={tpl} />,
- }, // 务必填写 key
- { label: "video", key: "video", children: <VideoTpl /> },
- ]}
- />
- </Modal>
- </>
- );
- };
- export default TplBuilderWidget;
|