AttachmentDialog.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Modal } from "antd";
  2. import { useEffect, useState } from "react";
  3. import AttachmentList from "./AttachmentList";
  4. import type { IAttachmentRequest } from "../../api/Attachments";
  5. interface IWidget {
  6. open?: boolean;
  7. trigger?: React.ReactNode;
  8. studioName?: string;
  9. onOpenChange?: Function;
  10. onSelect?: Function;
  11. }
  12. const AttachmentDialog = ({
  13. open,
  14. trigger,
  15. studioName,
  16. onOpenChange,
  17. onSelect,
  18. }: IWidget) => {
  19. const [isModalOpen, setIsModalOpen] = useState(open);
  20. useEffect(() => setIsModalOpen(open), [open]);
  21. const showModal = () => {
  22. setIsModalOpen(true);
  23. if (typeof onOpenChange !== "undefined") {
  24. onOpenChange(true);
  25. }
  26. };
  27. const handleOk = () => {
  28. setIsModalOpen(false);
  29. if (typeof onOpenChange !== "undefined") {
  30. onOpenChange(false);
  31. }
  32. };
  33. const handleCancel = () => {
  34. setIsModalOpen(false);
  35. if (typeof onOpenChange !== "undefined") {
  36. onOpenChange(false);
  37. }
  38. };
  39. return (
  40. <>
  41. <span onClick={showModal}>{trigger}</span>
  42. <Modal
  43. width={700}
  44. title="加入文集"
  45. open={isModalOpen}
  46. onOk={handleOk}
  47. onCancel={handleCancel}
  48. maskClosable={false}
  49. >
  50. <AttachmentList
  51. studioName={studioName}
  52. onClick={(value: IAttachmentRequest) => {
  53. if (typeof onSelect !== "undefined") {
  54. onSelect(value);
  55. }
  56. handleOk();
  57. }}
  58. />
  59. </Modal>
  60. </>
  61. );
  62. };
  63. export default AttachmentDialog;