Skip to content

Commit b04dfb2

Browse files
committed
feat(cdk/tree): move new demos to cdk-tree-redesign dir
1 parent e96e893 commit b04dfb2

File tree

6 files changed

+137
-108
lines changed

6 files changed

+137
-108
lines changed

src/components-examples/cdk/tree/cdk-tree-flat-level-accessor/cdk-tree-flat-level-accessor-example.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {ArrayDataSource} from '@angular/cdk/collections';
2+
import {Component} from '@angular/core';
3+
import {FlatFoodNode, FLAT_DATA, NESTED_DATA} from './tree-data';
4+
5+
/**
6+
* @title Tree with flat nodes
7+
*/
8+
@Component({
9+
selector: 'cdk-tree-flat-level-accessor-example',
10+
templateUrl: 'cdk-tree-flat-level-accessor-example.html',
11+
styleUrls: ['cdk-tree-flat-level-accessor-example.css'],
12+
})
13+
export class CdkTreeFlatLevelAccessorExample {
14+
levelAccessor = (dataNode: FlatFoodNode) => dataNode.level;
15+
16+
dataSource = new ArrayDataSource(FLAT_DATA);
17+
18+
hasChild = (_: number, node: FlatFoodNode) => node.expandable;
19+
20+
getParentNode(node: FlatFoodNode) {
21+
const nodeIndex = FLAT_DATA.indexOf(node);
22+
23+
for (let i = nodeIndex - 1; i >= 0; i--) {
24+
if (FLAT_DATA[i].level === node.level - 1) {
25+
return FLAT_DATA[i];
26+
}
27+
}
28+
29+
return null;
30+
}
31+
32+
shouldRender(node: FlatFoodNode) {
33+
let parent = this.getParentNode(node);
34+
while (parent) {
35+
if (!parent.isExpanded) {
36+
return false;
37+
}
38+
parent = this.getParentNode(parent);
39+
}
40+
return true;
41+
}
42+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/** Flat node with expandable and level information */
2+
export interface FlatFoodNode {
3+
expandable: boolean;
4+
name: string;
5+
level: number;
6+
isExpanded?: boolean;
7+
}
8+
9+
export const FLAT_DATA: FlatFoodNode[] = [
10+
{
11+
name: 'Fruit',
12+
expandable: true,
13+
level: 0,
14+
},
15+
{
16+
name: 'Apple',
17+
expandable: false,
18+
level: 1,
19+
},
20+
{
21+
name: 'Banana',
22+
expandable: false,
23+
level: 1,
24+
},
25+
{
26+
name: 'Fruit loops',
27+
expandable: false,
28+
level: 1,
29+
},
30+
{
31+
name: 'Vegetables',
32+
expandable: true,
33+
level: 0,
34+
},
35+
{
36+
name: 'Green',
37+
expandable: true,
38+
level: 1,
39+
},
40+
{
41+
name: 'Broccoli',
42+
expandable: false,
43+
level: 2,
44+
},
45+
{
46+
name: 'Brussels sprouts',
47+
expandable: false,
48+
level: 2,
49+
},
50+
{
51+
name: 'Orange',
52+
expandable: true,
53+
level: 1,
54+
},
55+
{
56+
name: 'Pumpkins',
57+
expandable: false,
58+
level: 2,
59+
},
60+
{
61+
name: 'Carrots',
62+
expandable: false,
63+
level: 2,
64+
},
65+
];
66+
67+
/**
68+
* Food data with nested structure.
69+
* Each node has a name and an optional list of children.
70+
*/
71+
export interface NestedFoodNode {
72+
name: string;
73+
children?: NestedFoodNode[];
74+
}
75+
76+
export const NESTED_DATA: NestedFoodNode[] = [
77+
{
78+
name: 'Fruit',
79+
children: [{name: 'Apple'}, {name: 'Banana'}, {name: 'Fruit loops'}],
80+
},
81+
{
82+
name: 'Vegetables',
83+
children: [
84+
{
85+
name: 'Green',
86+
children: [{name: 'Broccoli'}, {name: 'Brussels sprouts'}],
87+
},
88+
{
89+
name: 'Orange',
90+
children: [{name: 'Pumpkins'}, {name: 'Carrots'}],
91+
},
92+
],
93+
},
94+
];

src/components-examples/cdk/tree/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {NgModule} from '@angular/core';
33
import {MatLegacyButtonModule} from '@angular/material/legacy-button';
44
import {MatIconModule} from '@angular/material/icon';
55
import {CdkTreeFlatExample} from './cdk-tree-flat/cdk-tree-flat-example';
6-
import {CdkTreeFlatLevelAccessorExample} from './cdk-tree-flat-level-accessor/cdk-tree-flat-level-accessor-example';
76
import {CdkTreeNestedExample} from './cdk-tree-nested/cdk-tree-nested-example';
7+
import {CdkTreeFlatLevelAccessorExample} from './cdk-tree-redesign/cdk-tree-flat-level-accessor-example';
88

99
export {CdkTreeFlatExample, CdkTreeNestedExample, CdkTreeFlatLevelAccessorExample};
1010

0 commit comments

Comments
 (0)