Skip to content

Commit d9a207b

Browse files
feat: prefix icon for label tag component (#1450)
1 parent 9af4573 commit d9a207b

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

projects/components/src/label-tag/label-tag.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
display: flex;
1313
align-items: center;
1414
justify-content: center;
15+
gap: 4px;
1516

1617
// Default color. Could be overridden by the component
1718
background-color: $blue-1;
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import { createHostFactory, Spectator } from '@ngneat/spectator/jest';
2+
import { MockComponent } from 'ng-mocks';
3+
import { IconComponent } from '../icon/icon.component';
24
import { LabelTagComponent } from './label-tag.component';
35

46
describe('Label Tag Component', () => {
57
let spectator: Spectator<LabelTagComponent>;
68

79
const createHost = createHostFactory({
810
component: LabelTagComponent,
9-
shallow: true
11+
shallow: true,
12+
declarations: [MockComponent(IconComponent)]
1013
});
1114

1215
test('renders the beta tag with given parameters', () => {
13-
spectator = createHost('<ht-label-tag label="Beta" backgroundColor="#f2d0f5" labelColor="#94209f"></ht-label-tag>');
16+
spectator = createHost(
17+
'<ht-label-tag label="Beta" backgroundColor="#f2d0f5" labelColor="#94209f" prefixIcon="test-icon"></ht-label-tag>'
18+
);
1419
const labelElement = spectator.query('.label-tag') as HTMLElement;
1520
expect(labelElement).toHaveText('Beta');
1621
expect(labelElement.style.backgroundColor).toEqual('rgb(242, 208, 245)');
1722
expect(labelElement.style.color).toEqual('rgb(148, 32, 159)');
23+
expect(spectator.query(IconComponent)?.icon).toBe('test-icon');
1824
});
1925
});

projects/components/src/label-tag/label-tag.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
22
import { Color } from '@hypertrace/common';
3+
import { IconSize } from '../icon/icon-size';
34

45
@Component({
56
selector: 'ht-label-tag',
67
styleUrls: ['./label-tag.component.scss'],
78
changeDetection: ChangeDetectionStrategy.OnPush,
89
template: `
910
<div class="label-tag" [ngStyle]="{ backgroundColor: this.backgroundColor, color: this.labelColor }">
11+
<ht-icon
12+
*ngIf="this.prefixIcon"
13+
[icon]="this.prefixIcon"
14+
size="${IconSize.Small}"
15+
[color]="this.labelColor"
16+
></ht-icon>
1017
{{ this.label }}
1118
</div>
1219
`
@@ -20,4 +27,7 @@ export class LabelTagComponent {
2027

2128
@Input()
2229
public backgroundColor?: Color;
30+
31+
@Input()
32+
public prefixIcon?: string;
2333
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
3+
import { IconModule } from '../icon/icon.module';
34
import { LabelTagComponent } from './label-tag.component';
45

56
@NgModule({
67
declarations: [LabelTagComponent],
7-
imports: [CommonModule],
8+
imports: [CommonModule, IconModule],
89
exports: [LabelTagComponent]
910
})
1011
export class LabelTagModule {}

0 commit comments

Comments
 (0)