1
1
import {
2
- Component , Host , HostBinding , Input , OnDestroy , OnInit ,
2
+ Component , Host , HostBinding , Inject , Input , OnDestroy , OnInit ,
3
3
Optional , QueryList , SkipSelf , ViewChildren , ViewEncapsulation
4
4
} from '@angular/core' ;
5
+ import { expandCollapse , expandCollapseForDomDestroy } from 'ng-devui/utils' ;
5
6
import { AccordionItemRouterlinkComponent } from './accordion-item-routerlink.component' ;
6
- import { AccordionMenuComponent } from './accordion-menu.component' ;
7
- import { AccordionComponent } from './accordion.component' ;
7
+ import { ACCORDION_LIST } from './accordion-list-token' ;
8
+ import { ACCORDION_MENU } from './accordion-menu-token' ;
9
+ import { ACCORDION } from './accordion-token' ;
8
10
import { AccordionMenuItem } from './accordion.type' ;
9
11
10
12
@Component ( {
11
13
selector : 'd-accordion-list' ,
12
14
templateUrl : './accordion-list.component.html' ,
13
15
encapsulation : ViewEncapsulation . None ,
16
+ animations : [ expandCollapse , expandCollapseForDomDestroy ] ,
14
17
preserveWhitespaces : false ,
18
+ providers : [ {
19
+ provide : ACCORDION_LIST ,
20
+ useExisting : AccordionListComponent
21
+ } ]
15
22
} )
16
23
export class AccordionListComponent implements OnInit , OnDestroy {
17
- @Input ( ) data : Array < AccordionMenuItem > ;
18
- @Input ( ) deepth = 0 ;
19
- @Input ( ) parent : AccordionMenuItem ;
20
- @ViewChildren ( AccordionMenuComponent ) accordionMenuQueryList : QueryList < AccordionMenuComponent > ;
21
- @ViewChildren ( AccordionItemRouterlinkComponent ) accordionItemRouterlinkQueryList : QueryList < AccordionItemRouterlinkComponent > ;
22
- constructor ( @Optional ( ) @Host ( ) @SkipSelf ( ) private parentComponent : AccordionMenuComponent ,
23
- private accordion : AccordionComponent ) { }
24
- ngOnInit ( ) : void {
25
- if ( this . parentComponent ) {
26
- setTimeout ( ( ) => { this . parentComponent . accordionListFromView = this ; } ) ;
27
- }
28
- }
29
- ngOnDestroy ( ) : void {
30
- if ( this . parentComponent ) {
31
- this . parentComponent . accordionListFromView = undefined ;
32
- }
33
- }
34
24
25
+ // @HostBinding ('class.open')
26
+ // get open() {
27
+ // return (this.keyOpen === undefined && this.accordion.autoOpenActiveMenu)
28
+ // ? this.childActived
29
+ // : this.keyOpen;
30
+ // }
31
+ // get keyOpen() {
32
+ // return this.data && this.data[this.accordion.openKey];
33
+ // }
34
+
35
+ // get children() {
36
+ // return this.data && this.data[this.accordion.childrenKey];
37
+ // }
38
+ // get childActived() {
39
+ // return this.routerLinkActived || this.hasActiveChildren;
40
+ // }
41
+
42
+ // get showAnimate() {
43
+ // return this.accordion.showAnimation;
44
+ // }
45
+ constructor ( @Optional ( ) @Host ( ) @SkipSelf ( ) @Inject ( ACCORDION_MENU ) private parentComponent : any ,
46
+ @Inject ( ACCORDION ) private accordion : any ) { }
35
47
@HostBinding ( 'class.devui-accordion-show-animate' ) get animateState ( ) {
36
48
return this . accordion . showAnimation ;
37
49
}
@@ -81,21 +93,6 @@ export class AccordionListComponent implements OnInit, OnDestroy {
81
93
get linkDefaultTarget ( ) {
82
94
return this . accordion . linkDefaultTarget ;
83
95
}
84
- private isLinkRouterActive ( airlc : AccordionItemRouterlinkComponent ) : boolean {
85
- return airlc . routerLinkActived ;
86
- }
87
- private isMenuRouterActive ( amc : AccordionMenuComponent ) : boolean {
88
- return amc . routerLinkActived ;
89
- }
90
- private isMenuDataActive ( amc : AccordionMenuComponent ) : boolean {
91
- return amc . hasActiveChildren ;
92
- }
93
- private isItemDataActive ( item : AccordionMenuItem ) : boolean {
94
- return ! ! item [ this . activeKey ] ;
95
- }
96
- private isItemData ( item : AccordionMenuItem ) : boolean {
97
- return item [ this . childrenKey ] === undefined ;
98
- }
99
96
get routerLinkActived ( ) : boolean {
100
97
return ( ! ! this . accordionItemRouterlinkQueryList
101
98
&& this . accordionItemRouterlinkQueryList . some ( airlc => this . isLinkRouterActive ( airlc ) )
@@ -111,6 +108,37 @@ export class AccordionListComponent implements OnInit, OnDestroy {
111
108
&& this . data . some ( item => this . isItemData ( item ) && this . isItemDataActive ( item ) )
112
109
) ;
113
110
}
111
+ @Input ( ) data : Array < AccordionMenuItem > ;
112
+ @Input ( ) deepth = 0 ;
113
+ @Input ( ) parent : AccordionMenuItem ;
114
+ @ViewChildren ( ACCORDION_MENU ) accordionMenuQueryList : QueryList < any > ;
115
+ @ViewChildren ( AccordionItemRouterlinkComponent ) accordionItemRouterlinkQueryList : QueryList < AccordionItemRouterlinkComponent > ;
116
+ 6 ;
117
+ ngOnInit ( ) : void {
118
+ if ( this . parentComponent ) {
119
+ setTimeout ( ( ) => { this . parentComponent . accordionListFromView = this ; } ) ;
120
+ }
121
+ }
122
+ ngOnDestroy ( ) : void {
123
+ if ( this . parentComponent ) {
124
+ this . parentComponent . accordionListFromView = undefined ;
125
+ }
126
+ }
127
+ private isLinkRouterActive ( airlc : AccordionItemRouterlinkComponent ) : boolean {
128
+ return airlc . routerLinkActived ;
129
+ }
130
+ private isMenuRouterActive ( amc : any ) : boolean {
131
+ return amc . routerLinkActived ;
132
+ }
133
+ private isMenuDataActive ( amc : any ) : boolean {
134
+ return amc . hasActiveChildren ;
135
+ }
136
+ private isItemDataActive ( item : AccordionMenuItem ) : boolean {
137
+ return ! ! item [ this . activeKey ] ;
138
+ }
139
+ private isItemData ( item : AccordionMenuItem ) : boolean {
140
+ return item [ this . childrenKey ] === undefined ;
141
+ }
114
142
menuToggleItemFn = ( item : any , event ?: any ) => {
115
143
this . accordion . menuToggleFn ( {
116
144
item : item ,
0 commit comments