This commit is contained in:
CHEVALLIER Abel
2025-11-13 16:23:22 +01:00
parent de9c515a47
commit cb235644dc
34924 changed files with 3811102 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<button nz-button nzType="primary" (click)="createModal()">
<span>String</span>
</button>
<button nz-button nzType="primary" (click)="createTplModal(tplTitle, tplContent, tplFooter)">
<span>Template</span>
</button>
<ng-template #tplTitle>
<span>Title Template</span>
</ng-template>
<ng-template #tplContent let-params>
<p>some contents...</p>
<p>some contents...</p>
<p>{{ params?.value }}</p>
</ng-template>
<ng-template #tplFooter let-ref="modalRef">
<button nz-button (click)="ref.destroy()">Destroy</button>
<button nz-button nzType="primary" (click)="destroyTplModal(ref)" [nzLoading]="tplModalButtonLoading">
Close after submit
</button>
</ng-template>
<br />
<br />
<button nz-button nzType="primary" (click)="createComponentModal()">
<span>Use Component</span>
</button>
<button nz-button nzType="primary" (click)="createCustomButtonModal()">Custom Button</button>
<br />
<br />
<button nz-button nzType="primary" (click)="openAndCloseAll()">Open more modals then close all after 2s</button>

View File

@@ -0,0 +1,23 @@
import { fakeAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { <%= classify(name) %>Component } from './<%= dasherize(name) %>.component';
describe('<%= classify(name) %>Component', () => {
let component: <%= classify(name) %>Component;
let fixture: ComponentFixture<<%= classify(name) %>Component>;
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [ <%= classify(name) %>Component ]
})
.compileComponents();
;
fixture = TestBed.createComponent(<%= classify(name) %>Component);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should compile', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,210 @@
import { Component, inject, Input, TemplateRef, ViewContainerRef } from '@angular/core';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzModalRef, NzModalService, NZ_MODAL_DATA, NzModalModule } from 'ng-zorro-antd/modal';
interface IModalData {
favoriteLibrary: string;
favoriteFramework: string;
}
@Component({
selector: '<%= selector %>',
imports: [NzButtonModule, NzModalModule],
<% if(inlineTemplate) { %>template: `
<button nz-button nzType="primary" (click)="createModal()">
<span>String</span>
</button>
<button nz-button nzType="primary" (click)="createTplModal(tplTitle, tplContent, tplFooter)">
<span>Template</span>
</button>
<ng-template #tplTitle>
<span>Title Template</span>
</ng-template>
<ng-template #tplContent let-params>
<p>some contents...</p>
<p>some contents...</p>
<p>{{ params?.value }}</p>
</ng-template>
<ng-template #tplFooter let-ref="modalRef">
<button nz-button (click)="ref.destroy()">Destroy</button>
<button nz-button nzType="primary" (click)="destroyTplModal(ref)" [nzLoading]="tplModalButtonLoading">
Close after submit
</button>
</ng-template>
<br />
<br />
<button nz-button nzType="primary" (click)="createComponentModal()">
<span>Use Component</span>
</button>
<button nz-button nzType="primary" (click)="createCustomButtonModal()">Custom Button</button>
<br />
<br />
<button nz-button nzType="primary" (click)="openAndCloseAll()">Open more modals then close all after 2s</button>
`<% } else { %>templateUrl: './<%= dasherize(name) %>.component.html'<% } %>,
<% if(inlineStyle) { %>styles: [`
button {
margin-right: 8px;
}
`]<% } else { %>styleUrls: ['./<%= dasherize(name) %>.component.<%= style %>']<% } %>
})
export class <%= classify(name) %>Component {
tplModalButtonLoading = false;
disabled = false;
constructor(
private modal: NzModalService,
private viewContainerRef: ViewContainerRef
) {}
createModal(): void {
this.modal.create({
nzTitle: 'Modal Title',
nzContent: 'string, will close after 1 sec',
nzClosable: false,
nzOnOk: () => new Promise(resolve => setTimeout(resolve, 1000))
});
}
createTplModal(tplTitle: TemplateRef<{}>, tplContent: TemplateRef<{}>, tplFooter: TemplateRef<{}>): void {
this.modal.create({
nzTitle: tplTitle,
nzContent: tplContent,
nzFooter: tplFooter,
nzMaskClosable: false,
nzClosable: false,
nzOnOk: () => console.log('Click ok')
});
}
destroyTplModal(modelRef: NzModalRef): void {
this.tplModalButtonLoading = true;
setTimeout(() => {
this.tplModalButtonLoading = false;
modelRef.destroy();
}, 1000);
}
createComponentModal(): void {
const modal = this.modal.create<NzModalCustomComponent, IModalData>({
nzTitle: 'Modal Title',
nzContent: NzModalCustomComponent,
nzViewContainerRef: this.viewContainerRef,
nzData: {
favoriteLibrary: 'angular',
favoriteFramework: 'angular'
},
nzOnOk: () => new Promise(resolve => setTimeout(resolve, 1000)),
nzFooter: [
{
label: 'change component title from outside',
onClick: componentInstance => {
componentInstance!.title = 'title in inner component is changed';
}
}
]
});
const instance = modal.getContentComponent();
modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!'));
// Return a result when closed
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result));
// delay until modal instance created
setTimeout(() => {
instance.subtitle = 'sub title is changed';
}, 2000);
}
createCustomButtonModal(): void {
const modal: NzModalRef = this.modal.create({
nzTitle: 'custom button demo',
nzContent: 'pass array of button config to nzFooter to create multiple buttons',
nzFooter: [
{
label: 'Close',
shape: 'round',
onClick: () => modal.destroy()
},
{
label: 'Confirm',
type: 'primary',
onClick: () => this.modal.confirm({ nzTitle: 'Confirm Modal Title', nzContent: 'Confirm Modal Content' })
},
{
label: 'Change Button Status',
type: 'primary',
danger: true,
loading: false,
onClick(): void {
this.loading = true;
setTimeout(() => (this.loading = false), 1000);
setTimeout(() => {
this.loading = false;
this.disabled = true;
this.label = 'can not be clicked';
}, 2000);
}
},
{
label: 'async load',
type: 'dashed',
onClick: () => new Promise(resolve => setTimeout(resolve, 2000))
}
]
});
}
openAndCloseAll(): void {
let pos = 0;
['create', 'info', 'success', 'error'].forEach(method =>
// @ts-ignore
this.modal[method]({
nzMask: false,
nzTitle: `Test ${method} title`,
nzContent: `Test content: <b>${method}</b>`,
nzStyle: { position: 'absolute', top: `${pos * 70}px`, left: `${pos++ * 300}px` }
})
);
this.modal.afterAllClose.subscribe(() => console.log('afterAllClose emitted!'));
setTimeout(() => this.modal.closeAll(), 2000);
}
}
@Component({
selector: 'nz-modal-custom-component',
imports: [NzButtonModule],
template: `
<div>
<h2>{{ title }}</h2>
<h4>{{ subtitle }}</h4>
<p
>My favorite framework is {{ nzModalData.favoriteFramework }} and my favorite library is
{{ nzModalData.favoriteLibrary }}
</p>
<p>
<span>Get Modal instance in component</span>
<button nz-button [nzType]="'primary'" (click)="destroyModal()">destroy modal in the component</button>
</p>
</div>
`
})
export class NzModalCustomComponent {
@Input() title?: string;
@Input() subtitle?: string;
readonly #modal = inject(NzModalRef);
readonly nzModalData: IModalData = inject(NZ_MODAL_DATA);
destroyModal(): void {
this.#modal.destroy({ data: 'this the result data' });
}
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const build_component_1 = require("../../utils/build-component");
function default_1(options) {
return (0, schematics_1.chain)([
(0, build_component_1.buildComponent)(Object.assign({}, options), {
template: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template',
stylesheet: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__.template'
})
]);
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../schematics/demo/modal-service/index.ts"],"names":[],"mappings":";;AAQA,4BAUC;AAlBD,2DAGoC;AACpC,iEAA6D;AAI7D,mBAAwB,OAAe;IACrC,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,gCAAc,oBACP,OAAO,GACZ;YACE,QAAQ,EAAE,kFAAkF;YAC5F,UAAU,EAAE,uFAAuF;SACpG,CACF;KACF,CAAC,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=schema.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../schematics/demo/modal-service/schema.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1 @@
{"$schema":"http://json-schema.org/schema","$id":"service-modal","title":"NG-ZORRO service modal","type":"object","properties":{"path":{"type":"string","format":"path","description":"The path to create the component.","visible":false},"project":{"type":"string","description":"The name of the project.","$default":{"$source":"projectName"}},"name":{"type":"string","description":"The name of the component.","$default":{"$source":"argv","index":0},"x-prompt":"What should be the name of the component?"},"inlineStyle":{"description":"When true, includes styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file.","type":"boolean","default":false,"alias":"s"},"inlineTemplate":{"description":"When true, includes template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file.","type":"boolean","default":false,"alias":"t"},"standalone":{"description":"Whether the generated component is standalone.","type":"boolean"},"prefix":{"type":"string","description":"The prefix to apply to the generated component selector.","alias":"p","oneOf":[{"maxLength":0},{"minLength":1,"format":"html-selector"}]},"styleext":{"description":"The file extension to use for style files.","type":"string","default":"css","x-deprecated":"Use \"style\" instead."},"style":{"description":"The file extension or preprocessor to use for style files.","type":"string","default":"css","enum":["css","scss","sass","less","styl"]},"spec":{"type":"boolean","description":"When true (the default), generates a \"spec.ts\" test file for the new component.","default":true,"x-deprecated":"Use \"skipTests\" instead."},"skipTests":{"type":"boolean","description":"When true, does not create \"spec.ts\" test files for the new component."},"flat":{"type":"boolean","description":"Flag to indicate if a dir is created.","default":false},"skipImport":{"type":"boolean","description":"When true, does not import this component into the owning NgModule."},"selector":{"type":"string","format":"html-selector","description":"The selector to use for the component."},"module":{"type":"string","description":"Allows specification of the declaring module.","alias":"m"},"export":{"type":"boolean","default":false,"description":"When true, the declaring NgModule exports this component."},"entryComponent":{"type":"boolean","default":false,"description":"When true, the new component is the entry component of the declaring NgModule."},"classnameWithModule":{"type":"boolean","description":"When true, Use module class name as additional prefix for the component classname.","default":false}},"required":["name"]}