Skip to content

Commit 310ba9e

Browse files
author
Patricio Albizu
committed
feat: adding icon support to toggle group
1 parent fc33c22 commit 310ba9e

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

projects/components/src/toggle-group/toggle-group.component.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fakeAsync } from '@angular/core/testing';
2+
import { IconType } from '@hypertrace/assets-library';
23
import { createHostFactory, Spectator } from '@ngneat/spectator/jest';
34
import { MockComponent } from 'ng-mocks';
45
import { LabelComponent } from '../label/label.component';
@@ -23,6 +24,7 @@ describe('Toggle Group Component', () => {
2324
},
2425
{
2526
label: 'Second',
27+
icon: IconType.Add,
2628
value: 'second-value'
2729
}
2830
];

projects/components/src/toggle-group/toggle-group.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ import { ToggleItemComponent } from './toggle-item.component';
2828
></div>
2929
<div class="container" *ngFor="let item of this.items; let index = index">
3030
<div class="divider" *ngIf="index !== 0" [class.hide-divider]="this.shouldHideDivider(index)"></div>
31-
<ht-toggle-item class="tab" [label]="item.label" (click)="this.setActiveItem(item)"></ht-toggle-item>
31+
<ht-toggle-item
32+
class="tab"
33+
[label]="item.label"
34+
[icon]="item.icon"
35+
(click)="this.setActiveItem(item)"
36+
></ht-toggle-item>
3237
</div>
3338
</div>
3439
</div>

projects/components/src/toggle-group/toggle-group.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
3+
import { IconModule } from '../icon/icon.module';
34
import { LabelModule } from '../label/label.module';
45
import { ToggleGroupComponent } from './toggle-group.component';
56
import { ToggleItemComponent } from './toggle-item.component';
67

78
@NgModule({
8-
imports: [CommonModule, LabelModule],
9+
imports: [CommonModule, LabelModule, IconModule],
910
exports: [ToggleGroupComponent],
1011
declarations: [ToggleGroupComponent, ToggleItemComponent]
1112
})

projects/components/src/toggle-group/toggle-item.component.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
padding: 0 12px;
99
cursor: pointer;
1010

11-
.label {
11+
.label,
12+
.icon {
1213
z-index: 1; // Needs to stack above the active element
1314
pointer-events: none; // Make this label ignore hover so active element gets it
1415
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import { ChangeDetectionStrategy, Component, ElementRef, Input } from '@angular/core';
2+
import { IconType } from '@hypertrace/assets-library';
3+
import { IconSize } from '../icon/icon-size';
24

35
@Component({
46
selector: 'ht-toggle-item',
57
styleUrls: ['./toggle-item.component.scss'],
68
changeDetection: ChangeDetectionStrategy.OnPush,
79
template: `
810
<div class="toggle-item">
9-
<ht-label class="label" [label]="this.label"></ht-label>
11+
<ht-icon *ngIf="this.icon; else labelBlock" class="icon" [icon]="this.icon" size="${IconSize.Medium}"></ht-icon>
12+
<ng-template #labelBlock>
13+
<ht-label class="label" [label]="this.label"></ht-label>
14+
</ng-template>
1015
</div>
1116
`
1217
})
1318
export class ToggleItemComponent {
1419
@Input()
1520
public label?: string;
1621

22+
@Input()
23+
public icon?: IconType;
24+
1725
public constructor(public readonly elementRef: ElementRef) {}
1826
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { IconType } from '@hypertrace/assets-library';
2+
13
export interface ToggleItem<TValue = unknown> {
2-
label: string;
4+
label?: string;
5+
icon?: IconType;
36
value?: TValue;
47
}

0 commit comments

Comments
 (0)