Skip to content

Commit 3793bfa

Browse files
committed
feat: add icon support
Signed-off-by: Akshat Patel <[email protected]>
1 parent d4adac4 commit 3793bfa

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

src/tag/tag-filter.component.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,40 @@ import {
33
Output,
44
EventEmitter,
55
HostBinding,
6-
Input
6+
Input,
7+
TemplateRef
78
} from "@angular/core";
89
import { Tag } from "./tag.component";
910

1011
@Component({
1112
selector: "cds-tag-filter, ibm-tag-filter",
1213
template: `
13-
<span
14-
class="cds--tag__label"
15-
[attr.title]="title ? title : null"
16-
(click)="onClick($event)">
17-
<ng-content></ng-content>
18-
</span>
19-
<button
20-
class="cds--tag__close-icon"
21-
(click)="onClose($event)"
22-
[disabled]="disabled"
23-
[title]="closeButtonLabel">
24-
<span class="cds--visually-hidden">{{closeButtonLabel}}</span>
25-
<svg cdsIcon="close" size="16"></svg>
26-
</button>
14+
<ng-container *ngIf="!skeleton">
15+
<ng-content select="[cdsTagIcon],[ibmTagIcon]"></ng-content>
16+
<span
17+
class="cds--tag__label"
18+
[attr.title]="title ? title : null"
19+
(click)="onClick($event)">
20+
<ng-content></ng-content>
21+
</span>
22+
<button
23+
class="cds--tag__close-icon"
24+
(click)="onClose($event)"
25+
[disabled]="disabled"
26+
[title]="closeButtonLabel">
27+
<span class="cds--visually-hidden">{{closeButtonLabel}}</span>
28+
<svg cdsIcon="close" size="16"></svg>
29+
</button>
30+
</ng-container>
2731
`
2832
})
2933
export class TagFilter extends Tag {
3034
@Input() closeButtonLabel = "Clear Filter";
3135
@Input() disabled: boolean;
3236
@Input() title: string;
3337

38+
@Input() icon: string | TemplateRef<any>;
39+
3440
/**
3541
* Function for close/delete the tag
3642
*/
@@ -59,8 +65,16 @@ export class TagFilter extends Tag {
5965
this.close.emit();
6066
}
6167

68+
/**
69+
* @todo
70+
* Remove `cds--tag--${this.size}` in v7
71+
*/
6272
@HostBinding("attr.class") get attrClass() {
63-
return `cds--tag cds--tag--filter cds--tag--${this.type} cds--tag--${this.size} cds--layout--size-${this.size} ${this.class}${this.disabled ? " cds--tag--disabled" : ""}`;
73+
const disabledClass = this.disabled ? "cds--tag--disabled" : "";
74+
const sizeClass = `cds--tag--${this.size} cds--layout--size-${this.size}`;
75+
const skeletonClass = this.skeleton ? "cds--skeleton" : "";
76+
77+
return `cds--tag cds--tag--filter cds--tag--${this.type} ${disabledClass} ${sizeClass} ${skeletonClass} ${this.class}`;
6478
}
6579

6680
@HostBinding("attr.aria-label") get attrAriaLabel() {

src/tag/tag-icon.directive.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Directive, HostBinding } from "@angular/core";
2+
3+
@Directive({
4+
selector: "[cdsTagIcon], [ibmTagIcon]"
5+
})
6+
export class TagIconDirective {
7+
@HostBinding("class.cds--tag__custom-icon") tagIcon = true;
8+
}

src/tag/tag.component.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ export type TagType = "red" |
3131
*/
3232
@Component({
3333
selector: "cds-tag, ibm-tag",
34-
template: `<ng-content></ng-content>`
34+
template: `
35+
<ng-container *ngIf="!skeleton">
36+
<ng-content select="[cdsTagIcon],[ibmTagIcon]"></ng-content>
37+
<span class="cds--tag__label">
38+
<ng-content></ng-content>
39+
</span>
40+
</ng-container>
41+
`
3542
})
3643
export class Tag {
3744
/**
@@ -42,11 +49,20 @@ export class Tag {
4249
/**
4350
* Tag render size
4451
*/
45-
@Input() size: "sm" | "md" = "md";
52+
@Input() size: "sm" | "md" | "lg" = "md";
4653

4754
@Input() class = "";
4855

56+
@Input() skeleton = false;
57+
58+
/**
59+
* @todo
60+
* Remove `cds--tag--${this.size}` in v7
61+
*/
4962
@HostBinding("attr.class") get attrClass() {
50-
return `cds--tag cds--tag--${this.type} cds--tag--${this.size} cds--layout--size-${this.size} ${this.class}`;
63+
const skeletonClass = this.skeleton ? "cds--skeleton" : "";
64+
const sizeClass = `cds--tag--${this.size} cds--layout--size-${this.size}`;
65+
66+
return `cds--tag cds--tag--${this.type} ${sizeClass} ${skeletonClass} ${this.class}`;
5167
}
5268
}

0 commit comments

Comments
 (0)