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' ;
12import { BgColorDirective } from './bg-color.directive' ;
23
34describe ( 'BgColorDirective' , ( ) => {
45 it ( 'should create an instance' , ( ) => {
6+ TestBed . runInInjectionContext ( ( ) => {
57 const directive = new BgColorDirective ( ) ;
68 expect ( directive ) . toBeTruthy ( ) ;
9+ } ) ;
710 } ) ;
811} ) ;
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' ;
22import { BackgroundColors } from '../coreui.types' ;
33
44@Directive ( {
5- selector : '[cBgColor]'
5+ selector : '[cBgColor]' ,
6+ exportAs : 'cBgColor' ,
7+ host : { '[class]' : 'hostClasses' }
68} )
79export class BgColorDirective {
810 /**
911 * Set the background of an element to any contextual class
1012 */
11- @Input ( 'cBgColor' ) color : BackgroundColors = '' ;
13+ readonly cBgColor = input < BackgroundColors > ( '' ) ;
14+
1215 /**
1316 * Add linear gradient as background image to the backgrounds.
14- * @type boolean
17+ * @return boolean
1518 */
16- @ Input ( ) gradient ?: boolean ;
19+ readonly gradient = input < boolean > ( ) ;
1720
18- @ HostBinding ( 'class' )
19- get hostClasses ( ) : any {
21+ readonly hostClasses = computed ( ( ) => {
22+ const color = this . cBgColor ( ) ;
2023 return {
21- [ `bg-${ this . color } ` ] : ! ! this . color ,
22- 'bg-gradient' : this . gradient
24+ [ `bg-${ color } ` ] : ! ! color ,
25+ 'bg-gradient' : this . gradient ( )
2326 } ;
24- }
27+ } ) ;
2528}
You can’t perform that action at this time.
0 commit comments