File tree 9 files changed +77
-23
lines changed
9 files changed +77
-23
lines changed Original file line number Diff line number Diff line change
1
+ import { AppSidebarNavBadgePipe } from './app-sidebar-nav-badge.pipe' ;
2
+
3
+ describe ( 'AppSidebarNavBadgePipe' , ( ) => {
4
+ it ( 'create an instance' , ( ) => {
5
+ const pipe = new AppSidebarNavBadgePipe ( ) ;
6
+ expect ( pipe ) . toBeTruthy ( ) ;
7
+ } ) ;
8
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { Pipe , PipeTransform } from '@angular/core' ;
2
+
3
+ @Pipe ( {
4
+ name : 'appSidebarNavBadge'
5
+ } )
6
+ export class AppSidebarNavBadgePipe implements PipeTransform {
7
+
8
+ transform ( item : any , args ?: any ) : any {
9
+ const classes = {
10
+ 'badge' : true
11
+ } ;
12
+ const variant = `badge-${ item . badge . variant } ` ;
13
+ classes [ variant ] = ! ! item . badge . variant ;
14
+ return classes ;
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ import { AppSidebarNavIconPipe } from './app-sidebar-nav-icon.pipe' ;
2
+
3
+ describe ( 'AppSidebarNavIconPipe' , ( ) => {
4
+ it ( 'create an instance' , ( ) => {
5
+ const pipe = new AppSidebarNavIconPipe ( ) ;
6
+ expect ( pipe ) . toBeTruthy ( ) ;
7
+ } ) ;
8
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { Pipe , PipeTransform } from '@angular/core' ;
2
+
3
+ @Pipe ( {
4
+ name : 'appSidebarNavIcon'
5
+ } )
6
+ export class AppSidebarNavIconPipe implements PipeTransform {
7
+
8
+ transform ( item : any , args ?: any ) : any {
9
+ const classes = {
10
+ 'nav-icon' : true
11
+ } ;
12
+ const icon = item . icon ;
13
+ classes [ icon ] = ! ! item . icon ;
14
+ return classes ;
15
+ }
16
+ }
Original file line number Diff line number Diff line change 3
3
[appHtmlAttr] ="item.attributes ">
4
4
< i *ngIf ="helper.hasIcon(item) " [ngClass] ="getLabelIconClass() "> </ i >
5
5
< ng-container > {{item.name}}</ ng-container >
6
- < span *ngIf ="helper.hasBadge(item) " [ngClass] ="helper.getBadgeClass( item) "> {{ item.badge.text }}</ span >
6
+ < span *ngIf ="helper.hasBadge(item) " [ngClass] ="item | appSidebarNavBadge "> {{ item.badge.text }}</ span >
7
7
</ a >
Original file line number Diff line number Diff line change @@ -8,28 +8,30 @@ import {SidebarNavHelper} from '../app-sidebar-nav.service';
8
8
export class AppSidebarNavLabelComponent implements OnInit {
9
9
@Input ( ) item : any ;
10
10
11
+ private classes = {
12
+ 'nav-label' : true ,
13
+ 'active' : true
14
+ } ;
15
+ private iconClasses = { } ;
16
+
11
17
constructor (
12
18
public helper : SidebarNavHelper
13
19
) { }
14
20
15
21
ngOnInit ( ) {
22
+ this . iconClasses = this . helper . getIconClass ( this . item ) ;
16
23
}
17
24
18
25
getItemClass ( ) {
19
- const labelClass = {
20
- 'nav-label' : true ,
21
- 'active' : true
22
- } ;
23
26
const itemClass = this . item . class ;
24
- labelClass [ itemClass ] = ! ! itemClass ;
25
- return labelClass ;
27
+ this . classes [ itemClass ] = ! ! itemClass ;
28
+ return this . classes ;
26
29
}
27
30
getLabelIconClass ( ) {
28
- const classes = this . helper . getIconClass ( this . item ) ;
29
31
const variant = `text-${ this . item . label . variant } ` ;
30
- classes [ variant ] = ! ! variant ;
32
+ this . iconClasses [ variant ] = ! ! this . item . label . variant ;
31
33
const labelClass = this . item . label . class ;
32
- classes [ labelClass ] = ! ! labelClass ;
33
- return classes ;
34
+ this . iconClasses [ labelClass ] = ! ! labelClass ;
35
+ return this . iconClasses ;
34
36
}
35
37
}
Original file line number Diff line number Diff line change 3
3
[ngClass] ="getLinkClass() "
4
4
href ="{{item.url}} "
5
5
[appHtmlAttr] ="item.attributes ">
6
- < i *ngIf ="helper.hasIcon(item) " [ngClass] ="helper.getIconClass( item) "> </ i >
6
+ < i *ngIf ="helper.hasIcon(item) " [ngClass] ="item | appSidebarNavIcon "> </ i >
7
7
< ng-container > {{item.name}}</ ng-container >
8
- < span *ngIf ="helper.hasBadge(item) " [ngClass] ="helper.getBadgeClass( item) "> {{ item.badge.text }}</ span >
8
+ < span *ngIf ="helper.hasBadge(item) " [ngClass] ="item | appSidebarNavBadge "> {{ item.badge.text }}</ span >
9
9
</ a >
10
10
< a *ngSwitchDefault
11
11
[ngClass] ="getLinkClass() "
14
14
routerLinkActive ="active "
15
15
[routerLink] ="[item.url] "
16
16
(click) ="hideMobile() ">
17
- < i *ngIf ="helper.hasIcon(item) " [ngClass] ="helper.getIconClass( item) "> </ i >
17
+ < i *ngIf ="helper.hasIcon(item) " [ngClass] ="item | appSidebarNavIcon "> </ i >
18
18
< ng-container > {{item.name}}</ ng-container >
19
- < span *ngIf ="helper.hasBadge(item) " [ngClass] ="helper.getBadgeClass( item) "> {{ item.badge.text }}</ span >
19
+ < span *ngIf ="helper.hasBadge(item) " [ngClass] ="item | appSidebarNavBadge "> {{ item.badge.text }}</ span >
20
20
</ a >
21
21
</ ng-container >
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ export class AppSidebarNavLinkComponent implements OnInit {
12
12
public linkType : string ;
13
13
public href : string ;
14
14
15
+ private classes = { 'nav-link' : true } ;
16
+
15
17
constructor (
16
18
@Inject ( DOCUMENT ) private document : any ,
17
19
private renderer : Renderer2 ,
@@ -25,16 +27,13 @@ export class AppSidebarNavLinkComponent implements OnInit {
25
27
26
28
public getLinkClass ( ) {
27
29
const disabled = this . isDisabled ( ) ;
28
- const classes = {
29
- 'nav-link' : true ,
30
- 'disabled' : disabled ,
31
- 'btn-link' : disabled
32
- } ;
30
+ this . classes [ 'disabled' ] = disabled ;
31
+ this . classes [ 'btn-link' ] = disabled ;
33
32
if ( this . hasVariant ( ) ) {
34
33
const variant = `nav-link-${ this . item . variant } ` ;
35
- classes [ variant ] = true ;
34
+ this . classes [ variant ] = true ;
36
35
}
37
- return classes ;
36
+ return this . classes ;
38
37
}
39
38
40
39
public getLinkType ( ) {
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import { AppSidebarNavLinkComponent } from './app-sidebar-nav/app-sidebar-nav-li
19
19
import { AppSidebarNavTitleComponent } from './app-sidebar-nav/app-sidebar-nav-title.component' ;
20
20
import { SidebarNavHelper } from './app-sidebar-nav.service' ;
21
21
import { AppSidebarNavLabelComponent } from './app-sidebar-nav/app-sidebar-nav-label.component' ;
22
+ import { AppSidebarNavIconPipe } from './app-sidebar-nav/app-sidebar-nav-icon.pipe' ;
23
+ import { AppSidebarNavBadgePipe } from './app-sidebar-nav/app-sidebar-nav-badge.pipe' ;
22
24
23
25
@NgModule ( {
24
26
imports : [
@@ -57,7 +59,9 @@ import { AppSidebarNavLabelComponent } from './app-sidebar-nav/app-sidebar-nav-l
57
59
AppSidebarNavTitleComponent ,
58
60
NavDropdownDirective ,
59
61
NavDropdownToggleDirective ,
60
- AppSidebarNavLabelComponent
62
+ AppSidebarNavLabelComponent ,
63
+ AppSidebarNavIconPipe ,
64
+ AppSidebarNavBadgePipe
61
65
] ,
62
66
providers : [
63
67
SidebarNavHelper
You can’t perform that action at this time.
0 commit comments