From e614ead7b310c0fecf547fea9266fbc71d19c032 Mon Sep 17 00:00:00 2001 From: wuxh Date: Tue, 1 Aug 2023 11:11:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AF=BC=E5=87=BA=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E4=B8=AD=E7=9A=84=20useEasyAntdModal=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/context/index.tsx | 4 ++-- src/hooks/useModalEnhanced.ts | 4 ++-- src/index.ts | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/context/index.tsx b/src/context/index.tsx index 0ffc2d2..ca44cc0 100644 --- a/src/context/index.tsx +++ b/src/context/index.tsx @@ -18,13 +18,13 @@ export const EasyAntdModalContext = React.createContext React.useContext(EasyAntdModalContext); +export const useEasyAntdModal = () => React.useContext(EasyAntdModalContext); export const EasyAntdModalProvider = (props: React.PropsWithChildren) => { const { triggerProps: parentTriggerProps = 'trigger', contentProps: parentContentProps = 'children', - } = useEasyAntdModalContext(); + } = useEasyAntdModal(); const { children, triggerProps = parentTriggerProps, contentProps = parentContentProps } = props; diff --git a/src/hooks/useModalEnhanced.ts b/src/hooks/useModalEnhanced.ts index 6227e06..d383ce8 100644 --- a/src/hooks/useModalEnhanced.ts +++ b/src/hooks/useModalEnhanced.ts @@ -1,5 +1,5 @@ import React from 'react'; -import { useEasyAntdModalContext } from '../context'; +import { useEasyAntdModal } from '../context'; import type { AnyFunction, AnyObj } from '../types'; import { isDOMTypeElement, isElement, omit } from '../util'; import useBoolean from './useBoolean'; @@ -34,7 +34,7 @@ function useModalEnhanced(props: UseModalEnhancedProps = {}) { const [visible, { setTrue: open, setFalse: close }] = useBoolean(defaultOpen); const actionRef = React.useRef({ open, close }); - const { triggerProps, contentProps } = useEasyAntdModalContext(); + const { triggerProps, contentProps } = useEasyAntdModal(); const mergedTrigger = props[triggerProps!] as TriggerType; const mergedContent = props[contentProps!] as ContentType; diff --git a/src/index.ts b/src/index.ts index 576b0f6..14456fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { EasyAntdModalProvider } from './context'; // 只导出 Provider!!! +import { EasyAntdModalProvider, useEasyAntdModal } from './context'; import DragModal from './drag-modal'; import Drawer from './drawer'; import Modal from './modal'; @@ -10,7 +10,14 @@ export * from './util'; export * from './drag-modal'; export * from './modal'; -export { DragModal, Drawer, EasyAntdModalProvider, Modal }; +export { + DragModal, + Drawer, + EasyAntdModalProvider, + Modal, + // ====== Hooks ====== + useEasyAntdModal, +}; export default Modal;