Skip to content

Commit

Permalink
docs: make the better type of TS (#4246)
Browse files Browse the repository at this point in the history
* docs: make the better type of ts

* docs: fix demo filename

* docs: update cascader demos
  • Loading branch information
hsuanxyz authored and vthinkxie committed Oct 14, 2019
1 parent 812e1c5 commit f3a74f7
Show file tree
Hide file tree
Showing 77 changed files with 400 additions and 212 deletions.
2 changes: 1 addition & 1 deletion components/affix/demo/on-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Component } from '@angular/core';
`
})
export class NzDemoAffixOnChangeComponent {
onChange(status: boolean) {
onChange(status: boolean): void {
console.log(status);
}
}
10 changes: 8 additions & 2 deletions components/auto-complete/demo/certain-category.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@angular/core';

export interface AutocompleteOptionGroups {
title: string;
count?: number;
children?: AutocompleteOptionGroups[];
}

@Component({
selector: 'nz-demo-auto-complete-certain-category',
encapsulation: ViewEncapsulation.None,
Expand Down Expand Up @@ -50,9 +56,9 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@
})
export class NzDemoAutoCompleteCertainCategoryComponent implements OnInit {
inputValue: string;
optionGroups: any[];
optionGroups: AutocompleteOptionGroups[];

onChange(value: any): void {
onChange(value: string): void {
console.log(value);
}

Expand Down
4 changes: 3 additions & 1 deletion components/avatar/demo/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class NzDemoAvatarDynamicComponent {
change(): void {
let idx = userList.indexOf(this.text);
++idx;
if (idx === userList.length) idx = 0;
if (idx === userList.length) {
idx = 0;
}
this.text = userList[idx];
this.color = colorList[idx];
}
Expand Down
12 changes: 6 additions & 6 deletions components/cascader/demo/change-on-function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -69,15 +69,15 @@ const options = [
]
})
export class NzDemoCascaderChangeOnFunctionComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}

validate(option: any, _index: number): boolean {
const value = option.value;
validate(option: NzCascaderOption, _index: number): boolean {
const value = option.value as string;
return ['hangzhou', 'xihu', 'nanjing', 'zhonghuamen'].indexOf(value) >= 0;
}
}
8 changes: 4 additions & 4 deletions components/cascader/demo/change-on-select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -58,10 +58,10 @@ const options = [
]
})
export class NzDemoCascaderChangeOnSelectComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}
}
12 changes: 6 additions & 6 deletions components/cascader/demo/custom-field-names.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -72,15 +72,15 @@ const options = [
]
})
export class NzDemoCascaderCustomFieldNamesComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}

validate(option: any, _index: number): boolean {
const value = option.value;
validate(option: NzCascaderOption, _index: number): boolean {
const value = option.value as string;
return ['hangzhou', 'xihu', 'nanjing', 'zhonghuamen'].indexOf(value) >= 0;
}
}
10 changes: 5 additions & 5 deletions components/cascader/demo/custom-render.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -77,14 +77,14 @@ const options = [
]
})
export class NzDemoCascaderCustomRenderComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}

handleAreaClick(e: Event, label: string, option: any): void {
handleAreaClick(e: Event, label: string, option: NzCascaderOption): void {
e.preventDefault();
e.stopPropagation();
console.log('clicked "', label, '"', option);
Expand Down
8 changes: 4 additions & 4 deletions components/cascader/demo/default-value-and-asyn-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component, OnInit } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -57,10 +57,10 @@ const options = [
]
})
export class NzDemoCascaderDefaultValueAndAsynOptionsComponent implements OnInit {
nzOptions: any[] | null = null;
values: any[] = ['zhejiang', 'hangzhou', 'xihu'];
nzOptions: NzCascaderOption[] | null = null;
values: string[] = ['zhejiang', 'hangzhou', 'xihu'];

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}

Expand Down
8 changes: 4 additions & 4 deletions components/cascader/demo/default-value-and-lazyload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const provinces = [
{
Expand Down Expand Up @@ -63,14 +63,14 @@ const scenicspots: { [key: string]: Array<{ value: string; label: string; isLeaf
]
})
export class NzDemoCascaderDefaultValueAndLazyloadComponent {
values: any[] = ['zhejiang', 'hangzhou', 'xihu'];
values: string[] = ['zhejiang', 'hangzhou', 'xihu'];

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}

/** load data async execute by `nzLoadData` method */
loadData(node: any, index: number): PromiseLike<any> {
loadData(node: NzCascaderOption, index: number): PromiseLike<void> {
return new Promise(resolve => {
setTimeout(() => {
if (index < 0) {
Expand Down
8 changes: 4 additions & 4 deletions components/cascader/demo/default-value.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -57,9 +57,9 @@ const options = [
]
})
export class NzDemoCascaderDefaultValueComponent {
nzOptions = options;
nzOptions: NzCascaderOption[] = options;

values: any[] = ['zhejiang', 'hangzhou', 'xihu'];
values: string[] = ['zhejiang', 'hangzhou', 'xihu'];
/* // or like this:
values: any[] = [{
value: 'zhejiang',
Expand All @@ -72,7 +72,7 @@ export class NzDemoCascaderDefaultValueComponent {
label: 'West Lake'
}]; */

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}
}
8 changes: 4 additions & 4 deletions components/cascader/demo/disabled.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -58,10 +58,10 @@ const options = [
]
})
export class NzDemoCascaderDisabledComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}
}
8 changes: 4 additions & 4 deletions components/cascader/demo/hover.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -63,10 +63,10 @@ const options = [
]
})
export class NzDemoCascaderHoverComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}
}
8 changes: 4 additions & 4 deletions components/cascader/demo/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const provinces = [
{
Expand Down Expand Up @@ -63,14 +63,14 @@ const scenicspots: { [key: string]: Array<{ value: string; label: string; isLeaf
]
})
export class NzDemoCascaderLazyComponent {
values: any[] | null = null;
values: string[] | null = null;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values);
}

/** load data async execute by `nzLoadData` method */
loadData(node: any, index: number): PromiseLike<any> {
loadData(node: NzCascaderOption, index: number): PromiseLike<void> {
return new Promise(resolve => {
setTimeout(() => {
if (index < 0) {
Expand Down
8 changes: 4 additions & 4 deletions components/cascader/demo/modal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -66,11 +66,11 @@ const options = [
]
})
export class NzDemoCascaderModalComponent {
nzOptions = options;
values: any[] | null = null;
nzOptions: NzCascaderOption[] = options;
values: string[] | null = null;
isVisible = false;

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}

Expand Down
25 changes: 17 additions & 8 deletions components/cascader/demo/reactive-form.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// tslint:disable:no-any
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Component, OnDestroy } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';
import { Subscription } from 'rxjs';

const options = [
{
Expand Down Expand Up @@ -48,7 +49,7 @@ const options = [
selector: 'nz-demo-cascader-reactive-form',
template: `
<form [formGroup]="form" novalidate>
<nz-cascader [nzOptions]="nzOptions" (nzChange)="onChanges($event)" [formControlName]="'name'"> </nz-cascader>
<nz-cascader [nzOptions]="nzOptions" [formControlName]="'name'"> </nz-cascader>
</form>
<br />
<button nz-button (click)="reset()">Reset</button>
Expand All @@ -66,12 +67,16 @@ const options = [
`
]
})
export class NzDemoCascaderReactiveFormComponent {
export class NzDemoCascaderReactiveFormComponent implements OnDestroy {
form: FormGroup;
nzOptions = options;

nzOptions: NzCascaderOption[] = options;
changeSubscription: Subscription;
constructor(private fb: FormBuilder) {
this.createForm();
const control = this.form.get('name') as FormControl;
this.changeSubscription = control.valueChanges.subscribe(data => {
this.onChanges(data);
});
}

private createForm(): void {
Expand All @@ -89,7 +94,11 @@ export class NzDemoCascaderReactiveFormComponent {
console.log(this.form.value);
}

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values);
}

ngOnDestroy(): void {
this.changeSubscription.unsubscribe();
}
}
8 changes: 4 additions & 4 deletions components/cascader/demo/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any
import { Component, OnInit } from '@angular/core';
import { NzCascaderOption } from 'ng-zorro-antd/cascader';

const options = [
{
Expand Down Expand Up @@ -105,8 +105,8 @@ const otherOptions = [
]
})
export class NzDemoCascaderSearchComponent implements OnInit {
nzOptions: any = null;
values: any[] | null = null;
nzOptions: NzCascaderOption[] | null = null;
values: string[] | null = null;

ngOnInit(): void {
setTimeout(() => {
Expand All @@ -122,7 +122,7 @@ export class NzDemoCascaderSearchComponent implements OnInit {
}
}

onChanges(values: any): void {
onChanges(values: string[]): void {
console.log(values, this.values);
}
}
Loading

0 comments on commit f3a74f7

Please sign in to comment.