-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79b3c4f
commit b97ab23
Showing
2 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import Modal from './Modal'; | ||
import attachPropertiesToComponent from '../utils/attachPropertiesToComponent'; | ||
import alert from './Alert'; | ||
import confirm from './Confirm'; | ||
import attachPropertiesToComponent from '../utils/attachPropertiesToComponent'; | ||
import Modal from './Modal'; | ||
import { show, clear } from './methods'; | ||
|
||
export type { ModalProps, ModalCssVars } from './Modal'; | ||
export type { ModalCssVars, ModalProps } from './Modal'; | ||
|
||
export default attachPropertiesToComponent(Modal, { | ||
show, | ||
clear, | ||
alert, | ||
confirm, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
import { ImperativeHandler, renderImperatively } from '../utils/dom'; | ||
import Modal, { ModalProps } from './Modal'; | ||
|
||
export type ModalShowProps = Omit<ModalProps, 'visible' | 'destroy' | 'forceRender'>; | ||
|
||
export type ModalShowHandler = Pick<ImperativeHandler, 'close'>; | ||
|
||
const closeFn = new Set<() => void>(); | ||
|
||
export const show = (props: ModalShowProps) => { | ||
const handler: ModalShowHandler = renderImperatively( | ||
<Modal | ||
{...props} | ||
afterClose={() => { | ||
closeFn.delete(handler.close); | ||
props.afterClose?.(); | ||
}} | ||
/>, | ||
); | ||
closeFn.add(handler.close); | ||
return handler; | ||
}; | ||
|
||
export const clear = () => { | ||
closeFn.forEach((close) => close()); | ||
}; |