Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resolveFalseAndRemove helper function to modal handler #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export interface NiceModalHandler<Props = Record<string, unknown>> extends NiceM
* Resolve the promise returned by {@link NiceModalHandler.hide | hide} method.
*/
resolveHide: (args?: unknown) => void;

/**
* Resolves the promise returned by {@link NiceModalHandler.show | show} method with value `false`,
* then removes the modal using the {@link NiceModalHandler.remove | remove} method.
*/
resolveFalseAndRemove: () => void;
}

// Omit will not work if extends Record<string, unknown>, which is not needed here
Expand Down Expand Up @@ -339,6 +345,11 @@ export function useModal(modal?: any, args?: any): any {
},
[mid],
);
const resolveFalseAndRemove = useCallback(() => {
const modalResolve = modalCallbacks[mid].resolve;
modalResolve(false);
remove(mid);
}, [mid]);

return {
id: mid,
Expand All @@ -351,6 +362,7 @@ export function useModal(modal?: any, args?: any): any {
resolve: resolveCallback,
reject: rejectCallback,
resolveHide,
resolveFalseAndRemove,
};
}
export const create = <P extends {}>(Comp: React.ComponentType<P>): React.FC<P & NiceModalHocProps> => {
Expand Down