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 fix(module:icon): fix icon importing logger
- Loading branch information
Wendell
committed
Nov 8, 2018
1 parent
76fe065
commit 49e85da
Showing
19 changed files
with
935 additions
and
1,181 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 @@ | ||
--- | ||
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,73 @@ | ||
// 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'" | ||
[nzShowSearch]="true" | ||
[(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,47 @@ | ||
import { 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({ | ||
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.