-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:modal): add afterOpen/afterAllClose/closeAll/openModals, …
…adjust the boolean props. TODO: adjust changeBodyOverflow and testing.
- Loading branch information
1 parent
7a801d2
commit 501054d
Showing
10 changed files
with
235 additions
and
64 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
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
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
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
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
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,48 @@ | ||
import { Subject } from 'rxjs/Subject'; | ||
|
||
import { NzModalRef } from './nz-modal-ref.class'; | ||
|
||
export class ModalManager { | ||
afterAllClose: Subject<void> = new Subject<void>(); | ||
|
||
private openModals: NzModalRef[] = []; | ||
|
||
// Register a modal to listen its open/close | ||
registerModal(modalRef: NzModalRef): void { | ||
if (!this.hasOpenModal(modalRef)) { | ||
modalRef.afterOpen.subscribe(() => this.openModals.push(modalRef)); | ||
modalRef.afterClose.subscribe(() => this.removeOpenModal(modalRef)); | ||
} | ||
} | ||
|
||
getOpenModals(): NzModalRef[] { | ||
return this.openModals; | ||
} | ||
|
||
hasOpenModal(modalRef: NzModalRef): boolean { | ||
return this.openModals.indexOf(modalRef) > -1; | ||
} | ||
|
||
// Close all registered opened modals | ||
closeAll(): void { | ||
let i = this.openModals.length; | ||
|
||
while (i--) { | ||
this.openModals[i].close(); | ||
} | ||
} | ||
|
||
private removeOpenModal(modalRef: NzModalRef): void { | ||
const index = this.openModals.indexOf(modalRef); | ||
|
||
if (index > -1) { | ||
this.openModals.splice(index, 1); | ||
|
||
if (!this.openModals.length) { | ||
this.afterAllClose.next(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default new ModalManager(); |
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
Oops, something went wrong.