File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed
projects/coreui-angular/src/lib/utilities Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change
1
+ import { TestBed } from '@angular/core/testing' ;
1
2
import { BgColorDirective } from './bg-color.directive' ;
2
3
3
4
describe ( 'BgColorDirective' , ( ) => {
4
5
it ( 'should create an instance' , ( ) => {
6
+ TestBed . runInInjectionContext ( ( ) => {
5
7
const directive = new BgColorDirective ( ) ;
6
8
expect ( directive ) . toBeTruthy ( ) ;
9
+ } ) ;
7
10
} ) ;
8
11
} ) ;
Original file line number Diff line number Diff line change 1
- import { Directive , HostBinding , Input } from '@angular/core' ;
1
+ import { computed , Directive , input } from '@angular/core' ;
2
2
import { BackgroundColors } from '../coreui.types' ;
3
3
4
4
@Directive ( {
5
- selector : '[cBgColor]'
5
+ selector : '[cBgColor]' ,
6
+ exportAs : 'cBgColor' ,
7
+ host : { '[class]' : 'hostClasses' }
6
8
} )
7
9
export class BgColorDirective {
8
10
/**
9
11
* Set the background of an element to any contextual class
10
12
*/
11
- @Input ( 'cBgColor' ) color : BackgroundColors = '' ;
13
+ readonly cBgColor = input < BackgroundColors > ( '' ) ;
14
+
12
15
/**
13
16
* Add linear gradient as background image to the backgrounds.
14
- * @type boolean
17
+ * @return boolean
15
18
*/
16
- @ Input ( ) gradient ?: boolean ;
19
+ readonly gradient = input < boolean > ( ) ;
17
20
18
- @ HostBinding ( 'class' )
19
- get hostClasses ( ) : any {
21
+ readonly hostClasses = computed ( ( ) => {
22
+ const color = this . cBgColor ( ) ;
20
23
return {
21
- [ `bg-${ this . color } ` ] : ! ! this . color ,
22
- 'bg-gradient' : this . gradient
24
+ [ `bg-${ color } ` ] : ! ! color ,
25
+ 'bg-gradient' : this . gradient ( )
23
26
} ;
24
- }
27
+ } ) ;
25
28
}
You can’t perform that action at this time.
0 commit comments