Skip to content

Commit

Permalink
fix: fix type of some API (#3166)
Browse files Browse the repository at this point in the history
* fix: fix type of some API

* fix: table

* fix: fix nullale API

* feat(module:table): use generic typing

* fix: fix generic type
  • Loading branch information
Wendell authored and vthinkxie committed Mar 27, 2019
1 parent 92097b2 commit c685836
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
81 changes: 47 additions & 34 deletions components/icon/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { manifest } from '@ant-design/icons-angular';
import { AccountBookFill } from '@ant-design/icons-angular/icons';
import { NzIconService } from 'ng-zorro-antd';

const categories: { [ key: string ]: string[] } = {
const categories: { [key: string]: string[] } = {
direction: [
'step-backward',
'step-forward',
Expand Down Expand Up @@ -374,33 +374,42 @@ const newIconNames: string[] = [
];

@Component({
selector : 'nz-page-demo-icon',
template : `
<h3>{{localeObj.chooseTheme}}</h3>
selector: 'nz-page-demo-icon',
template: `
<h3>{{ localeObj.chooseTheme }}</h3>
<nz-radio-group [ngModel]="currentTheme" (ngModelChange)="setIconsShouldBeDisplayed($event)">
<label nz-radio-button nzValue="outline">
<i nz-icon>
<svg>
<path d="M864 64H160C107 64 64 107 64 160v704c0 53 43 96 96 96h704c53 0 96-43 96-96V160c0-53-43-96-96-96z m-12 800H172c-6.6 0-12-5.4-12-12V172c0-6.6 5.4-12 12-12h680c6.6 0 12 5.4 12 12v680c0 6.6-5.4 12-12 12z"></path>
<path
d="M864 64H160C107 64 64 107 64 160v704c0 53 43 96 96 96h704c53 0 96-43 96-96V160c0-53-43-96-96-96z m-12 800H172c-6.6 0-12-5.4-12-12V172c0-6.6 5.4-12 12-12h680c6.6 0 12 5.4 12 12v680c0 6.6-5.4 12-12 12z"
></path>
</svg>
</i> Outlined
</i>
Outlined
</label>
<label nz-radio-button nzValue="fill">
<i nz-icon>
<svg>
<path d="M864 64H160C107 64 64 107 64 160v704c0 53 43 96 96 96h704c53 0 96-43 96-96V160c0-53-43-96-96-96z"></path>
<path
d="M864 64H160C107 64 64 107 64 160v704c0 53 43 96 96 96h704c53 0 96-43 96-96V160c0-53-43-96-96-96z"
></path>
</svg>
</i> Filled
</i>
Filled
</label>
<label nz-radio-button nzValue="twotone">
<i nz-icon>
<svg>
<path d="M16 512c0 273.932 222.066 496 496 496s496-222.068 496-496S785.932 16 512 16 16 238.066 16 512z m496 368V144c203.41 0 368 164.622 368 368 0 203.41-164.622 368-368 368z"></path>
<path
d="M16 512c0 273.932 222.066 496 496 496s496-222.068 496-496S785.932 16 512 16 16 238.066 16 512z m496 368V144c203.41 0 368 164.622 368 368 0 203.41-164.622 368-368 368z"
></path>
</svg>
</i> Two Tone
</i>
Two Tone
</label>
</nz-radio-group>
<ng-container *ngFor="let category of categoryNames; let i = index;">
<ng-container *ngFor="let category of categoryNames; let i = index">
<h3>{{ localeObj[category] }}</h3>
<ul class="anticons-list">
<li *ngFor="let icon of displayedNames[i].icons; trackBy: trackByFn" (click)="onIconClick($event, icon)">
Expand All @@ -417,33 +426,37 @@ const newIconNames: string[] = [
</ul>
</ng-container>
`,
styles : [
`h3 {
margin: 1.6em 0 0.6em;
font-size: 18px;
}`,
`ul.anticons-list li .anticon {
font-size: 24px;
}`
styles: [
`
h3 {
margin: 1.6em 0 0.6em;
font-size: 18px;
}
`,
`
ul.anticons-list li .anticon {
font-size: 24px;
}
`
]
})
export class NzPageDemoIconComponent implements OnInit {
displayedNames: Array<{ name: string, icons: string[] }> = [];
displayedNames: Array<{ name: string; icons: string[] }> = [];
categoryNames: string[] = [];
currentTheme = 'outline';
localeObj: { [ key: string ]: string } = locale;
localeObj: { [key: string]: string } = locale;

trackByFn = (_index: number, item: string) => {
return `${item}-${this.currentTheme}`;
}
};

isNewIcon = (name: string) => {
return newIconNames.indexOf(name) > -1;
}
};

onIconClick(e: MouseEvent, icon: string): void {
const target = e.target as HTMLElement;
const copiedString = `<i nz-icon type="${icon}" theme="${this.currentTheme}"></i>`;
const copiedString = `<i nz-icon nzType="${icon}" nzTheme="${this.currentTheme}"></i>`;
target.classList.add('copied');
this._copy(copiedString).then(() => {
setTimeout(() => {
Expand All @@ -453,8 +466,9 @@ export class NzPageDemoIconComponent implements OnInit {
}

private _copy(value: string): Promise<string> {
const promise = new Promise<string>((resolve): void => {
let copyTextArea = null as any as HTMLTextAreaElement; // tslint:disable-line:no-any
const promise = new Promise<string>(
(resolve): void => {
let copyTextArea = (null as any) as HTMLTextAreaElement; // tslint:disable-line:no-any
try {
copyTextArea = this.dom.createElement('textarea');
copyTextArea.style.height = '0px';
Expand All @@ -473,19 +487,18 @@ export class NzPageDemoIconComponent implements OnInit {
}
);

return (promise);

return promise;
}

setIconsShouldBeDisplayed(value: string): void {
// tslint:disable
const names = Object.keys(categories)
.map(category => ({
name : category,
// @ts-ignore
icons: categories[ category ].filter(name => manifest[ value ].indexOf(name) > -1)
}))
.filter(({ icons }) => Boolean(icons.length));
.map(category => ({
name: category,
// @ts-ignore
icons: categories[category].filter(name => manifest[value].indexOf(name) > -1)
}))
.filter(({ icons }) => Boolean(icons.length));

this.displayedNames = names;
this.categoryNames = names.map(({ name }) => name);
Expand Down
4 changes: 2 additions & 2 deletions components/modal/nz-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R>
@Input() @InputBoolean() nzNoAnimation = false;
@Input() nzContent: string | TemplateRef<{}> | Type<T>; // [STATIC] If not specified, will use <ng-content>
@Input() nzComponentParams: T; // [STATIC] ONLY avaliable when nzContent is a component
@Input() nzFooter: string | TemplateRef<{}> | Array<ModalButtonOptions<T>>; // [STATIC] Default Modal ONLY
@Input() nzFooter: string | TemplateRef<{}> | Array<ModalButtonOptions<T>> | null; // [STATIC] Default Modal ONLY
@Input() nzGetContainer: HTMLElement | OverlayRef | (() => HTMLElement | OverlayRef) = () => this.overlay.create(); // [STATIC]
@Input() nzZIndex: number = 1000;
@Input() nzWidth: number | string = 520;
Expand Down Expand Up @@ -308,7 +308,7 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R>
return value instanceof Type;
}

public isModalButtons(value: {}): boolean {
public isModalButtons(value: string | TemplateRef<{}> | Array<ModalButtonOptions<T>> | null): boolean {
return Array.isArray(value) && value.length > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion components/modal/nz-modal.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ModalOptions<T = any, R = any> {
nzMaskClosable?: boolean;
nzMaskStyle?: object;
nzBodyStyle?: object;
nzFooter?: string | TemplateRef<{}> | Array<ModalButtonOptions<T>>; // Default Modal ONLY
nzFooter?: string | TemplateRef<{}> | Array<ModalButtonOptions<T>> | null; // Default Modal ONLY
nzGetContainer?: HTMLElement | OverlayRef | (() => HTMLElement | OverlayRef); // STATIC
nzAfterOpen?: EventEmitter<void>;
nzAfterClose?: EventEmitter<R>;
Expand Down
14 changes: 7 additions & 7 deletions components/table/nz-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ import { NzVirtualScrollDirective } from './nz-virtual-scroll.directive';
`
]
})
export class NzTableComponent implements OnInit, AfterViewInit, OnDestroy, OnChanges, AfterContentInit {
// tslint:disable-next-line no-any
export class NzTableComponent<T = any> implements OnInit, AfterViewInit, OnDestroy, OnChanges, AfterContentInit {
/** public data for ngFor tr */
data = [];
/* tslint:disable-next-line:no-any */
locale: any = {};
data: T[] = [];
locale: any = {}; // tslint:disable-line:no-any
nzTheadComponent: NzTheadComponent;
lastScrollLeft = 0;
headerBottomStyle = {};
Expand All @@ -79,9 +79,9 @@ export class NzTableComponent implements OnInit, AfterViewInit, OnDestroy, OnCha
@Input() nzWidthConfig: string[] = [];
@Input() nzPageIndex = 1;
@Input() nzPageSize = 10;
@Input() nzData = [];
@Input() nzData: T[] = [];
@Input() nzPaginationPosition: 'top' | 'bottom' | 'both' = 'bottom';
@Input() nzScroll: { x: string | null; y: string | null } = { x: null, y: null };
@Input() nzScroll: { x?: string | null; y?: string | null } = { x: null, y: null };
@Input() @ViewChild('renderItemTemplate') nzItemRender: TemplateRef<{
$implicit: 'page' | 'prev' | 'next';
page: number;
Expand Down Expand Up @@ -188,7 +188,7 @@ export class NzTableComponent implements OnInit, AfterViewInit, OnDestroy, OnCha
}

updateFrontPaginationDataIfNeeded(isPageSizeOrDataChange: boolean = false): void {
let data = [];
let data: any[] = []; // tslint:disable-line:no-any
if (this.nzFrontPagination) {
this.nzTotal = this.nzData.length;
if (isPageSizeOrDataChange) {
Expand Down
2 changes: 1 addition & 1 deletion components/tooltip/nz-tooltip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class NzToolTipComponent implements OnChanges {
visibleSource = new BehaviorSubject<boolean>(false);
visible$: Observable<boolean> = this.visibleSource.asObservable();
@ViewChild('overlay') overlay: CdkConnectedOverlay;
@Input() @ContentChild('nzTemplate') nzTitle: string | TemplateRef<void>;
@Input() @ContentChild('nzTemplate') nzTitle: string | TemplateRef<void> | null;
@Input() nzOverlayClassName = '';
@Input() nzOverlayStyle: { [key: string]: string } = {};
@Input() nzMouseEnterDelay = 0.15; // second
Expand Down
4 changes: 2 additions & 2 deletions components/tooltip/nz-tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class NzTooltipDirective implements AfterViewInit, OnChanges, OnInit, OnD

@Output() readonly nzVisibleChange = new EventEmitter<boolean>();

@Input('nz-tooltip') nzTitle: string | TemplateRef<void>;
@Input('nz-tooltip') nzTitle: string | TemplateRef<void> | null;

@Input('nzTitle') set setTitle(title: string | TemplateRef<void>) {
@Input('nzTitle') set setTitle(title: string | TemplateRef<void> | null) {
this.nzTitle = title;
}

Expand Down

0 comments on commit c685836

Please sign in to comment.