1
- import { Directive , HostBinding , Input } from '@angular/core' ;
1
+ import { computed , Directive , input } from '@angular/core' ;
2
2
import { Rounded } from './rounded.type' ;
3
3
4
4
@Directive ( {
5
- selector : '[cRounded]'
5
+ selector : '[cRounded]' ,
6
+ exportAs : 'cRounded' ,
7
+ host : { '[class]' : 'hostClasses' }
6
8
} )
7
9
export class RoundedDirective {
8
10
/**
9
11
* Set border radius variant and radius size
10
12
* @type Rounded
11
13
*/
12
- @ Input ( ' cRounded' ) rounded : Rounded = true ;
14
+ readonly cRounded = input < Rounded > ( true ) ;
13
15
14
- @ HostBinding ( 'class' )
15
- get hostClasses ( ) : any {
16
- if ( typeof this . rounded === 'boolean' ) {
16
+ readonly hostClasses = computed ( ( ) => {
17
+ const rounded = this . cRounded ( ) ;
18
+ if ( typeof rounded === 'boolean' ) {
17
19
return { rounded : true } ;
18
20
}
19
- if ( typeof this . rounded === 'number' || typeof this . rounded === 'string' ) {
21
+ if ( typeof rounded === 'number' || typeof rounded === 'string' ) {
20
22
return {
21
- [ `rounded-${ this . rounded } ` ] : true
23
+ [ `rounded-${ rounded } ` ] : true
22
24
} ;
23
25
}
24
- if ( typeof this . rounded === 'object' ) {
26
+ if ( typeof rounded === 'object' ) {
25
27
const roundedObj = {
26
28
top : undefined ,
27
29
end : undefined ,
@@ -30,7 +32,7 @@ export class RoundedDirective {
30
32
circle : undefined ,
31
33
pill : undefined ,
32
34
size : undefined ,
33
- ...this . rounded
35
+ ...rounded
34
36
} ;
35
37
// @ts -ignore
36
38
const keys = Object . keys ( roundedObj ) . filter ( ( key ) => roundedObj [ key ] !== undefined ) ;
@@ -49,5 +51,6 @@ export class RoundedDirective {
49
51
// console.log('rounded keys', keys, classes);
50
52
return Object . entries ( classes ) . length === 0 ? { rounded : false } : classes ;
51
53
}
52
- }
54
+ return { rounded : false } ;
55
+ } ) ;
53
56
}
0 commit comments