Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fakeAsync } from '@angular/core/testing';
import { IconType } from '@hypertrace/assets-library';
import { createHostFactory, Spectator } from '@ngneat/spectator/jest';
import { MockComponent } from 'ng-mocks';
import { LabelComponent } from '../label/label.component';
Expand All @@ -23,6 +24,7 @@ describe('Toggle Group Component', () => {
},
{
label: 'Second',
icon: IconType.Add,
value: 'second-value'
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import { ToggleItemComponent } from './toggle-item.component';
></div>
<div class="container" *ngFor="let item of this.items; let index = index">
<div class="divider" *ngIf="index !== 0" [class.hide-divider]="this.shouldHideDivider(index)"></div>
<ht-toggle-item class="tab" [label]="item.label" (click)="this.setActiveItem(item)"></ht-toggle-item>
<ht-toggle-item
class="tab"
[label]="item.label"
[icon]="item.icon"
(click)="this.setActiveItem(item)"
></ht-toggle-item>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { IconModule } from '../icon/icon.module';
import { LabelModule } from '../label/label.module';
import { ToggleGroupComponent } from './toggle-group.component';
import { ToggleItemComponent } from './toggle-item.component';

@NgModule({
imports: [CommonModule, LabelModule],
imports: [CommonModule, LabelModule, IconModule],
exports: [ToggleGroupComponent],
declarations: [ToggleGroupComponent, ToggleItemComponent]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
padding: 0 12px;
cursor: pointer;

.label {
.label,
.icon {
z-index: 1; // Needs to stack above the active element
pointer-events: none; // Make this label ignore hover so active element gets it
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { ChangeDetectionStrategy, Component, ElementRef, Input } from '@angular/core';
import { IconType } from '@hypertrace/assets-library';
import { IconSize } from '../icon/icon-size';

@Component({
selector: 'ht-toggle-item',
styleUrls: ['./toggle-item.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="toggle-item">
<ht-label class="label" [label]="this.label"></ht-label>
<ht-icon *ngIf="this.icon; else labelBlock" class="icon" [icon]="this.icon" size="${IconSize.Medium}"></ht-icon>
<ng-template #labelBlock>
<ht-label class="label" [label]="this.label"></ht-label>
</ng-template>
</div>
`
})
export class ToggleItemComponent {
@Input()
public label?: string;

@Input()
public icon?: IconType;

public constructor(public readonly elementRef: ElementRef) {}
}
5 changes: 4 additions & 1 deletion projects/components/src/toggle-group/toggle-item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { IconType } from '@hypertrace/assets-library';

export interface ToggleItem<TValue = unknown> {
label: string;
label?: string;
icon?: IconType;
value?: TValue;
}