@orca-fe/hooks
Version:
React Hooks Collections
98 lines (97 loc) • 3.72 kB
TypeScript
import React from 'react';
export declare const PromisifyModalContext: React.Context<{
ok: (...args: any[]) => void;
cancel: () => void;
destroy: () => void;
minimize: () => void;
resume: () => void;
resolve: (...args: any[]) => void;
update: (...args: any[]) => void;
}>;
export type UsePromisifyModalOptions = {
/** 标记用于控制显隐的属性名称,默认为 open */
openField?: string;
/** 弹框的确认回调事件,触发该事件时,相当于 Promise.resolve(); */
onOkField?: string;
/** 弹框的关闭回调事件,触发该事件时,相当于 Promise 挂起,不再触发 resolve 流程 */
onCloseField?: string;
/** 关闭弹窗后卸载弹框示例的延迟(一般用于维持弹框消失时的动画) */
destroyDelay?: number;
/** 关闭弹框时,是否触发 Promise.reject()。默认情况下不触发,Promise 将永远保持 pending */
rejectOnClose?: boolean;
/** 当触发 onOk 时,但处于异步逻辑的过程中,对弹框组件注入一个 loading 属性,用于控制弹框确认按钮的 loading 效果 */
confirmLoadingPropName?: string;
};
/**
* 帮助你管理维护弹框的 open 状态,适用于 antd-modal 及基于 modal 封装的自定义弹框
* 通过 show 方法,直接弹出 modal 即可。工具会自动接管 onOk 和 onCancel 事件,并更新 open
* @param options
*/
export default function usePromisifyModal(options?: UsePromisifyModalOptions): {
show: <T>(element?: React.ReactElement) => Promise<T> & {
hide: () => void;
destroy: () => void;
ok: (value: T) => void;
cancel: () => void;
resolve: (value: T) => void;
};
open: <T>(element?: React.ReactElement) => Promise<T> & {
hide: () => void;
destroy: () => void;
ok: (value: T) => void;
cancel: () => void;
resolve: (value: T) => void;
};
hide: () => void;
destroy: () => void;
instance: React.FunctionComponentElement<React.ProviderProps<{
ok: (...args: any[]) => void;
cancel: () => void;
destroy: () => void;
minimize: () => void;
resume: () => void;
resolve: (...args: any[]) => void;
update: (...args: any[]) => void;
}>>;
resume: () => void;
minimize: () => void;
ok: (this: unknown, ...args: any[]) => void;
cancel: (this: unknown, ...args: any[]) => void;
resolve: (this: unknown, ...args: any[]) => void;
update: (props: any) => void;
isOpen: boolean;
};
export declare const usePromisifyDrawer: (options?: UsePromisifyModalOptions) => {
show: <T>(element?: React.ReactElement) => Promise<T> & {
hide: () => void;
destroy: () => void;
ok: (value: T) => void;
cancel: () => void;
resolve: (value: T) => void;
};
open: <T>(element?: React.ReactElement) => Promise<T> & {
hide: () => void;
destroy: () => void;
ok: (value: T) => void;
cancel: () => void;
resolve: (value: T) => void;
};
hide: () => void;
destroy: () => void;
instance: React.FunctionComponentElement<React.ProviderProps<{
ok: (...args: any[]) => void;
cancel: () => void;
destroy: () => void;
minimize: () => void;
resume: () => void;
resolve: (...args: any[]) => void;
update: (...args: any[]) => void;
}>>;
resume: () => void;
minimize: () => void;
ok: (this: unknown, ...args: any[]) => void;
cancel: (this: unknown, ...args: any[]) => void;
resolve: (this: unknown, ...args: any[]) => void;
update: (props: any) => void;
isOpen: boolean;
};