-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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): support use directive to define the footer (#3036)
* feat(module:modal): support use directive to define the footer close #3035 * docs(module:modal): add custom footer demo * test(module:modal): add test * test(module:modal): add test * fix(module:modal): fix type * test(module:modal): fix test * chore: rebase master * chore: rebase master * test(module:modal): fix test * test(module:modal): fix test
- Loading branch information
Showing
16 changed files
with
267 additions
and
9 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,5 +1,5 @@ | ||
--- | ||
order: 3 | ||
order: 4 | ||
title: | ||
zh-CN: 确认对话框 | ||
en-US: Confirmation modal dialog | ||
|
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,14 @@ | ||
--- | ||
order: 3 | ||
title: | ||
zh-CN: 自定义页脚(2) | ||
en-US: Customized Footer(2) | ||
--- | ||
|
||
## zh-CN | ||
|
||
使用 `nzModalFooter` 指令自定义了页脚的按钮。 | ||
|
||
## en-US | ||
|
||
use `nzModalFooter` directive to customized footer button bar. |
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,87 @@ | ||
/* entryComponents: NzModalCustomFooterComponent */ | ||
|
||
import { Component } from '@angular/core'; | ||
import { NzModalService, NzModalRef } from 'ng-zorro-antd'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-modal-footer2', | ||
template: ` | ||
<button nz-button nzType="primary" (click)="showModal1()"> | ||
<span>In Template</span> | ||
</button> | ||
<br> | ||
<br> | ||
<button nz-button nzType="primary" (click)="showModal2()"> | ||
<span>In Component</span> | ||
</button> | ||
<nz-modal [(nzVisible)]="isVisible" nzTitle="Custom Modal Title" (nzOnCancel)="handleCancel()"> | ||
<div> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
</div> | ||
<div *nzModalFooter> | ||
<span>Modal Footer: </span> | ||
<button nz-button nzType="default" (click)="handleCancel()">Custom Callback</button> | ||
<button nz-button nzType="primary" (click)="handleOk()" [nzLoading]="isConfirmLoading">Custom Submit</button> | ||
</div> | ||
</nz-modal> | ||
`, | ||
styles: [] | ||
}) | ||
export class NzDemoModalFooter2Component { | ||
isVisible = false; | ||
isConfirmLoading = false; | ||
|
||
constructor(private modalService: NzModalService) { } | ||
|
||
showModal1(): void { | ||
this.isVisible = true; | ||
} | ||
|
||
showModal2(): void { | ||
this.modalService.create({ | ||
nzTitle: 'Modal Title', | ||
nzContent: NzModalCustomFooterComponent | ||
}); | ||
} | ||
|
||
handleOk(): void { | ||
this.isConfirmLoading = true; | ||
setTimeout(() => { | ||
this.isVisible = false; | ||
this.isConfirmLoading = false; | ||
}, 3000); | ||
} | ||
|
||
handleCancel(): void { | ||
this.isVisible = false; | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'nz-modal-custom-footer-component', | ||
template: ` | ||
<div> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
<p>Modal Content</p> | ||
</div> | ||
<div *nzModalFooter> | ||
<button nz-button nzType="default" (click)="destroyModal()">Custom Callback</button> | ||
<button nz-button nzType="primary" (click)="destroyModal()">Custom Submit</button> | ||
</div> | ||
` | ||
}) | ||
export class NzModalCustomFooterComponent { | ||
|
||
constructor(private modal: NzModalRef) { } | ||
|
||
destroyModal(): void { | ||
this.modal.destroy(); | ||
} | ||
} |
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,5 +1,5 @@ | ||
--- | ||
order: 5 | ||
order: 6 | ||
title: | ||
zh-CN: 信息提示 | ||
en-US: Information modal dialog | ||
|
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,5 +1,5 @@ | ||
--- | ||
order: 6 | ||
order: 7 | ||
title: | ||
zh-CN: 国际化 | ||
en-US: Internationalization | ||
|
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,5 +1,5 @@ | ||
--- | ||
order: 7 | ||
order: 8 | ||
title: | ||
zh-CN: 手动移除 | ||
en-US: Manual to destroy | ||
|
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,5 +1,5 @@ | ||
--- | ||
order: 8 | ||
order: 9 | ||
title: | ||
zh-CN: 自定义位置 | ||
en-US: To customize the position of modal | ||
|
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,5 +1,5 @@ | ||
--- | ||
order: 9 | ||
order: 10 | ||
title: | ||
zh-CN: 服务方式创建 | ||
en-US: Modal's service | ||
|
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,84 @@ | ||
import { OverlayContainer } from '@angular/cdk/overlay'; | ||
import { Component } from '@angular/core'; | ||
import { async, fakeAsync, inject, tick, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
import { NzModalModule } from './nz-modal.module'; | ||
import { NzModalService } from './nz-modal.service'; | ||
|
||
describe('modal footer directive', () => { | ||
let overlayContainer: OverlayContainer; | ||
let overlayContainerElement: HTMLElement; | ||
let fixture: ComponentFixture<TestDirectiveFooterComponent>; | ||
let testComponent: TestDirectiveFooterComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [NzModalModule, NoopAnimationsModule], | ||
declarations: [TestDirectiveFooterComponent], | ||
providers: [NzModalService] | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestDirectiveFooterComponent); | ||
testComponent = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
beforeEach(inject([OverlayContainer], (oc: OverlayContainer) => { | ||
overlayContainer = oc; | ||
overlayContainerElement = oc.getContainerElement(); | ||
})); | ||
|
||
afterEach(() => { | ||
overlayContainer.ngOnDestroy(); | ||
}); | ||
|
||
afterEach(fakeAsync(() => { | ||
fixture.detectChanges(); | ||
tick(1000); | ||
})); | ||
|
||
it('should work with template', () => { | ||
testComponent.showModal(); | ||
fixture.detectChanges(); | ||
expect(testComponent.isVisible).toBe(true); | ||
const cancelBtn: HTMLButtonElement = overlayContainerElement.querySelector( | ||
'.ant-modal #btn-template' | ||
) as HTMLButtonElement; | ||
expect(cancelBtn).toBeTruthy(); | ||
cancelBtn.click(); | ||
fixture.detectChanges(); | ||
expect(testComponent.isVisible).toBe(false); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<nz-modal [(nzVisible)]="isVisible" nzTitle="Custom Modal Title" (nzOnCancel)="handleCancel()"> | ||
<div> | ||
<p>Modal Content</p> | ||
</div> | ||
<div *nzModalFooter> | ||
<button id="btn-template" nz-button nzType="default" (click)="handleCancel()">Custom Callback</button> | ||
</div> | ||
</nz-modal> | ||
` | ||
}) | ||
class TestDirectiveFooterComponent { | ||
isVisible = false; | ||
|
||
constructor() {} | ||
|
||
handleCancel(): void { | ||
this.isVisible = false; | ||
} | ||
|
||
showModal(): void { | ||
this.isVisible = true; | ||
} | ||
} |
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,21 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { Directive, Optional, TemplateRef } from '@angular/core'; | ||
import { NzModalRef } from './nz-modal-ref.class'; | ||
|
||
@Directive({ | ||
selector: '[nzModalFooter]' | ||
}) | ||
export class NzModalFooterDirective { | ||
constructor(@Optional() private nzModalRef: NzModalRef, public templateRef: TemplateRef<{}>) { | ||
if (this.nzModalRef) { | ||
this.nzModalRef.getInstance().setFooterWithTemplate(this.templateRef); | ||
} | ||
} | ||
} |
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