1- import { Directive , HostBinding , Input } from '@angular/core' ;
1+ import { computed , Directive , input } from '@angular/core' ;
22import { Rounded } from './rounded.type' ;
33
44@Directive ( {
5- selector : '[cRounded]'
5+ selector : '[cRounded]' ,
6+ exportAs : 'cRounded' ,
7+ host : { '[class]' : 'hostClasses' }
68} )
79export class RoundedDirective {
810 /**
911 * Set border radius variant and radius size
1012 * @type Rounded
1113 */
12- @ Input ( ' cRounded' ) rounded : Rounded = true ;
14+ readonly cRounded = input < Rounded > ( true ) ;
1315
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' ) {
1719 return { rounded : true } ;
1820 }
19- if ( typeof this . rounded === 'number' || typeof this . rounded === 'string' ) {
21+ if ( typeof rounded === 'number' || typeof rounded === 'string' ) {
2022 return {
21- [ `rounded-${ this . rounded } ` ] : true
23+ [ `rounded-${ rounded } ` ] : true
2224 } ;
2325 }
24- if ( typeof this . rounded === 'object' ) {
26+ if ( typeof rounded === 'object' ) {
2527 const roundedObj = {
2628 top : undefined ,
2729 end : undefined ,
@@ -30,7 +32,7 @@ export class RoundedDirective {
3032 circle : undefined ,
3133 pill : undefined ,
3234 size : undefined ,
33- ...this . rounded
35+ ...rounded
3436 } ;
3537 // @ts -ignore
3638 const keys = Object . keys ( roundedObj ) . filter ( ( key ) => roundedObj [ key ] !== undefined ) ;
@@ -49,5 +51,6 @@ export class RoundedDirective {
4951 // console.log('rounded keys', keys, classes);
5052 return Object . entries ( classes ) . length === 0 ? { rounded : false } : classes ;
5153 }
52- }
54+ return { rounded : false } ;
55+ } ) ;
5356}
0 commit comments