Skip to content

Commit

Permalink
feat: 导出上下文中的 useEasyAntdModal hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Aug 1, 2023
1 parent 7873164 commit e614ead
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export const EasyAntdModalContext = React.createContext<EasyAntdModalContextType
contentProps: 'children',
});

export const useEasyAntdModalContext = () => React.useContext(EasyAntdModalContext);
export const useEasyAntdModal = () => React.useContext(EasyAntdModalContext);

export const EasyAntdModalProvider = (props: React.PropsWithChildren<EasyAntdModalContextType>) => {
const {
triggerProps: parentTriggerProps = 'trigger',
contentProps: parentContentProps = 'children',
} = useEasyAntdModalContext();
} = useEasyAntdModal();

const { children, triggerProps = parentTriggerProps, contentProps = parentContentProps } = props;

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useModalEnhanced.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,7 +34,7 @@ function useModalEnhanced(props: UseModalEnhancedProps = {}) {

const [visible, { setTrue: open, setFalse: close }] = useBoolean(defaultOpen);
const actionRef = React.useRef<ModalEnhancedAction>({ open, close });
const { triggerProps, contentProps } = useEasyAntdModalContext();
const { triggerProps, contentProps } = useEasyAntdModal();

const mergedTrigger = props[triggerProps!] as TriggerType;
const mergedContent = props[contentProps!] as ContentType;
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand Down

0 comments on commit e614ead

Please sign in to comment.