Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add types definition for input #4575

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/card/nz-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class NzCardComponent {
@Input() nzBodyStyle: { [key: string]: string };
@Input() nzCover: TemplateRef<void>;
@Input() nzActions: Array<TemplateRef<void>> = [];
@Input() nzType: string;
@Input() nzType: 'inner' | null;
@Input() @WithConfig(NZ_CONFIG_COMPONENT_NAME, 'default') nzSize: NzSizeDSType;
@Input() nzTitle: string | TemplateRef<void>;
@Input() nzExtra: string | TemplateRef<void>;
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 @@ -39,7 +39,7 @@ import {
import { fromEvent, Observable, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { getElementOffset, InputBoolean, isPromise, NzConfigService, warnDeprecation, WithConfig } from 'ng-zorro-antd/core';
import { getElementOffset, InputBoolean, isPromise, NzButtonType, NzConfigService, warnDeprecation, WithConfig } from 'ng-zorro-antd/core';
import { NzI18nService } from 'ng-zorro-antd/i18n';

import { NZ_MODAL_CONFIG, NzModalConfig } from './nz-modal-config';
Expand Down Expand Up @@ -94,7 +94,7 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R>
@Input() nzBodyStyle: object;
@Input() nzOkText: string | null;
@Input() nzCancelText: string | null;
@Input() nzOkType: string = 'primary';
@Input() nzOkType: NzButtonType = 'primary';
@Input() nzIconType: string = 'question-circle'; // Confirm Modal ONLY
@Input() nzModalType: ModalType = 'default';

Expand Down
3 changes: 2 additions & 1 deletion components/modal/nz-modal.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { OverlayRef } from '@angular/cdk/overlay';
import { EventEmitter, TemplateRef, Type } from '@angular/core';
import { NzButtonType } from 'ng-zorro-antd/core';

export type OnClickCallback<T> = (instance: T) => (false | void | {}) | Promise<false | void | {}>;

Expand Down Expand Up @@ -43,7 +44,7 @@ export interface ModalOptions<T = any, R = any> {

// --- Predefined OK & Cancel buttons
nzOkText?: string | null;
nzOkType?: string;
nzOkType?: NzButtonType;
nzOkLoading?: boolean;
nzOkDisabled?: boolean;
nzCancelDisabled?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions components/popconfirm/nz-popconfirm.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { takeUntil } from 'rxjs/operators';

import { InputBoolean, NzNoAnimationDirective, NzTSType } from 'ng-zorro-antd/core';
import { NzTooltipBaseDirective, NzTooltipTrigger } from 'ng-zorro-antd/tooltip';
import { NzTooltipBaseDirective, NzTooltipPlacement, NzTooltipTrigger } from 'ng-zorro-antd/tooltip';

import { NzPopconfirmComponent } from './nz-popconfirm.component';

Expand All @@ -40,7 +40,7 @@ export class NzPopconfirmDirective extends NzTooltipBaseDirective implements OnI
@Input('nzPopconfirmTitle') specificTitle: NzTSType;
@Input('nz-popconfirm') directiveNameTitle: NzTSType | null;
@Input('nzPopconfirmTrigger') specificTrigger: NzTooltipTrigger;
@Input('nzPopconfirmPlacement') specificPlacement: string;
@Input('nzPopconfirmPlacement') specificPlacement: NzTooltipPlacement;
@Input() nzOkText: string;
@Input() nzOkType: string;
@Input() nzCancelText: string;
Expand Down
4 changes: 2 additions & 2 deletions components/popover/nz-popover.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@angular/core';

import { NzNoAnimationDirective, NzTSType } from 'ng-zorro-antd/core';
import { NzTooltipBaseDirective, NzTooltipTrigger } from 'ng-zorro-antd/tooltip';
import { NzTooltipBaseDirective, NzTooltipPlacement, NzTooltipTrigger } from 'ng-zorro-antd/tooltip';

import { NzPopoverComponent } from './nz-popover.component';

Expand All @@ -35,7 +35,7 @@ export class NzPopoverDirective extends NzTooltipBaseDirective {
@Input('nzPopoverContent') specificContent: NzTSType;
@Input('nz-popover') directiveNameTitle: NzTSType | null;
@Input('nzPopoverTrigger') specificTrigger: NzTooltipTrigger;
@Input('nzPopoverPlacement') specificPlacement: string;
@Input('nzPopoverPlacement') specificPlacement: NzTooltipPlacement;

componentFactory: ComponentFactory<NzPopoverComponent> = this.resolver.resolveComponentFactory(NzPopoverComponent);

Expand Down
1 change: 1 addition & 0 deletions components/table/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Table 组件同时具备了易用性和高度可定制性
| `[nzItemRender]` | 用于自定义页码的结构,用法参照 Pagination 组件 | `TemplateRef<{ $implicit: 'page' \| 'prev' \| 'next', page: number }>` | - |
| `[nzHideOnSinglePage]` | 只有一页时是否隐藏分页器 | `boolean` | `false` | ✅ |
| `[nzSimple]` | 当添加该属性时,显示为简单分页 | `boolean` | - | ✅ |
| `[nzTemplateMode]` | 模板模式仅用于显示时使用,不需要 `nzData` | `boolean` | `false` |
| `[nzVirtualScroll]` | 是否启用虚拟滚动模式,与 `[nzScroll]` 配合使用 | `boolean` | `false` |
| `[nzVirtualItemSize]` | 虚拟滚动时每一列的高度,与 [cdk itemSize](https://material.angular.io/cdk/scrolling/api) 相同 | `number` | `0` |
| `[nzVirtualMaxBufferPx]` | 缓冲区最大像素高度,与 [cdk maxBufferPx](https://material.angular.io/cdk/scrolling/api) 相同 | `number` | `200` |
Expand Down
10 changes: 5 additions & 5 deletions components/tooltip/nz-tooltip-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
toBoolean
} from 'ng-zorro-antd/core';

import { NzTooltipTrigger } from './nz-tooltip.definitions';
import { NzTooltipPlacement, NzTooltipTrigger } from './nz-tooltip.definitions';

export abstract class NzTooltipBaseComponent implements OnDestroy {
@ViewChild('overlay', { static: false }) overlay: CdkConnectedOverlay;
Expand Down Expand Up @@ -59,21 +59,21 @@ export abstract class NzTooltipBaseComponent implements OnDestroy {

protected _trigger: NzTooltipTrigger = 'hover';

set nzPlacement(value: string) {
set nzPlacement(value: NzTooltipPlacement) {
if (value !== this.preferredPlacement) {
this.preferredPlacement = value;
this._positions = [POSITION_MAP[this.nzPlacement], ...this._positions];
}
}

get nzPlacement(): string {
get nzPlacement(): NzTooltipPlacement {
return this.preferredPlacement;
}

nzContentTemplate: TemplateRef<void>;
nzTitleTemplate: TemplateRef<void>;
origin: CdkOverlayOrigin;
preferredPlacement = 'top';
preferredPlacement: NzTooltipPlacement = 'top';

_classMap: NgClassInterface = {};
_hasBackdrop = false;
Expand Down Expand Up @@ -135,7 +135,7 @@ export abstract class NzTooltipBaseComponent implements OnDestroy {
}

onPositionChange(position: ConnectedOverlayPositionChange): void {
this.preferredPlacement = getPlacementName(position)!;
this.preferredPlacement = getPlacementName(position)! as NzTooltipPlacement;
this.setClassMap();
this.cdr.detectChanges();
}
Expand Down
8 changes: 4 additions & 4 deletions components/tooltip/nz-tooltip-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import { Subject } from 'rxjs';
import { distinctUntilChanged, takeUntil } from 'rxjs/operators';

import { NzTooltipBaseComponent } from './nz-tooltip-base.component';
import { NzTooltipTrigger } from './nz-tooltip.definitions';
import { NzTooltipPlacement, NzTooltipTrigger } from './nz-tooltip.definitions';

export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDestroy, AfterViewInit {
directiveNameTitle?: NzTSType | null;
specificTitle?: NzTSType | null;
directiveNameContent?: NzTSType | null;
specificContent?: NzTSType | null;
specificTrigger?: NzTooltipTrigger;
specificPlacement?: string;
specificPlacement?: NzTooltipPlacement;

/**
* @deprecated 10.0.0. This is deprecated and going to be removed in 10.0.0.
Expand All @@ -59,7 +59,7 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes
* @deprecated 10.0.0. This is deprecated and going to be removed in 10.0.0.
* Please use a more specific API. Like `nzTooltipPlacement`.
*/
@Input() nzPlacement: string = 'top';
@Input() nzPlacement: NzTooltipPlacement = 'top';

@Input() nzMouseEnterDelay: number;
@Input() nzMouseLeaveDelay: number;
Expand All @@ -83,7 +83,7 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes
return this.specificContent || this.directiveNameContent || this.nzContent;
}

protected get placement(): string {
protected get placement(): NzTooltipPlacement {
return this.specificPlacement || this.nzPlacement;
}

Expand Down
13 changes: 13 additions & 0 deletions components/tooltip/nz-tooltip.definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@
*/

export type NzTooltipTrigger = 'click' | 'focus' | 'hover' | null;
export type NzTooltipPlacement =
| 'top'
| 'left'
| 'right'
| 'bottom'
| 'topLeft'
| 'topRight'
| 'bottomLeft'
| 'bottomRight'
| 'leftTop'
| 'leftBottom'
| 'rightTop'
| 'rightBottom';
4 changes: 2 additions & 2 deletions components/tooltip/nz-tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { NzNoAnimationDirective, NzTSType } from 'ng-zorro-antd/core';

import { NzTooltipBaseDirective } from './nz-tooltip-base.directive';
import { NzToolTipComponent } from './nz-tooltip.component';
import { NzTooltipTrigger } from './nz-tooltip.definitions';
import { NzTooltipPlacement, NzTooltipTrigger } from './nz-tooltip.definitions';

@Directive({
selector: '[nz-tooltip]',
Expand All @@ -43,7 +43,7 @@ export class NzTooltipDirective extends NzTooltipBaseDirective {
@Input('nz-tooltip') directiveNameTitle: NzTSType | null;

@Input('nzTooltipTrigger') specificTrigger: NzTooltipTrigger;
@Input('nzTooltipPlacement') specificPlacement: string;
@Input('nzTooltipPlacement') specificPlacement: NzTooltipPlacement;

componentFactory: ComponentFactory<NzToolTipComponent> = this.resolver.resolveComponentFactory(NzToolTipComponent);

Expand Down