forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(module:cascader): refactor to Angular 7
close NG-ZORRO#2935, NG-ZORRO#2198
- Loading branch information
Wendell
committed
Nov 6, 2018
1 parent
76fe065
commit 5525372
Showing
17 changed files
with
833 additions
and
1,067 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "chrome", | ||
"request": "launch", | ||
"name": "Launch Chrome against localhost", | ||
"url": "http://localhost:49152", | ||
"webRoot": "${workspaceFolder}" | ||
} | ||
] | ||
} |
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,15 @@ | ||
--- | ||
order: 16 | ||
title: | ||
zh-CN: 自定义字段名 | ||
en-US: Custom Field Names | ||
--- | ||
|
||
## zh-CN | ||
|
||
自定义字段名。 | ||
|
||
## en-US | ||
|
||
Custom field names. | ||
|
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,72 @@ | ||
// tslint:disable:no-any | ||
import { Component } from '@angular/core'; | ||
|
||
const options = [{ | ||
code: 'zhejiang', | ||
name: 'Zhejiang', | ||
children: [{ | ||
code: 'hangzhou', | ||
name: 'Hangzhou', | ||
children: [{ | ||
code: 'xihu', | ||
name: 'West Lake', | ||
isLeaf: true | ||
}] | ||
}, { | ||
code: 'ningbo', | ||
name: 'Ningbo', | ||
children: [{ | ||
code: 'dongqianlake', | ||
name: 'Dongqian Lake', | ||
isLeaf: true | ||
}] | ||
}] | ||
}, { | ||
code: 'jiangsu', | ||
name: 'Jiangsu', | ||
children: [{ | ||
code: 'nanjing', | ||
name: 'Nanjing', | ||
children: [{ | ||
code: 'zhonghuamen', | ||
name: 'Zhong Hua Men', | ||
isLeaf: true | ||
}] | ||
}] | ||
}]; | ||
|
||
@Component({ | ||
selector: 'nz-demo-cascader-custom-field-names', | ||
template: ` | ||
<nz-cascader | ||
[nzChangeOn]="validate" | ||
[nzOptions]="nzOptions" | ||
[nzLabelProperty]="'name'" | ||
[nzValueProperty]="'code'" | ||
[(ngModel)]="values" | ||
(ngModelChange)="onChanges($event)"> | ||
</nz-cascader>`, | ||
styles : [ | ||
` | ||
.ant-cascader-picker { | ||
width: 300px; | ||
} | ||
` | ||
] | ||
}) | ||
export class NzDemoCascaderCustomFieldNamesComponent { | ||
/** init data */ | ||
nzOptions = options; | ||
|
||
/** ngModel value */ | ||
public values: any[] = null; | ||
|
||
public onChanges(values: any): void { | ||
console.log(values, this.values); | ||
} | ||
|
||
public validate(option: any, index: number): boolean { | ||
const value = option.value; | ||
return ['hangzhou', 'xihu', 'nanjing', 'zhonghuamen'].indexOf(value) >= 0; | ||
} | ||
} |
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,9 @@ | ||
<ng-container *ngIf="highlightText"> | ||
<span [innerHTML]="renderHighlightString(getOptionLabel())"></span> | ||
</ng-container> | ||
<ng-container *ngIf="!highlightText"> | ||
{{ getOptionLabel() }} | ||
</ng-container> | ||
<span *ngIf="!option.isLeaf || option.children && option.children.length || option.loading" class="ant-cascader-menu-item-expand-icon"> | ||
<i nz-icon [type]="option.loading ? 'loading' : 'right'"></i> | ||
</span> |
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,48 @@ | ||
import { ChangeDetectionStrategy, Component, Input, SecurityContext } from '@angular/core'; | ||
import { DomSanitizer } from '@angular/platform-browser'; | ||
import { classMapToString } from '../core/style/map'; | ||
import { CascaderOption } from './types'; | ||
|
||
const prefixCls = 'ant-cascader-menu-item'; | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
selector : '[nz-cascader-option]', | ||
templateUrl: './nz-cascader-li.component.html', | ||
host : { | ||
'[attr.title]': 'option.title || getOptionLabel()', | ||
'[class]' : 'getOptionClassString()' | ||
} | ||
}) | ||
export class NzCascaderOptionComponent { | ||
@Input() option: CascaderOption; | ||
@Input() activated = false; | ||
@Input() highlightText: string; | ||
@Input() nzLabelProperty = 'label'; | ||
|
||
getOptionLabel(): string { | ||
return this.option ? this.option[ this.nzLabelProperty ] : ''; | ||
} | ||
|
||
getOptionClassString(): string { | ||
return classMapToString({ | ||
[ `${prefixCls}` ] : true, | ||
[ `${prefixCls}-active` ] : this.activated, | ||
[ `${prefixCls}-expand` ] : !this.option.isLeaf, | ||
[ `${prefixCls}-disabled` ]: this.option.disabled | ||
}); | ||
} | ||
|
||
renderHighlightString(str: string): string { | ||
const safeHtml = this.sanitizer.sanitize( | ||
SecurityContext.HTML, `<span class="ant-cascader-menu-item-keyword">${this.highlightText}</span>` | ||
); | ||
if (!safeHtml) { | ||
throw new Error(`[NG-ZORRO] Input value "${this.highlightText}" is not considered security.`); | ||
} | ||
return str.replace(new RegExp(this.highlightText, 'g'), safeHtml); | ||
} | ||
|
||
constructor(private sanitizer: DomSanitizer) { | ||
} | ||
} |
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,8 @@ | ||
.ant-cascader-menus { | ||
margin-top: 4px; | ||
margin-bottom: 4px; | ||
top: 100%; | ||
left: 0; | ||
position: relative; | ||
width: 100%; | ||
} |
Oops, something went wrong.