You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
980 B

11 months ago
  1. import { Modal, ModalFuncProps } from 'antd'
  2. import React from 'react'
  3. import { HookAPI } from 'antd/es/modal/useModal'
  4. import { useDialog } from '@/components/dialog'
  5. export interface AlterProps extends ModalFuncProps {
  6. onLoad?: () => void
  7. alterType: keyof HookAPI | 'dialog'
  8. children: JSX.Element | React.ReactNode
  9. }
  10. const ModalPro = ({ onLoad, alterType, children, ...props }: AlterProps) => {
  11. const [ modal, modalHolder ] = Modal.useModal()
  12. const [ dialogRef, dialog, ] = useDialog(props)
  13. return (
  14. <>
  15. <span onClick={() => {
  16. if (onLoad) {
  17. onLoad()
  18. }
  19. if (alterType === 'dialog') {
  20. dialogRef.current?.show()
  21. } else {
  22. modal[alterType]?.(props)
  23. }
  24. }}>{children}</span>
  25. {alterType !== 'dialog' && modalHolder}
  26. {alterType === 'dialog' && dialog}
  27. </>
  28. )
  29. }
  30. export default ModalPro