1- import { Component , HostBinding , Input } from '@angular/core' ;
1+ import { Component , HostBinding , input , InputSignal } from '@angular/core' ;
22import { BadgePositions , Colors , Shapes , TextColors } from '../coreui.types' ;
33import { TextBgColorDirective , TextColorDirective } from '../utilities' ;
44
@@ -9,61 +9,69 @@ import { TextBgColorDirective, TextColorDirective } from '../utilities';
99 hostDirectives : [
1010 { directive : TextColorDirective , inputs : [ 'cTextColor: textColor' ] } ,
1111 { directive : TextBgColorDirective , inputs : [ 'cTextBgColor: textBgColor' ] }
12- ]
12+ ] ,
13+ host : {
14+ class : 'badge'
15+ }
1316} )
1417export class BadgeComponent {
1518 /**
1619 * Sets the color context of the component to one of CoreUI’s themed colors.
1720 * @type Colors
1821 */
19- @ Input ( ) color ?: Colors ;
22+ readonly color : InputSignal < Colors | undefined > = input ( ) ;
2023 /**
2124 * Position badge in one of the corners of a link or button.
2225 * @type BadgePositions
2326 */
24- @Input ( ) position ?: BadgePositions ;
27+ readonly position : InputSignal < BadgePositions | undefined > = input ( ) ;
28+
2529 /**
2630 * Select the shape of the component.
2731 * @type Shapes
2832 */
29- @Input ( ) shape ?: Shapes ;
33+ readonly shape : InputSignal < Shapes | undefined > = input ( ) ;
34+
3035 /**
3136 * Size the component small.
3237 */
33- @ Input ( ) size ?: 'sm' ;
38+ readonly size : InputSignal < 'sm' | undefined > = input ( ) ;
3439
3540 /**
3641 * Sets the text color of the component to one of CoreUI’s themed colors.
3742 * via TextColorDirective
3843 * @type TextColors
3944 */
40- @ Input ( ) textColor ?: TextColors ;
45+ readonly textColor : InputSignal < TextColors | undefined > = input ( ) ;
4146
4247 /**
4348 * Sets the component's color scheme to one of CoreUI's themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility.
4449 * via TextBgColorDirective
4550 * @type Colors
4651 * @since 5.0.0
4752 */
48- @ Input ( ) textBgColor ?: Colors ;
53+ readonly textBgColor : InputSignal < Colors | undefined > = input ( ) ;
4954
5055 @HostBinding ( 'class' )
5156 get hostClasses ( ) : any {
57+ const position = this . position ( ) ;
5258 const positionClasses = {
53- 'position-absolute' : ! ! this . position ,
54- 'translate-middle' : ! ! this . position ,
55- 'top-0' : this . position ?. includes ( 'top' ) ,
56- 'top-100' : this . position ?. includes ( 'bottom' ) ,
57- 'start-100' : this . position ?. includes ( 'end' ) ,
58- 'start-0' : this . position ?. includes ( 'start' )
59+ 'position-absolute' : ! ! position ,
60+ 'translate-middle' : ! ! position ,
61+ 'top-0' : position ?. includes ( 'top' ) ,
62+ 'top-100' : position ?. includes ( 'bottom' ) ,
63+ 'start-100' : position ?. includes ( 'end' ) ,
64+ 'start-0' : position ?. includes ( 'start' )
5965 } ;
6066
61- return Object . assign ( {
67+ return Object . assign (
68+ {
6269 badge : true ,
63- [ `bg-${ this . color } ` ] : ! ! this . color ,
64- [ `badge-${ this . size } ` ] : ! ! this . size ,
65- [ `${ this . shape } ` ] : ! ! this . shape
66- } , ! ! this . position ? positionClasses : { }
70+ [ `bg-${ this . color ( ) } ` ] : ! ! this . color ( ) ,
71+ [ `badge-${ this . size ( ) } ` ] : ! ! this . size ( ) ,
72+ [ `${ this . shape ( ) } ` ] : ! ! this . shape ( )
73+ } ,
74+ ! ! position ? positionClasses : { }
6775 ) ;
6876 }
6977}
0 commit comments