1
- import { Component , HostBinding , Input } from '@angular/core' ;
1
+ import { Component , HostBinding , input , InputSignal } from '@angular/core' ;
2
2
import { BadgePositions , Colors , Shapes , TextColors } from '../coreui.types' ;
3
3
import { TextBgColorDirective , TextColorDirective } from '../utilities' ;
4
4
@@ -9,61 +9,69 @@ import { TextBgColorDirective, TextColorDirective } from '../utilities';
9
9
hostDirectives : [
10
10
{ directive : TextColorDirective , inputs : [ 'cTextColor: textColor' ] } ,
11
11
{ directive : TextBgColorDirective , inputs : [ 'cTextBgColor: textBgColor' ] }
12
- ]
12
+ ] ,
13
+ host : {
14
+ class : 'badge'
15
+ }
13
16
} )
14
17
export class BadgeComponent {
15
18
/**
16
19
* Sets the color context of the component to one of CoreUI’s themed colors.
17
20
* @type Colors
18
21
*/
19
- @ Input ( ) color ?: Colors ;
22
+ readonly color : InputSignal < Colors | undefined > = input ( ) ;
20
23
/**
21
24
* Position badge in one of the corners of a link or button.
22
25
* @type BadgePositions
23
26
*/
24
- @Input ( ) position ?: BadgePositions ;
27
+ readonly position : InputSignal < BadgePositions | undefined > = input ( ) ;
28
+
25
29
/**
26
30
* Select the shape of the component.
27
31
* @type Shapes
28
32
*/
29
- @Input ( ) shape ?: Shapes ;
33
+ readonly shape : InputSignal < Shapes | undefined > = input ( ) ;
34
+
30
35
/**
31
36
* Size the component small.
32
37
*/
33
- @ Input ( ) size ?: 'sm' ;
38
+ readonly size : InputSignal < 'sm' | undefined > = input ( ) ;
34
39
35
40
/**
36
41
* Sets the text color of the component to one of CoreUI’s themed colors.
37
42
* via TextColorDirective
38
43
* @type TextColors
39
44
*/
40
- @ Input ( ) textColor ?: TextColors ;
45
+ readonly textColor : InputSignal < TextColors | undefined > = input ( ) ;
41
46
42
47
/**
43
48
* 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.
44
49
* via TextBgColorDirective
45
50
* @type Colors
46
51
* @since 5.0.0
47
52
*/
48
- @ Input ( ) textBgColor ?: Colors ;
53
+ readonly textBgColor : InputSignal < Colors | undefined > = input ( ) ;
49
54
50
55
@HostBinding ( 'class' )
51
56
get hostClasses ( ) : any {
57
+ const position = this . position ( ) ;
52
58
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' )
59
65
} ;
60
66
61
- return Object . assign ( {
67
+ return Object . assign (
68
+ {
62
69
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 : { }
67
75
) ;
68
76
}
69
77
}
0 commit comments