1
- import {
1
+ import {
2
2
Component ,
3
3
ChangeDetectorRef ,
4
4
EventEmitter ,
16
16
} from '@angular/core' ;
17
17
import { IDisplayDensityOptions , DisplayDensityToken , DisplayDensityBase } from '../core/density' ;
18
18
import { IgxDragDirective , IDragBaseEventArgs , IDragStartEventArgs , IDropBaseEventArgs , IDropDroppedEventArgs , IgxDropDirective } from '../directives/drag-drop/drag-drop.directive' ;
19
- import { IBaseEventArgs } from '../core/utils' ;
19
+ import { IBaseEventArgs , mkenum } from '../core/utils' ;
20
20
import { IChipResourceStrings } from '../core/i18n/chip-resources' ;
21
21
import { CurrentResourceStrings } from '../core/i18n/resources' ;
22
- import { fromEvent , Subject } from 'rxjs' ;
23
- import { take , filter } from 'rxjs/operators' ;
22
+ import { Subject } from 'rxjs' ;
24
23
import { IgxIconComponent } from '../icon/icon.component' ;
25
24
import { NgClass , NgTemplateOutlet , NgIf } from '@angular/common' ;
26
25
26
+ export const IgxChipTypeVariant = mkenum ( {
27
+ PRIMARY : 'primary' ,
28
+ INFO : 'info' ,
29
+ SUCCESS : 'success' ,
30
+ WARNING : 'warning' ,
31
+ DANGER : 'danger'
32
+ } ) ;
33
+
27
34
export interface IBaseChipEventArgs extends IBaseEventArgs {
28
35
originalEvent : IDragBaseEventArgs | IDropBaseEventArgs | KeyboardEvent | MouseEvent | TouchEvent ;
29
36
owner : IgxChipComponent ;
@@ -79,6 +86,21 @@ let CHIP_ID = 0;
79
86
imports : [ IgxDropDirective , IgxDragDirective , NgClass , NgTemplateOutlet , NgIf , IgxIconComponent ]
80
87
} )
81
88
export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
89
+
90
+ /**
91
+ * Sets/gets the variant of the chip.
92
+ *
93
+ * @remarks
94
+ * Allowed values are `primary`, `info`, `success`, `warning`, `danger`.
95
+ * Providing an invalid value won't change the chip.
96
+ *
97
+ * @example
98
+ * ```html
99
+ * <igx-chip [variant]="success"></igx-chip>
100
+ * ```
101
+ */
102
+ @Input ( )
103
+ public variant : string | typeof IgxChipTypeVariant ;
82
104
/**
83
105
* An @Input property that sets the value of `id` attribute. If not provided it will be automatically generated.
84
106
*
@@ -218,6 +240,13 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
218
240
@Input ( )
219
241
public selectIcon : TemplateRef < any > ;
220
242
243
+ /**
244
+ * @hidden
245
+ * @internal
246
+ */
247
+ @Input ( )
248
+ public class = '' ;
249
+
221
250
/**
222
251
* An @Input property that defines if the `IgxChipComponent` is disabled. When disabled it restricts user interactions
223
252
* like focusing on click or tab, selection on click or Space, dragging.
@@ -228,6 +257,7 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
228
257
* <igx-chip [id]="chip.id" [disabled]="true"></igx-chip>
229
258
* ```
230
259
*/
260
+ @HostBinding ( 'class.igx-chip--disabled' )
231
261
@Input ( )
232
262
public disabled = false ;
233
263
@@ -456,6 +486,44 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
456
486
@Output ( )
457
487
public dragDrop = new EventEmitter < IChipEnterDragAreaEventArgs > ( ) ;
458
488
489
+ @HostBinding ( 'class.igx-chip' )
490
+ protected defaultClass = 'igx-chip' ;
491
+
492
+ @HostBinding ( 'class.igx-chip--primary' )
493
+ protected get isPrimary ( ) {
494
+ return this . variant === IgxChipTypeVariant . PRIMARY ;
495
+ }
496
+
497
+ @HostBinding ( 'class.igx-chip--info' )
498
+ protected get isInfo ( ) {
499
+ return this . variant === IgxChipTypeVariant . INFO ;
500
+ }
501
+
502
+ @HostBinding ( 'class.igx-chip--success' )
503
+ protected get isSuccess ( ) {
504
+ return this . variant === IgxChipTypeVariant . SUCCESS ;
505
+ }
506
+
507
+ @HostBinding ( 'class.igx-chip--warning' )
508
+ protected get isWarning ( ) {
509
+ return this . variant === IgxChipTypeVariant . WARNING ;
510
+ }
511
+
512
+ @HostBinding ( 'class.igx-chip--danger' )
513
+ protected get isDanger ( ) {
514
+ return this . variant === IgxChipTypeVariant . DANGER ;
515
+ }
516
+
517
+ @HostBinding ( 'class.igx-chip--cosy' )
518
+ protected get isCosy ( ) {
519
+ return this . displayDensity === 'cosy' ;
520
+ }
521
+
522
+ @HostBinding ( 'class.igx-chip--compact' )
523
+ protected get isCompact ( ) {
524
+ return this . displayDensity === 'compact' ;
525
+ }
526
+
459
527
/**
460
528
* Property that contains a reference to the `IgxDragDirective` the `IgxChipComponent` uses for dragging behavior.
461
529
*
@@ -479,13 +547,6 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
479
547
@ViewChild ( 'chipArea' , { read : ElementRef , static : true } )
480
548
public chipArea : ElementRef ;
481
549
482
- /**
483
- * @hidden
484
- * @internal
485
- */
486
- @ViewChild ( 'selectContainer' , { read : ElementRef , static : true } )
487
- public selectContainer : ElementRef ;
488
-
489
550
/**
490
551
* @hidden
491
552
* @internal
@@ -505,7 +566,9 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
505
566
* @internal
506
567
*/
507
568
public get removeButtonTemplate ( ) {
508
- return this . removeIcon || this . defaultRemoveIcon ;
569
+ if ( ! this . disabled ) {
570
+ return this . removeIcon || this . defaultRemoveIcon ;
571
+ }
509
572
}
510
573
511
574
/**
@@ -552,20 +615,6 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
552
615
super ( _displayDensityOptions ) ;
553
616
}
554
617
555
- @HostBinding ( 'class' )
556
- private get hostClass ( ) : string {
557
- const classes = [ this . getComponentDensityClass ( 'igx-chip' ) ] ;
558
-
559
- // Add the base class first for each density
560
- if ( ! classes . includes ( 'igx-chip' ) ) {
561
- classes . unshift ( 'igx-chip' ) ;
562
- }
563
-
564
- classes . push ( this . disabled ? 'igx-chip--disabled' : '' ) ;
565
-
566
- return classes . join ( ' ' ) . toString ( ) . trim ( ) ;
567
- }
568
-
569
618
/**
570
619
* @hidden
571
620
* @internal
@@ -836,10 +885,6 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
836
885
cancel : false
837
886
} ;
838
887
839
- fromEvent ( this . selectContainer . nativeElement , 'transitionend' )
840
- . pipe ( filter < TransitionEvent > ( event => event . propertyName === 'width' ) , take ( 1 ) )
841
- . subscribe ( event => this . onSelectTransitionDone ( event ) ) ;
842
-
843
888
if ( newValue && ! this . _selected ) {
844
889
onSelectArgs . selected = true ;
845
890
this . selectedChanging . emit ( onSelectArgs ) ;
@@ -848,6 +893,10 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
848
893
this . renderer . addClass ( this . chipArea . nativeElement , this . _selectedItemClass ) ;
849
894
this . _selected = newValue ;
850
895
this . selectedChange . emit ( this . _selected ) ;
896
+ this . selectedChanged . emit ( {
897
+ owner : this ,
898
+ originalEvent : srcEvent
899
+ } ) ;
851
900
}
852
901
} else if ( ! newValue && this . _selected ) {
853
902
this . selectedChanging . emit ( onSelectArgs ) ;
@@ -856,6 +905,10 @@ export class IgxChipComponent extends DisplayDensityBase implements OnDestroy {
856
905
this . renderer . removeClass ( this . chipArea . nativeElement , this . _selectedItemClass ) ;
857
906
this . _selected = newValue ;
858
907
this . selectedChange . emit ( this . _selected ) ;
908
+ this . selectedChanged . emit ( {
909
+ owner : this ,
910
+ originalEvent : srcEvent
911
+ } ) ;
859
912
}
860
913
}
861
914
}
0 commit comments