-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:(module:tree-select): add tree-select component (#1477)
close #1391
- Loading branch information
Showing
24 changed files
with
1,786 additions
and
6 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
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,55 @@ | ||
import { | ||
animate, | ||
state, | ||
style, | ||
transition, | ||
trigger, | ||
AnimationTriggerMetadata | ||
} from '@angular/animations'; | ||
|
||
export const selectDropDownAnimation: AnimationTriggerMetadata = trigger('selectDropDownAnimation', [ | ||
state('hidden', style({ | ||
opacity: 0, | ||
display: 'none' | ||
})), | ||
state('bottom', style({ | ||
opacity : 1, | ||
transform : 'scaleY(1)', | ||
transformOrigin: '0% 0%' | ||
})), | ||
state('top', style({ | ||
opacity : 1, | ||
transform : 'scaleY(1)', | ||
transformOrigin: '0% 100%' | ||
})), | ||
transition('hidden => bottom', [ | ||
style({ | ||
opacity : 0, | ||
transform : 'scaleY(0.8)', | ||
transformOrigin: '0% 0%' | ||
}), | ||
animate('100ms cubic-bezier(0.755, 0.05, 0.855, 0.06)') | ||
]), | ||
transition('bottom => hidden', [ | ||
animate('100ms cubic-bezier(0.755, 0.05, 0.855, 0.06)', style({ | ||
opacity : 0, | ||
transform : 'scaleY(0.8)', | ||
transformOrigin: '0% 0%' | ||
})) | ||
]), | ||
transition('hidden => top', [ | ||
style({ | ||
opacity : 0, | ||
transform : 'scaleY(0.8)', | ||
transformOrigin: '0% 100%' | ||
}), | ||
animate('100ms cubic-bezier(0.755, 0.05, 0.855, 0.06)') | ||
]), | ||
transition('top => hidden', [ | ||
animate('100ms cubic-bezier(0.755, 0.05, 0.855, 0.06)', style({ | ||
opacity : 0, | ||
transform : 'scaleY(0.8)', | ||
transformOrigin: '0% 100%' | ||
})) | ||
]) | ||
]); |
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,21 @@ | ||
import { | ||
animate, | ||
state, | ||
style, | ||
transition, | ||
trigger, | ||
AnimationTriggerMetadata | ||
} from '@angular/animations'; | ||
|
||
export const selectTagAnimation: AnimationTriggerMetadata = trigger('selectTagAnimation', [ | ||
state('*', style({ opacity: 1, transform: 'scale(1)' })), | ||
transition('void => *', [ | ||
style({ opacity: 0, transform: 'scale(0)' }), | ||
animate('150ms linear') | ||
]), | ||
state('void', style({ opacity: 0, transform: 'scale(0)' })), | ||
transition('* => void', [ | ||
style({ opacity: 1, transform: 'scale(1)' }), | ||
animate('150ms linear') | ||
]) | ||
]); |
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,15 @@ | ||
--- | ||
order: 2 | ||
title: | ||
zh-CN: 异步数据加载 | ||
en-US: Load data asynchronously | ||
--- | ||
|
||
## zh-CN | ||
|
||
点击展开节点,动态加载数据,直到执行 addChildren() 方法取消加载状态。 | ||
|
||
## en-US | ||
|
||
To load data asynchronously when click to expand a treeNode, loading state keeps until excute addChildren(). | ||
|
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,133 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-tree-select-async', | ||
template: ` | ||
<nz-tree-select style="width: 250px" | ||
nzPlaceHolder="Please select" | ||
[nzDefaultExpandedKeys]="expandKeys" | ||
[nzDropdownMatchSelectWidth]="true" | ||
[nzDropdownStyle]="{ 'max-height': '300px' }" | ||
[(ngModel)]="value" | ||
[nzNodes]="nodes" | ||
[nzAsyncData]="true" | ||
(nzExpandChange)="onExpandChange($event)"> | ||
</nz-tree-select> | ||
` | ||
}) | ||
|
||
export class NzDemoTreeSelectAsyncComponent implements OnInit { | ||
expandKeys = [ '1001', '10001' ]; | ||
value: string; | ||
nodes = [ | ||
new NzTreeNode({ | ||
title: 'root1', | ||
key: '1001', | ||
children: [ | ||
{ | ||
title: 'child1', | ||
key: '10001', | ||
children: [ | ||
{ | ||
title: 'child1.1', | ||
key: '100011', | ||
children: [] | ||
}, | ||
{ | ||
title: 'child1.2', | ||
key: '100012', | ||
children: [ | ||
{ | ||
title: 'grandchild1.2.1', | ||
key: '1000121', | ||
isLeaf: true, | ||
disabled: true | ||
}, | ||
{ | ||
title: 'grandchild1.2.2', | ||
key: '1000122', | ||
isLeaf: true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}), | ||
new NzTreeNode({ | ||
title: 'root2', | ||
key: '1002', | ||
children: [ | ||
{ | ||
title: 'child2.1', | ||
key: '10021', | ||
children: [], | ||
disabled: true | ||
}, | ||
{ | ||
title: 'child2.2', | ||
key: '10022', | ||
children: [ | ||
{ | ||
title: 'grandchild2.2.1', | ||
key: '100221', | ||
isLeaf: true | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
]; | ||
|
||
onExpandChange(e: NzFormatEmitEvent): void { | ||
if (e.node.getChildren().length === 0 && e.node.isExpanded) { | ||
this.loadNode().then(data => { | ||
e.node.addChildren(data); | ||
}); | ||
} | ||
} | ||
|
||
loadNode(): Promise<any[]> { | ||
return new Promise(resolve => { | ||
setTimeout(() => resolve([ | ||
new NzTreeNode({ | ||
title: 'root2', | ||
key: '10030-' + (new Date()).getTime(), | ||
children: [ | ||
{ | ||
title: 'child2.1', | ||
key: '10021', | ||
children: [], | ||
checked: true, | ||
disabled: true | ||
}, | ||
{ | ||
title: 'child2.2', | ||
key: '10022', | ||
children: [ | ||
{ | ||
title: 'grandchild2.2.1', | ||
key: '100221', | ||
isLeaf: true | ||
} | ||
] | ||
} | ||
] | ||
}), | ||
{ | ||
title: 'childAdd-1', | ||
key: '10031-' + (new Date()).getTime() | ||
}, | ||
{ | ||
title: 'childAdd-2', | ||
key: '10032-' + (new Date()).getTime(), | ||
isLeaf: true | ||
}]), | ||
1000); | ||
}); | ||
} | ||
|
||
ngOnInit(): void { | ||
} | ||
} |
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,14 @@ | ||
--- | ||
order: 0 | ||
title: | ||
zh-CN: 基本 | ||
en-US: Basic | ||
--- | ||
|
||
## zh-CN | ||
|
||
最简单的用法。 | ||
|
||
## en-US | ||
|
||
The most basic usage. |
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,90 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-tree-select-basic', | ||
template: ` | ||
<nz-tree-select | ||
style="width: 250px" | ||
[nzDefaultExpandedKeys]="expandKeys" | ||
[nzNodes]="nodes" | ||
nzPlaceHolder="Please select" | ||
[(ngModel)]="value" | ||
(ngModelChange)="onChange($event)"> | ||
</nz-tree-select>` | ||
}) | ||
|
||
export class NzDemoTreeSelectBasicComponent implements OnInit { | ||
expandKeys = [ '1001', '10001' ]; | ||
value: string; | ||
nodes = [ | ||
new NzTreeNode({ | ||
title: 'root1', | ||
key: '1001', | ||
children: [ | ||
{ | ||
title: 'child1', | ||
key: '10001', | ||
children: [ | ||
{ | ||
title: 'child1.1', | ||
key: '100011', | ||
children: [] | ||
}, | ||
{ | ||
title: 'child1.2', | ||
key: '100012', | ||
children: [ | ||
{ | ||
title: 'grandchild1.2.1', | ||
key: '1000121', | ||
isLeaf: true, | ||
disabled: true | ||
}, | ||
{ | ||
title: 'grandchild1.2.2', | ||
key: '1000122', | ||
isLeaf: true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}), | ||
new NzTreeNode({ | ||
title: 'root2', | ||
key: '1002', | ||
children: [ | ||
{ | ||
title: 'child2.1', | ||
key: '10021', | ||
children: [], | ||
disableCheckbox: true | ||
}, | ||
{ | ||
title: 'child2.2', | ||
key: '10022', | ||
children: [ | ||
{ | ||
title: 'grandchild2.2.1', | ||
key: '100221', | ||
isLeaf: true | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
]; | ||
|
||
onChange($event: NzTreeNode): void { | ||
console.log($event); | ||
} | ||
|
||
ngOnInit(): void { | ||
// mock async | ||
setTimeout(() => { | ||
this.value = '10001'; | ||
}, 1000); | ||
} | ||
} |
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: 3 | ||
title: | ||
zh-CN: 可勾选 | ||
en-US: Checkable | ||
--- | ||
|
||
## zh-CN | ||
|
||
使用勾选框实现多选功能。 | ||
|
||
## en-US | ||
|
||
Multiple and checkable. | ||
|
Oops, something went wrong.